Exclude Sales Tax for Specific User Roles with WooCommerce

July 16, 2016

WOOCOMMERCE TUTORIALS

Remove Sales Tax for Specific Roles with WooCommerce

David Curtiss

Have you ever needed to remove sales tax for a specific user role in WooCommerce? A commom instance of this application would be for re-sale customers shopping at your store which in many states are not required to pay tax. I am going to show you how to remove sales tax/VAT for specific user roles.

First you are going to want to create a unique user role within WordPress. I do this with the User Role Editor plugin. This plugin is easy to use with many features to customize user roles.

Once you have the plugin installed you are going to navigate to Users –> User Role Editor in the WordPress admin sidebar. When the page loads click “Add Role”.

Make sure to take note of the Role Name (ID) field you enter. You will need this for the code later.

Next you are going to want to head over to Appearance —> Editor to make some modifications to your functions.php file. Some WordPress installations will have the editor disabled for security reasons. If this is the case it is easiest to modify the file via FTP. Make sure to be using a child theme so you won’t lose your updates when your theme is updated.

Paste the code below into your child theme functions.php file.

Make sure to replace ‘role-1’ with the Role Name (ID) you created earlier.

That’s it! Make sure to check out our other tutorials for more WordPress tips & tricks.

Want new articles before they get published?
Subscribe to our Awesome Newsletter.

WebDoc Hosting

WebDoc Security

By David Curtiss

I am a freelance website designer and developer. I enjoy helping people start businesses and writing about entrepreneurship.

Related Articles

20 Comments

  1. Pedro

    Hi,
    I am having problems making variable product tax at checkout.
    It works for simple items but not for variables.
    Can you be so kind to take a look into this code and advise. I tried almost all possible combinations.

    Thanks in advance
    /**
    * Function that filters the variable product hash based on user
    */
    function wc_get_variation_prices_hash_filter( $hash, $item, $display ) {

    // check for the user role
    $user_id = get_current_user_id();
    $user_data = get_userdata($user_id);
    if ( is_user_logged_in() && in_array( ‘clientes_re’, $user_data->roles ) ) {

    // clear key 2, which is where taxes are
    $hash[‘2’] = array();
    }

    // return the hash
    return $hash;
    }
    add_filter( ‘woocommerce_get_variation_prices_hash’, ‘wc_get_variation_prices_hash_filter’, 1, 3 );

    /**
    * Apply a different tax rate based on the user role.
    */
    function wc_diff_rate_for_user( $tax_class, $product ) {
    $user_id = get_current_user_id();
    $user_data = get_userdata($user_id);
    if ( is_user_logged_in() && in_array( ‘clientes_re’, $user_data->roles ) ) {
    $tax_class = ‘R.E’;
    }
    return $tax_class;
    }
    add_filter( ‘woocommerce_product_tax_class’, ‘wc_diff_rate_for_user’, 1, 2 );

    Reply
    • Gloria Bargelli

      Hello, I also found the same problem, did you solve it?

      Reply
    • Eric Dev Wise

      Great snippet! One issue I have run into is that if the user role (dealer in my case) has a failed credit card transaction then the sales tax comes back on the next process. Is there any way to account for this?

      Reply
  2. Andrew Platt

    Hi thanks for the tutorial, we have used this technique. How would we get it to set them back to paying tax if they have been set to be tax-exempt by mistake.

    Reply
    • Andrew Platt

      Never mind – simple or statement did that =)

      Please remove

      Reply
  3. David

    Hey! Do you have any suggestions for how to acquire the ID of a role that already exists? For example, I already have a Dealer role established, but I don’t know how to get the ID to input into your code. It was a role I already established and set up through another application. If I can find the ID of an existing role, then I could use your code.

    Thanks!

    Reply
  4. David

    Works GREAT. Thank you so much. In case others find this, I had already set up a Dealers Level within PaidMembershipsPro, and used pmpro_role_X (and replaced X with the number appended into the Level URL (Memberships/Membership Levels/Edit–then you see the Level ID).

    I hope that helps someone!

    Reply
  5. Andrew Platt

    We have noticed an issue where a tax-exempt order gets tax added after it has been viewed in the order admin system – has anyone else seen this?

    Reply
  6. Brian Richards

    Great snippet. Can you provide a modified snippet to be able to apply this to more than 1 user role?

    Reply
    • David Mason

      Brian, to add multiple roles for discount, simply add this example code after each first instance of the current_user_can( ‘role-1’ )

      current_user_can( ‘role-1’ ) || current_user_can( ‘role-2’ )

      Reply
  7. Carl

    I guess that a common instance of this application would be for re-sale customers shopping at your store which in many states are not required to pay tax.

    Reply
  8. Sherry Muldoon

    This code and plugin works great. We also need to customize the registration form to allow for tax id # input and possible file upload only for a certain user type. Is there another plugin that will be compatible with this one to make those type of changes? Thanks so much

    Reply
    • Drew Gerhard

      I did this part with a ninja form (any of them would work, contact form 7 is free for file uploads) by putting it on it’s own page and then added the link to the customer account page so they have to be logged in to see it. Then once they verify the user is legit, they just have to change that users role to the tax free customer role and it’s done.

      Reply
  9. Sherry Muldoon

    This worked great! We also need to allow a certain user the ability to put in their tax id number at registration or even upload a file. Is there another plugin that might be compatible with this one for those options?

    Reply
  10. Panos Koukos

    Hello,
    is this possible to work for more than one user role?
    Thank you!

    Reply
  11. Evan Holloway

    Hey, thanks for the tip!

    Any idea how I could remove the Excise Rate but keep the Standard Rate based on user?

    Thanks!

    Reply
  12. Bas

    Great solution, but it’s not being applied on the checkout. It is working correctly within the cart, but as soon as I’m in the checkout a form of tax is being applied.

    Reply
  13. Eric Dev Wise

    Great Snippet! One issue I am running into is if the user role (dealer in my case) has a failed credit card transaction, then the sales tax appears on the next attempted process. Is there any way to account for this?

    Reply
  14. Asier

    It’s not being applied on the checkout… any update for this solution?

    Reply
  15. Asier

    it’s not being applied on the checkout. It is working correctly within the cart, but as soon as I’m in the checkout a form of tax is being applied.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Shares
Share This