WooCommerce: Tax Exempt User Based on Checkout Field Value

 There is a nice WooCommerce function you can use to exempt someone from Tax/VAT calculations. You could, for example, enable exemption once they enter a Tax/VAT number, or maybe if they specify a given ZIP code.

Such function is called set_is_vat_exempt(), and together with a little trick to “get” a checkout field on the go, the snippet is pretty simple to build and test. Enjoy!

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

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

/**
 * @snippet       Remove Tax if Field Value Exists - WooCommerce Checkout
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli, BusinessBloomer.com
 * @testedwith    WooCommerce 4.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_taxexempt_checkout_based_on_zip' );
  
function bbloomer_taxexempt_checkout_based_on_zip( $post_data ) {
        WC()->customer->set_is_vat_exempt( false );
        parse_str( $post_data, $output );
        if ( $output['billing_postcode'] === '32444' ) WC()->customer->set_is_vat_exempt( true );
}

No comments:

Post a Comment

Free Shipping Threshold @ Cart Page