WooCommerce how to make a user exempt from tax charges

I’ve been working on a WooCommerce project recently, the client asked if I could isolate certain users who would need to be exempt from being charged any tax or VAT on products sold through their WooCommerce shop. This particular shop was behind the standard WordPress login so it was simply a case of:

adding a checkbox to the user’s profile to identify if they were exempt from paying tax or VAT, this would only visible to an Administrator.

use a WooCommerce hook to enable or disable tax charges at the point of checkout for the currently logged in user.

The user has to log in to purchase anything from the shop but they could never get to the /wp-admin/profile.php because WooCommerce, by default, creates all the user’s profile information in the frontend. So, it was just a case of getting the user ID after they log in, check if they have been set as an exempt tax or VAT payer, then filter to enable/disable the tax setting from WooCommerce on the checkout page because this is where the tax is added to the purchase.

WooCommerce has a filter hook for this, it filters the tax setting. Depending on the way the shop’s tax setting has been set up the filter can technically be switched to true or false when it’s loaded on the checkout page.

Because I’m sharing this as a plugin, the first thing to do is check if WooCommerce is even active on the site, we can do that on the activation of this plugin using the activation hook:

Now all you need to do is filter the WooCommerce tax setting. For most users, the tax is charged at the checkout, only a small number of users would be exempt so we only need to check that the user is exempt, if so then switch the setting from true to false: