I'm trying to custom code the shopping cart in Woocommerce by changing the price of the delivery when a condition is met.
For example, if the product weighs 25kg, then simply add another price on top.
Here's my code in functions.php but it doesn't seem to work when i refresh the shopping cart.
$chosen_shipping_state = WC()->customer->get_shipping_postcode();
$chosen_state = $chosen_shipping_state;
// Get the selected shipping price
$chosen_shipping_method_price = WC()->session->get('cart_totals')['shipping_total'];
if ($cartweight >= 25 && $cartweight <= 50) {
WC()->session->set('shipping_total', '100');
do_action( 'woocommerce_cart_updated' );
}
So the current price of the selected courier is $5.50.
If the product weighs over 25 kgs, how do I made the courier price set to $11 and the shopping cart automatically refreshes with this amount?