Recently we came across a condition where one of client want to remove the GST/TAX charge from checkout if customer enter his/her VAT number on checkout field. This same concept can be applied on any any input field like number or text.
In simple words we are removing or changing the Tax value based on the checkout field value. This process can be achieved via a code which will be added on functions.php file of your child theme.
We can do the above task using a function called set_is_vat_exempt(), and we going to make some changes to achieve the above task. Below is the step by step guide to do the same.
Step by step guide to remove TAX on WooCommerce if user enter VAT number.
- Click on theme editor and open functions.php file in your child theme.
- Add the below code on functions.php file. here we using ZIP code number, you can set any field as per your choice.
add_action( 'woocommerce_checkout_update_tax', 'remove_tax_checkout_on_checkout_field' );
function remove_tax_checkout_on_checkout_field( $post_data ) {
WC()->customer->set_is_vat_exempt( false );
parse_str( $post_data, $output );
if ( $output['billing_postcode'] === '*' ) WC()->customer->set_is_vat_exempt( true );
}
Once added, save the file and check on checkout page by entering the Postcode. Let us know in comment section if you getting any issues.
Happy Coding!
[caldera_form id=”CF60ca2e3ccf64f”]