Skip navigation
Help

hook_uc_order

7 uc_order.api.php hook_uc_order($op, $order, $arg2)

Performs actions on orders.

An order in Ubercart represents a single transaction. Orders are created during the checkout process where they sit in the database with a status of "In checkout". When a customer completes checkout, the order's status gets updated to show that the sale has gone through. Once an order is created, and even during its creation, it may be acted on by any module to connect extra information to an order. Every time an action occurs to an order, hook_uc_order() gets invoked to let your modules know what's happening and make stuff happen.

Parameters

$op: The action being performed.

$order: This is the order object.

$arg2: This is variable and is based on the value of $op:

  • new: Called when an order is created. $order is a reference to the new order object, so modules may add to or modify the order at creation.
  • presave: Before an order object is saved, the hook gets invoked with this op to let other modules alter order data before it is written to the database. $order is a reference to the order object.
  • save: When an order object is being saved, the hook gets invoked with this op to let other modules do any necessary saving. $order is a reference to the order object.
  • load: Called when an order is loaded after the order and product data has been loaded from the database. Passes $order as the reference to the order object, so modules may add to or modify the order object when it's loaded.
  • submit: When a sale is being completed and the customer has clicked the Submit order button from the checkout screen, the hook is invoked with this op. This gives modules a chance to determine whether or not the order should be allowed. An example use of this is the credit module attempting to process payments when an order is submitted and returning a failure message if the payment failed. To prevent an order from passing through, you must return an array resembling the following one with the failure message:
      return array(array(
        'pass' => FALSE,
        'message' => t('We were unable to process your credit card.'),
      ));
    
  • can_update: Called before an order's status is changed to make sure the order can be updated. $order is the order object with the old order status ID ($order->order_status), and $arg2 is simply the new order status ID. Return FALSE to stop the update for some reason.
  • update: Called when an order's status is changed. $order is the order object with the old order status ID ($order->order_status), and $arg2 is the new order status ID.
  • can_delete: Called before an order is deleted to verify that the order may be deleted. Returning FALSE will prevent a delete from happening. (For example, the payment module returns FALSE by default when an order has already received payments.)
  • delete: Called when an order is deleted and before the rest of the order information is removed from the database. Passes $order as the order object to let your module clean up it's tables.
  • total: Called when the total for an order is being calculated after the total of the products has been added. Passes $order as the order object. Expects in return a value (positive or negative) by which to modify the order total.

Related topics

7 functions implement hook_uc_order()

9 invocations of hook_uc_order()

File

ubercart/uc_order/uc_order.api.php, line 188
Hooks provided by the Order module.

Code

function hook_uc_order($op, $order, $arg2) {
  switch ($op) {
    case 'save':
      // Do something to save payment info!
      break;
  }
}