# Zero-Rate Tax Class for a Category

> Applies a different tax class, such as Zero rate or Reduced rate, to every product in chosen categories, so you do not have to edit each product.

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

## Code

```php
$wpide_tax_class_cats = array( 'books', 'childrens-clothing' ); // Category slugs.
$wpide_tax_class_slug = 'zero-rate';                           // Tax class slug.

$wpide_tax_class = function ( $class, $product ) use ( $wpide_tax_class_cats, $wpide_tax_class_slug ) {
    $id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();

    return has_term( $wpide_tax_class_cats, 'product_cat', $id ) ? $wpide_tax_class_slug : $class;
};

add_filter( 'woocommerce_product_get_tax_class', $wpide_tax_class, 10, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', $wpide_tax_class, 10, 2 );
```

## Notes

Use the tax class slug from WooCommerce > Settings > Tax (zero-rate, reduced-rate); variations follow their parent's categories.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Zero-Rate Tax Class for a Category" 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/
