Hi i'm looking for the action which triggered before the shipping fee calculation.
I have the following function, but this one runs after the shipping fee calculation. The problem is that in this site, you get discounts if you buy more than 3, 5 or 10 items, and the shipping is based on the price of your cart total. But if i select 3 items (so it gets a discount) and because of this price will go below the minimum price for the shipping method but the shipping method wont change'.
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');
function add_custom_fees( WC_Cart $cart ){
if( $cart->cart_contents_count >= 3 && $cart->cart_contents_count <= 4 ){
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.1;
$cart->add_fee( 'Text', -$discount);
return;
}
if( $cart->cart_contents_count >= 5 && $cart->cart_contents_count < 10 ){
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.15;
$cart->add_fee( 'Text', -$discount);
return;
}
if( $cart->cart_contents_count >= 10 ){
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.2;
$cart->add_fee( 'Text', -$discount);
return;
}
}
As you can see the current action I'm using is this one: woocommerce_cart_calculate_fees
thanks