This example changes the product tax class for the logged-in administrator role. It demonstrates role-based pricing policy; a WordPress role is not evidence of a legal tax exemption.
Note:
This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.
This documentation covers how to set up tax rates in WooCommerce, as well as how the platform handles taxes/VAT/GST based on these settings — not when or what to charge.
We are not tax professionals; our advice only applies to how to use our software. For advice on what — or when — to charge tax/VAT/GST etc., we recommend consulting a tax professional or accountant.
Every business is unique, and we are unable to cover all possibilities here.
Before you start
↑ Back to topConfigure a Zero rate tax class with a matching zero-percent rate before adding the code. The example uses the class slug zero-rate and the administrator role. Replace both deliberately for your approved policy. It applies to product and variation tax-class getters for the current user; it does not establish a complete exemption system for fees, shipping, guest customers, or manually created orders.
Test on a staging store first. Back up the store and add the snippet through a custom plugin or a snippet-management plugin. Keep a way to disable it if the site fails to load; avoid editing WooCommerce or a parent theme.
Add the snippet
↑ Back to top/**
* Assign a product tax class by customer role.
*
* @package WooCommerce\Docs
*/
/**
* Use the Zero rate class for logged-in administrators.
*
* @param string $tax_class Product tax class.
* @return string
*/
function woo_docs_tax_class_for_administrator( $tax_class ) {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles, true ) ) {
return 'zero-rate';
}
return $tax_class;
}
add_filter( 'woocommerce_product_get_tax_class', 'woo_docs_tax_class_for_administrator' );
add_filter( 'woocommerce_product_variation_get_tax_class', 'woo_docs_tax_class_for_administrator' );
Verify the result
↑ Back to topCompare a taxable simple product and a variation while signed in as an administrator, signed in as another role, and signed out. The administrator should use the configured Zero rate class; the other sessions should keep each product’s original class. Check the cart, checkout, and a test order. Review shipping and fees separately.
Remove or troubleshoot the change
↑ Back to topDisable the snippet and repeat the same test to restore the default behavior. If the result differs, check the tax settings and conflicting customizations before changing the code. Clear relevant caches and test in separate customer sessions.