You are here

function hook_line_item in Ubercart 5

Same name and namespace in other branches
  1. 6.2 docs/hooks.php \hook_line_item()

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.)
6 functions implement hook_line_item()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

uc_order_delete_line_item in uc_order/uc_order_line_item.inc
Delete a line item, or pass $order as TRUE and $id as an order_id to delete every line item attached to an order.
uc_order_line_item in uc_order/uc_order.module
Implementation of hook_line_item().
uc_order_update_line_item in uc_order/uc_order_line_item.inc
Update a line item.
uc_quote_line_item in shipping/uc_quote/uc_quote.module
Defines the shipping quote line item.
uc_taxes_line_item in uc_taxes/uc_taxes.module
Implementation of Übercart's hook_line_item().

... See full list

1 invocation of hook_line_item()
_line_item_list in uc_order/uc_order_line_item.inc
Build a list of line items defined in the enabled modules.

File

docs/hooks.php, line 580
These are the hooks that are invoked by the Übercart core.

Code

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;
}