Tax-Exempt Customer Roles
Removes tax from the cart and checkout for customers with roles you choose, such as charities, resellers or schools with tax exemption.
Opens WPIDE on
Code
$wpide_tax_exempt_roles = array( 'tax_exempt', 'wholesale_customer' ); // Roles without tax.
add_action( 'woocommerce_before_calculate_totals', function () use ( $wpide_tax_exempt_roles ) {
if ( ( is_admin() && ! wp_doing_ajax() ) || ! WC()->customer ) {
return;
}
$exempt = is_user_logged_in() && array_intersect( $wpide_tax_exempt_roles, (array) wp_get_current_user()->roles );
if ( $exempt ) {
WC()->customer->set_is_vat_exempt( true );
}
}, 5 );
Notes
Orders record the exemption in WooCommerce's is_vat_exempt field, so keep proof of exemption on file for each customer.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.