How can I charge different tax rates based on the shipping method a customer selects at checkout in Woocommerce? My store has one shipping option that lets international customers avoid the 7% VAT charged here in Thailand.
Here's how to disable taxes when Local Pickup is selected as the shipping option according to Woocommerce documentation:
add_filter( 'woocommerce_apply_base_tax_for_local_pickup', '__return_false' );
But how do I disable taxes on a custom shipping option?
I've started to work out a solution, but I could use some help with line 2. i.e. How to get the current shipping method?
function remove_tax_for_fob( $cart ) {
$ok_remove = get_shipping_method( 'FOB' );
if ($ok_remove){
$cart->remove_taxes();
}
return $cart;
}
add_action( 'woocommerce_calculate_totals', 'remove_tax_for_fob' );
Here is the solution. Thanks for your help, Anand Shah!
/* Remove tax from cart for FOB orders */
function remove_tax_for_fob( $cart ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if($chosen_shipping =='FOB') {
$cart->remove_taxes();
}
return $cart;
}
add_action( 'woocommerce_calculate_totals', 'remove_tax_for_fob' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With