Good evening. I wrote some code to alter the total weight of some specific articles in my cart (due to a specific request of the courier). Before you ask... no, I cannot modify the single article weight, because I have to calculate a special weight for packaging. Yes, it's a long story,
My code looks like that (simplified version):
function set_my_weight($weight) {
global $woocommerce;
$cart_items = $woocommerce->cart->get_cart();
$addedWeight = 0;
echo "prev: ". $weight;
foreach($cart_items as $prod => $values):
if(conditions):
$addedWeight += 1.5;
endif;
endforeach;
$weight += $addedWeight;
echo "final: ". $weight;
return $weight;
}
add_filter('woocommerce_cart_contents_weight', 'set_my_weight',10,1);
When I echo the value calling
echo WC()->cart->cart_contents_weight; all seems working fine, but for some reason the shipping costs do not change.
I'm using "WooCommerce Weight Based Shipping" plugin to manage my shipping costs.
Why the new weight is ignored by the plugin?
Thanks