0

I want to add a constant weight to the total weight of the orders in my shopping cart to account for packing materials in the weight calculation.

I'm also using Commerce Shipping Postal Code Code Weight. The Postal code weights work brilliantly.Shipping Postal Code Weights

What I want to do is add a 6oz to the total weight of my order.

0

You should implement this hook in a custom module:

/**
 * Allows modules to alter the weight that has been determined for an order.
 *
 * @param &$weight
 *   The weight field value array representing the weight of the order or NULL
 *   if no weight has yet been determined.
 * @param $order
 *   The order object whose weight is being determined.
 * @param $unit
 *   The unit of measurement to use for the returned weight of the order.
 *
 * @see commerce_physical_order_weight()
 */
function hook_commerce_physical_order_weight_alter(&$weight, $order, $unit) {
  // No example.
}
  • so the hook would have to grab 1) the physical_order_weight value, 2) check conditions (like the order weight does not = 0). take the physical order weight and add 6. How would this look? – nizz0k Dec 23 '15 at 20:32
  • Because, there isn't an example, I'm a little lost. I created a module, and I tried this little bit of code function add_ship_weight_commerce_physical_order_weight_alter(&$weight, $order, $unit) { dpm(&$weight);.} but this doesn't return anything with the devel module. – nizz0k Dec 24 '15 at 9:09
  • You do not need the ampersand sign in dpm, it means the variable is a reference and can be redefined. Alle you need to add is the following code: $weight = <some number>; The other provided variables are for more difficult calculations. – Neograph734 Dec 24 '15 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.