WooCommerce Tutorial – Add Additional Shipping Weight to Cart Items in a Shipping Class

Today’s WooCommerce Tutorial contains some fairly high level code which will allow you to do something really specific, that can help with getting your pricing just right, for example, if you’re using a shipping API which is returning weight based calculations.

The Use Case

I created this code for a client who was finding certain low weight items were coming in under a shipping API threshold, because the item was given a weight that did not include packaging.

In this client’s case, the items themselves are sold as “low weight” so it was not desirable simply to add extra weight onto the shipping weight (which was displaying in the site as additional information).

Therefore, in order to have shipping weight always calculate, the “packed weight” needed to be set per product.

The actual maths – in this case – and therefore this snippet, were pretty straightforward, but of course, please do adjust according to your own needs.

Remember to Test This

As always, test first. Then test in staging. Fire a few carts at it and see if you get the shipping rate you wanted to return.

Add Additional Shipping Weight to Cart Items in a Shipping Class

Find the code in the Gist below:

What to replace?

You should replace the following elements with items relevant to your own use case:

  • $additionalweight = 6; – replace 6 with some other amount!
  • “shipping-class-slug” – replace this with the actual shipping class slug you will use in your site

Where to put this?

Add this snippet into either – in order of my personal preference:

  • A custom plugin (best)
  • A snippets plugin (good)
  • The functions.php of your child theme (not so good)
  • functions.php of your current active theme (never if this is not a child theme!)

Questions, Comments, Praise, Flames?

Leave a comment below if this worked, didn’t work, or if you extended this in some awesome way. Share the knowledge. Share the love.

2 thoughts on “WooCommerce Tutorial – Add Additional Shipping Weight to Cart Items in a Shipping Class”

  1. Hello Robin,
    This is quite interesting as we are struggling to find a plugin which adds the weight of a wooden protection board that we would use only for the shipment of some metal sheet and cut out at the right size.
    Do you think your code could be applied to the attributes of a variable product. For instance when the metal sheet 500×100 mm is ordered (regardless of the quantity of metal sheet) we add 6 kg of wooden protection board.
    Moreover this additionnal weight would be fixed, only one protection board dimension: 500×100 if for example the customer orders 3 sheets of dimensions :500×100.
    Of course the protection board would be free but we need to add the weight of it in order to calculate a fair shipment price.
    Thank you in advance for your feed-back.


Leave a comment

No links of any kind allowed in comments - if you add any links, your comment will automatically be deleted.