I have set some Shipping methods with taxable option enabled in WooCommerce. I use this code to set up different shipping cost if spend over X amount:
// Extra discount on shipping for orders of values of above 150 or 100.
function custom_adjust_shipping_rate( $rates ) {
$cart_subtotal = WC()->cart->subtotal;
// Check if the subtotal is greater than value specified
if ( $cart_subtotal >= 29.99 ) {
// Loop through each shipping rate
foreach ( $rates as $rate ) {
// Store the previous cost in $cost
$cost = $rate->cost;
// Adjust the cost as needed
// original shipping greater than 6 discount by 5
if ( $cost == 7.38 ) {
// discount rate by 5
$rate->cost = $cost - 2.54;
}
// Optional discount for other shipping rates
if ( $cost == 4.10 ) {
$rate->cost = $cost - 5;
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'custom_adjust_shipping_rate', 10 );
But the problem is the tax calculations. My code doesn't handle taxes.
How can I adjust taxes from custom shipping cost?
How to enable taxes in cost calculations?
Any advice is appreciated.