function commerce_shipping_add_shipping_line_item in Commerce Shipping 7.2
Adds a shipping line item to an order.
Parameters
object $line_item: An unsaved shipping line item that should be added to the order.
object $order: The order to add the shipping line item to.
bool $skip_save: Boolean indicating whether or not to skip saving the order in this function.
Return value
object|bool The saved shipping line item object or FALSE on failure.
2 calls to commerce_shipping_add_shipping_line_item()
- commerce_shipping_pane_checkout_form_submit in includes/
commerce_shipping.checkout_pane.inc - Checkout pane callback: submit the shipping checkout pane.
- commerce_shipping_rate_apply in ./
commerce_shipping.rules.inc - Action: Apply a shipping rate to an order.
File
- ./
commerce_shipping.module, line 1060 - Defines a system for calculating shipping costs associated with an order.
Code
function commerce_shipping_add_shipping_line_item($line_item, $order, $skip_save = FALSE) {
// Do not proceed without a valid order.
if (empty($order)) {
return FALSE;
}
// Save the incoming line item now so we get its ID.
commerce_line_item_save($line_item);
// Add it to the order's line item reference value.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
// Save the updated order.
if (!$skip_save) {
commerce_order_save($order);
}
else {
commerce_order_calculate_total($order);
}
return $line_item;
}