Tax Exempt Customers for Woocommerce

Tax Exempt

I recently had a client who uses WordPress and Woocommerce for his e-commerce site ask me to come up with a method of making some customers tax exempt. He primarily sells to retail customers, but he has a number of resellers who use the site. The resellers should not pay sales tax, even though they reside in a state which does charge sales tax for retail customers.

I found some information on Woocommerce’s site which recommended extending the capabilities for the “customer” user role and adding an action to set the value of “set_is_vat_exempt” into the child theme’s functions.php in order to make some customers tax exempt. Unfortunately, the code snippet, which as of this writing hadn’t been updated since 2013, didn’t work, throwing a fatal PHP error on the test site and taking the entire site down.

Although, in the end, the fix was simple, it took a while for me to come up with a working solution, so I’d like to share it here, hopefully saving someone else the time and trouble of setting up tax exempt customers in Woocommerce. I’ve tested this approach using WordPress 4.9.6 and Woocommerce 3.4.2.

The first step is to add a new capability to extend the “Customer” user role. I chose to extend the capabilities of the “Customer” user role rather than creating a new user role because it seems like it will be more future-proof.

To add the new capability to the “Customer” user role and make it easy for the client to make specific customers tax exempt, I installed Vladimir Garagulya’s plugin User Role Editor. While it may be possible to use another user role editor, and in fact Woocommerce recommends some other ones for this purpose, User Role Editor adds convenient UI elements to the Users’ UI in WordPress that makes it ideal. In my testing, it installed cleanly, is well-documented, has an easy to use UI, has the capability to clean up user roles and capabilities, and worked flawlessly without generating any errors.

Add the Tax-Exempt User Role

Once you’ve installed User Role Editor, go Users -> User Role Editor, and click the “Add Capability” button to open the “Add Capability” dialog box.

Enter “tax_exempt” as the ID for the “Capability name (ID)” and click “Add Capability.”

Add Tax-Exempt Capability to Your Theme

In the functions.php of your child theme, add the following code:

/* 
      ******************* Add Tax Exempt Capability *******************
      This section sets up the ability to have customers who are tax-exempt. To use it, you need to install User Role Editor by Vladimir Garagulya 
      and add a capability to the Customer role with the ID "tax_exempt," which you then add to each user you want to be tax exempt by 
      going Users -> All Users and clicking the  "Capabilities" link for the customer/user you want to be tax-exempt. In the list of capabilities, check 
      the box by "tax_exempt," then click Update.   
   */
   if (is_user_logged_in() && !is_admin()) {
      add_filter( 'init', 'make_customer_tax_exempt' );
   }
   function make_customer_tax_exempt() {
      $tax_exempt = current_user_can( 'tax_exempt');
      wc()->customer->set_is_vat_exempt( $tax_exempt );
   }
   // This ends the tax-exempt section.

Make Customers Tax Exempt

You’re now ready to make specific customers tax exempt.

In order to make a customer tax exempt, you use the UI elements added by User Role Editor. There are currently two ways to access the User Role Editor UI for a specific customer:

  1. Go Users -> All Users, use the Search function to find the user, then click the “Edit” link and scroll down to the “Additional Capabilities” section and click the “Edit” link next to “Capabilities.”
  2. Go Users -> All Users, use the Search function to find the user, then click the “Capabilities” link buy the user’s name.

Once you’re at the User Role Editor page, verify that you have selected the correct user. (Under the page title it will list, “Change capabilities for user: <username>” rather than a user role dropdown.) Scroll down the list of capabilities until you find “tax_exempt.” Check the box by “tax_exempt” and click the “Update” button to save your changes.

Whether the user selects products before logging in and then checks out, or logs in before selecting products, they won’t be charged sales tax.