You are here

function hook_commerce_shipping_calculate_rate in Commerce Shipping 7.2

Allows modules or Rules to perform additional calculation of a shipping rate.

Calculation will be performed on top of the base rate determined by the shipping service.

Rate calculation rules work in much the same way as product pricing rules. The event and hook take a shipping line item parameter whose unit price has been initialized to the base rate for the shipping service. The unit price may then be updated by the unit price manipulation Rules actions or directly in code.

Manipulations made via custom code should update the unit price and create a price component in the unit price's data array representing the change in pricing. Without this price component, the change to the unit price amount will not be reflected in order total calculation.

While it is not part of the rate calculation process, the function commerce_shipping_example_service_details_form_submit() demonstrates what it means both to increment the shipping line item's unit price amount and to add a price component to its data array representing the change.

Parameters

object $line_item: The shipping line item that represents the shipping rate the customer must pay if the related shipping service is selected.

See also

commerce_shipping_service_rate_calculate()

commerce_shipping_example_service_details_form_submit()

File

./commerce_shipping.api.php, line 184
Contains API for commerce shipping module.

Code

function hook_commerce_shipping_calculate_rate($line_item) {

  // No example.
}