In my woocommerce cart, the shipping cost is still correctly calculated by the code below. But the shipping label is not being updated now. I can't found the cause; could be the recently woocommerce 3.7 update? Thanks for help!
/**
* Add different price for shipping based on products quantity
*/
function mx_shop_shipping_price( $rates, $package ) {
//Shipping Mode 1
if ( WC()->cart->cart_contents_count < 4 ) {
return array_filter($rates, function (WC_Shipping_Rate $rate) {
return $rate->get_label() === 'Shipping Mode 1'; // Shipping Mode 1
});
}
//Shipping Mode 2
if ( WC()->cart->cart_contents_count < 13 ) {
return array_filter($rates, function (WC_Shipping_Rate $rate) {
return $rate->get_label() === 'Shipping Mode 2';
});
}
//Shipping Mode 3
return array_filter($rates, function (WC_Shipping_Rate $rate) {
return $rate->get_label() === 'Shipping Mode 3';
});
}
add_filter( 'woocommerce_package_rates', 'mx_shop_shipping_price', 10, 2 );
/** End
Cart detail with Shipping label not updated. Note Order Total is correctly updated