# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, tax, roles, b2b
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-tax-exempt-role/

## Code

```php
$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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Tax-Exempt Customer Roles" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
