function hook_shipping_method in Ubercart 5
Same name and namespace in other branches
- 6.2 docs/hooks.php \hook_shipping_method()
Define callbacks and service options for shipping methods.
The shipping quote controller module, uc_quote, expects a very specific structured array of methods from the implementations of this hook.
The weights and enabled flags for shipping methods and types are set at the Shipping Quote Settings page under Store Configuration. They keys of the variables are the ids of the shipping methods. The "quote" and "ship" arrays of the method are both optional.
Return value
An array of shipping methods which have the following keys.
- "type": The quote and shipping types are ids of the product shipping type that these methods apply to. type may also be 'order' which indicates that the quote applies to the entire order, regardless of the shipping types of its products. This is used by quote methods that are base on the location of the customer rather than their purchase.
- "callback": The function that is called by uc_quote when a shipping quote is requested. Its arguments are the array of products and an array of order details (the shipping address). The return value is an array representing the rates quoted and errors returned (if any) for each option in the accessorials array.
- "accessorials": This array represents the different options the customer may choose for their shipment. The callback function should generate a quote for each option in accessorials and return them via an array. drupal_to_js() is very useful for this.
return array(
'03' => array('rate' => 15.75, 'format' => uc_currency_format(15.75) 'option_label' => t('UPS Ground'),
'error' => 'Additional handling charge automatically applied.'),
'14' => array('error' => 'Invalid package type.'),
'59' => array('rate' => 26.03, 'format' => uc_currency_format(26.03), 'option_label' => t('UPS 2nd Day Air A.M.'))
);
- "pkg_types": The list of package types that the shipping method can handle. This should be an associative array that can be used as the #options of a select form element. It is recommended that a function be written to output this array so the method doesn't need to be found just for the package types.
5 functions implement hook_shipping_method()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- uc_flatrate_shipping_method in shipping/
uc_flatrate/ uc_flatrate.module - Implementation of Übercart's hook_shipping_method().
- uc_quote_condition_order_shipping_method in shipping/
uc_quote/ uc_quote.module - uc_ups_shipping_method in shipping/
uc_ups/ uc_ups.module - Implementation of Übercart's hook_shipping_method().
- uc_usps_shipping_method in shipping/
uc_usps/ uc_usps.module - Implementation of Übercart's hook_shipping_method().
- uc_weightquote_shipping_method in shipping/
uc_weightquote/ uc_weightquote.module - Implementation of Übercart's hook_shipping_method().
20 invocations of hook_shipping_method()
- uc_cart_pane_quotes in shipping/
uc_quote/ uc_quote.module - Cart pane callback.
- uc_checkout_pane_quotes in shipping/
uc_quote/ uc_quote.module - Shipping quote checkout pane callback.
- uc_order_pane_quotes in shipping/
uc_quote/ uc_quote.module - Shipping quote order pane callback.
- uc_paypal_ec_review_form_submit in payment/
uc_paypal/ uc_paypal.module - uc_quote_cache_quotes in shipping/
uc_quote/ uc_quote.module
File
- docs/
hooks.php, line 950 - These are the hooks that are invoked by the Übercart core.
Code
function hook_shipping_method() {
$methods = array();
$enabled = variable_get('uc_quote_enabled', array(
'ups' => true,
));
$weight = variable_get('uc_quote_method_weight', array(
'ups' => 0,
));
$methods['ups'] = array(
'id' => 'ups',
'title' => t('UPS'),
'enabled' => $enabled['ups'],
'weight' => $weight['ups'],
'quote' => array(
'type' => 'small package',
'callback' => 'uc_ups_quote',
'accessorials' => array(
'03' => t('UPS Ground'),
'11' => t('UPS Standard'),
'01' => t('UPS Next Day Air'),
'13' => t('UPS Next Day Air Saver'),
'14' => t('UPS Next Day Early A.M.'),
'02' => t('UPS 2nd Day Air'),
'59' => t('UPS 2nd Day Air A.M.'),
'12' => t('UPS 3-Day Select'),
),
),
'ship' => array(
'type' => 'small package',
'callback' => 'uc_ups_fulfill_order',
'pkg_types' => array(
'01' => t('UPS Letter'),
'02' => t('Customer Supplied Package'),
'03' => t('Tube'),
'04' => t('PAK'),
'21' => t('UPS Express Box'),
'24' => t('UPS 25KG Box'),
'25' => t('UPS 10KG Box'),
'30' => t('Pallet'),
),
),
);
return $methods;
}