hook_line_item

Definition

hook_line_item()
ubercart/docs/hooks.php, line 528

Description

Used to define line items that are attached to orders.

A line item is a representation of charges, fees, and totals for an order. Default line items include the subtotal and total line items, the tax line item, and the shipping line item. There is also a generic line item that store admins can use to add extra fees and discounts to manually created orders. Module developers will use this hook to define new types of line items for their stores. An example use would be for a module that allows customers to use coupons and wants to represent an entered coupon as a line item.

Once a line item has been defined in hook_line_item, Übercart will begin interacting with it in various parts of the code. One of the primary ways this is done is through the callback function you specify for the line item.

Return value

Your hook should return an array of associative arrays. Each item in the array represents a single line item and should use the following keys:

  • "id"
    • type: string
    • value: The internal ID of the line item.
  • "title"
    • type: string
    • value: The title of the line item shown to the user in various interfaces. Use t().
  • "callback"
    • type: string
    • value: Name of the line item's callback function, called for various operations.
  • "weight"
    • type: integer
    • value: Display order of the line item in lists; "lighter" items are displayed first.
  • "stored"
    • type: boolean
    • value: Whether or not the line item will be stored in the database. Should be TRUE for any line item that is modifiable from the order edit screen.
  • "add_list"
    • type: boolean
    • value: Whether or not a line item should be included in the "Add a Line Item" select box on the order edit screen.
  • "calculated"
    • type: boolean
    • value: Whether or not the value of this line item should be added to the order total. (Ex: would be TRUE for a shipping charge line item but FALSE for the subtotal line item since the product prices are already taken into account.)
  • "display_only"
    • type: boolean
    • value: Whether or not this line item is simply a display of information but not calculated anywhere. (Ex: the total line item uses display to simply show the total of the order at the bottom of the list of line items.)

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_line_item() {
  $items[] = array(
    'id' => 'generic',
    'title' => t('Empty Line'),
    'weight' => 2,
    'default' => FALSE,
    'stored' => TRUE,
    'add_list' => TRUE,
    'calculated' => TRUE,
    'callback' => 'uc_line_item_generic',
  );

  return $items;
}
?>