WooCommerce: Remove Tax if Checkout Field Value Exists

You can use to exempt someone from Tax/VAT if they enter a Tax/VAT number, or maybe if they specify a given ZIP code.

When I discovered the WooCommerce function set_is_vat_exempt(), together with a little trick to “get” a checkout field programmatically, the snippet was pretty simple to build and test. Here’s the lovely piece of code ๐Ÿ™‚

WooCommerce: zero tax/vat if ZIP code equals ‘XYZ’

PHP Snippet: Remove Tax @ WooCommerce Checkout if Field Value Exists

 * @snippet       Remove Tax @ Checkout if Field Value Exists - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=21952
 * @author        Rodolfo Melogli
 * @compatible    WC 3.2.6

add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_taxexempt_checkout_based_on_zip' );

function bbloomer_taxexempt_checkout_based_on_zip( $post_data ) {
        global $woocommerce;
        $woocommerce->customer->set_is_vat_exempt( false );
        if ( $billing_postcode == '32444' ) $woocommerce->customer->set_is_vat_exempt( true );

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

27 thoughts on “WooCommerce: Remove Tax if Checkout Field Value Exists

  1. Hi ! I’m trying to set the tax 0 if the billing company field is set, but I don’t know how, can you help me?
    Thank you so much !

    1. Hello Jose, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hello!
    How can I make this work if I want students and non profits with tax ID to be exempt at checkout without having them to register as users?

    thank you!

    1. Hello George, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. Hey,
    Thanks a lot, I am using your solution and many other piece of code you share. I have noticed a undesirable behaviour of this code: if customer go back and forth between the payment page and the checkout page, a new custom field is_vat_exempt is set. That means that this custom field add up. I had the case where there was so many of them that it broke the payment validation. Is there a way to make sure there is a unic is_vat_exempt custom field for a given order?

    1. Hi Jonathan – if you remove my snippet does that happen as well? If yes, and if you disable all plugins but Woo and swith temporarily to 2017 theme, does that happen again? Let me know

  4. Hi. I am trying to use this on a custom radio button, but it’s not working.

    Here is the code for the button which works.

    function add_radio_field(){
      	$radioFile   = "";
     	$radioFile   .='<div class="customfield_cover"><label for="some_field_name" class="">Tax Exempt? </label><div id="radio_cover_id">';
     	$radioFile .='<input name="uhave_tax_exempt" id="uhave_tax_exempt" class="tax_exempt" type="radio" value="1" >Yes&nbsp;&nbsp;&nbsp;&nbsp;<input class="tax_exempt" name="uhave_tax_exempt" type="radio" value="2" >No';
     	$radioFile .='</div></div>';
     	echo $radioFile;

    But the code to remove the taxes isn’t working for me. I probably did something wrong.

    add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_taxexempt_checkout_based_on_zip' );
    function bbloomer_taxexempt_checkout_based_on_zip( $post_data ) {
            global $woocommerce;
            $woocommerce->customer->set_is_vat_exempt( false );
            if ( $uhave_tax_exempt == 1 ) $woocommerce->customer->set_is_vat_exempt( true );
    1. Hi Boston – it could be your field is not “posting” or that the $post_data variable needs to be debugged. Let me know

  5. I love this script and it works as expected, would that work with any other fields? I have added a custom field and I want to remove the tax when a checkbox is checked.

    1. Thanks Nik ๐Ÿ™‚ Yes, it should

  6. Hi Rodolfo,

    Great Code!
    is there any way to update product subtotal too?


    1. Hello Sigma, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  7. Thanks Rodolfo, I use your code but unfortunatly it doesn’t work when you place an order. The thank-you page diplays the price with the tax even if at the check out it’s zero. Don’t know why… ๐Ÿ™

    1. Hey Federico ๐Ÿ™‚ Try disabling all plugins and switching theme temporarily – does the snippet work then?

      1. Hi Rodolfo, I have same issue of Federico. On checkout form your snippet works as expected, but on Thankyou page taxes are not exempted and the same happens on admin order page. I tried deactivating all plugins and changing theme but with no luck. How can i do to solve the issue?
        Thanks, Fabrizio

        1. Hey Fabrizio, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

          To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

          Hope this helps!


  8. Hi Rodolfo
    excellent snippet
    one question , would this work for specific category of products ?

    thanks in advance

  9. Dear Rodolfo Melogli,

    Many thanks for this contribution! It works when I apply this rule to the following fields:


    Unfortunately it doesn’t work when I want to apply it to any other fields. Somehow those fields don’t get validated automatically. In face I want to apply it to a new field which is the tax number of the customer. Once the customer has entered a tax number the additional tax should be removed.

    Can you help me? Many thanks in advance!



    1. Matthieu, thanks so much for your comment! Unfortunately this is custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  10. Hi ROdolfo, is there a way to Remove Tax if customer selects payment method cash?

    1. Sandra, thanks for your comment! Yes, there is of course, you will need a little edit to the PHP of this snippet. Unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  11. Hello dear Rodolfo,

    you are great! Can you please give example how to use this function with Tax/VAT number field? I have setup field for UIC, but i have to remove VAT for order outside the country when VAT number is entered…

    Thank you for this awesome piece of code! ๐Ÿ™‚

    1. Hey Vladimir, thanks for your comment! You’ll need to change the line:

      if ( $billing_postcode == ___ )

      … with the name of the variable generated by your new Tax field, which is custom to your code and I can’t help with in here I’m afraid! ๐Ÿ™‚

  12. How about hide Sale Tax if Sale Tax is zero?

    1. Hey Vuster, thanks for your comment! I’m not sure I fully understand – could you send over a screenshot?

    2. I agree. In some stores, there is no tax at all… yet WooCommerce still shows Tax: $0.00 in cart and checkout. I’d like to hide the Tax row if there is a $0 tax value for the cart/order.

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *