I need change total weight of order in woocommerce website.
For example: I have a 3 product in a cart: 1 - 30g; 2 - 35; 3 - 35g; total = 30+35+35 = 100g, but I want to add package weight to total weight (30% from total weight).
Example: ((30+35+35) * 0.3) + (30+35+35) = 130g
I can calculate it, but how change total weight from 100g to 130g.
For getting total weight I use get_cart_contents_weight(), but I don't know how to set new value.
Hook in the right filter action
Let's have a look on the function
get_cart_contents_weight()
:There is a filter hook we can use:
woocommerce_cart_contents_weight
So we can add a function to this filter:
To add the package weight to every product separately, you can try this:
But do not use both solutions together.
It's working at my end. Update total weight to new weight value.