WooCommerce Tax display by customer role?

In a WooCommerce store, I have two roles: Customer and Professional. In the WooCommerce options, I have selected to display prices in the cart and checkout with taxes included.

Now, I need for the Professional role to have the opposite setting, that in the cart and checkout the prices are displayed without taxes included.

Is there a way to modify that option depending on the role? If it is possible to do so, is there a filter or a clue from which I can start researching?

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

4 thoughts on “WooCommerce Tax display by customer role?

  1. I’ve tried this code snippet, but unfortunately, it is not working. I have a user role set for wholesale customers who will not be charged taxes. Would be great instead of buying a plugin!

  2. You can definitely do that. First of all https://www.businessbloomer.com/disable-payment-gateway-specific-user-role-woocommerce/ should help you understand how to run a function only when a user has a certain role.

    Second, you can “set” whatever WordPress option you like with the https://developer.wordpress.org/reference/hooks/pre_option_option/ filter

    This is a similar scenario: https://www.businessbloomer.com/woocommerce-hide-out-of-stock-items-exception/

    1. This code snippet should do the trick:

      function bb_override_wc_tax_display( $v ) {
          if ( current_user_can( 'professional' ) ) {
              return 'excl';
          }
      
          return $v;
      }
      
      add_filter( 'pre_option_woocommerce_tax_display_shop', 'bb_override_wc_tax_display' );
      add_filter( 'pre_option_woocommerce_tax_display_cart', 'bb_override_wc_tax_display' );
      

      I’m unsure how you added the “Professional” role to your site, but this code snippet is assuming there is a capability called “professional”.

Reply

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