You are here

function hook_order in Ubercart 5

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

Perform actions on orders.

An order in Übercart 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_order() gets invoked to let your modules know what's happening and make stuff happen.

Parameters

$op: The action being performed.

&$arg1: This is the order object or a reference to it as noted below.

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

  • new: Called when an order is created. $arg1 is a reference to the new order object, so modules may add to or modify the order at creation.
  • save: When an order object is being saved, the hook gets invoked with this op to let other modules do any necessary saving. $arg1 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 $arg1 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. $arg1 is the order object with the old order status ID ($arg1->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. $arg1 is the order object with the old order status ID ($arg1->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 $arg1 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 $arg1 as the order object. Expects in return a value (positive or negative) by which to modify the order total.
10 functions implement hook_order()

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

uc_credit_order in payment/uc_credit/uc_credit.module
Implementation of hook_order().
uc_file_order in uc_file/uc_file.module
Implementation of hook_order().
uc_googleanalytics_order in uc_googleanalytics/uc_googleanalytics.module
Implementation of hook_order().
uc_notify_order in uc_notify/uc_notify.module
Implementation of hook_order().
uc_payment_order in payment/uc_payment/uc_payment.module
Implementation of hook_order().

... See full list

8 invocations of hook_order()
uc_cart_checkout_review_form_submit in uc_cart/uc_cart.module
uc_order_actions in uc_order/uc_order.module
Return the actions a user may perform on an order.
uc_order_delete in uc_order/uc_order.module
Deletes an order and tells other modules to do the same.
uc_order_get_total in uc_order/uc_order.module
Calculate up an order's total!
uc_order_load in uc_order/uc_order.module
Load an order from the database.

... See full list

File

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

Code

function hook_order($op, &$arg1, $arg2) {
  switch ($op) {
    case 'save':

      // Do something to save payment info!
      break;
  }
}