• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Apply a default tax rate to a WooCommerce product category

Discover how to configure WooCommerce to apply a specific tax rate to a product category, with a little bit of code.

Although you can apply a tax rate to each product created with WooCommerce, sometimes it can be more convenient to assign the tax rate according to the product category.

Are you interested in this solution? Here’s how to do it:

Code to always apply the same tax rate to a WooCommerce product category

Add the following code at the end of functions.php or in your functionality plugin:

To see this and another 1097 code snippets of this website, login or subscribe here.

This code hooks into the woocommerce_update_product action, which fires every time a product is updated in your store. In the example, it checks if the product belongs to the category with ID 393 and if its tax class is not already ‘zero-rate’. If those conditions are met, it changes the product’s tax class to ‘zero-rate’.

Of course, you can change the category ID (you can check the ID of a category if you go to edit it and check the URL) and the tax class to the one you want. But remember to configure these taxes in WooCommerce settings beforehand.

Conclusion

As you can see, with a few lines of code you can force a tax rate to a specific product category in WooCommerce.

If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.

Benefits of being a subscriber. 🙂

PHP Products WooCommerce

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2026

close-icon

Lost your password?