With following code I'm able for specific shipping rate method (here 'easypack_parcel_machines') to set the cost to 0, when cart subtotal is up to a specific amount (here 150 PLN):
function override_inpost_cost( $rates, $package ) {
// Make sure paczkomaty is available
if ( isset( $rates['easypack_parcel_machines'] ) ) {
// Current value of the shopping cart
$cart_subtotal = WC()->cart->subtotal;
// Check if the subtotal is greater than 150pln
if ( $cart_subtotal >= 150 ) {
// Set the cost to 0pln
$rates['easypack_parcel_machines']->cost = 0;
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'override_inpost_cost', 10, 2 );
But the problem is that shipping tax original cost remains, even if 'easypack_parcel_machines' shipping method rate cost is set to zero its original cost (as it is taxable).
How to change the code so if 'easypack_parcel_machines' shipping method rate cost is set to 0 the tax will also be set to zero?