Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Role based taxes in woocommerce

I am trying to set up a woocommerce store so that users who have a role of wholesaler or designer will automatically be exempt from tax and just have tax disappear from the cart/checkout. I've used the dynamic pricing plugin to provide different prices to different roles but there is no options for tax variations.

Someone posted this code:

// Place the following code in your theme's functions.php file and replace tax_exempt_role with the name of the role to apply to
add_action( 'init', 'woocommerce_customer_tax_exempt' );
function woocommerce_customer_tax_exempt() {
    global $woocommerce;
    if ( is_user_logged_in() ) {
        $tax_exempt = current_user_can( 'tax_exempt_role');
        $woocommerce->customer->set_is_vat_exempt( $tax_exempt );
    }
}

This seems to be working on the front end but breaks the backend. after adding it to functions.php when i go back into the admin area and see this: http://i.imgur.com/nNHMSAZ.png (is this just the new chrome error page?)

The other thing I couldn't figure out is how to add 2 roles instead of just one.

Thanks

like image 875
James Avatar asked Jul 25 '13 19:07

James


People also ask

How do I set up taxes in WooCommerce?

Enabling Taxes To access the tax settings screens, they first need to be enabled. Go to: WooCommerce > Settings > General. Select the Enable Taxes and Tax Calculations checkbox. Save changes.

Does WooCommerce take care of taxes?

Yes, WooCommerce takes care of sales tax. You can either configure it to calculate taxes for you, or you can add your own tax rates. If you need to charge sales tax on your orders, WooCommerce makes it easy to do so.

Does WooCommerce manage sales tax?

Once you update your tax settings, your store will collect sales tax at checkout based on the store address in your WooCommerce Settings.

Does WooCommerce collect and remit sales tax?

WooCommerce makes it easy to collect and remit sales tax by automatically calculating the correct tax rate for each customer based on their shipping address. You can also create custom tax rules for specific products or countries. To get started, you'll need to configure your tax settings in WooCommerce.


2 Answers

The following worked for me for user role "wholesaler". Added to functions.php.

add_filter( 'woocommerce_before_checkout_billing_form', 'prevent_wholesaler_taxes' );

function prevent_wholesaler_taxes() {

     global $woocommerce;

     if( current_user_can('wholesaler')) {

              $woocommerce->customer->set_is_vat_exempt(true);

         } else {

              $woocommerce->customer->set_is_vat_exempt(false);
         }
} //end prevent_wholesaler_taxes

To add multiple user roles, just add to the current_user_can(); function. I think this could work:

 if( current_user_can('wholesaler')||current_user_can('another_user_role') ) 
like image 189
dryan1144 Avatar answered Oct 30 '22 22:10

dryan1144


I noticed that when using 'woocommerce_before_checkout_billing_form', you have to update or refresh the checkout page first, then you have to refresh the cart page for it to take effect.

Use these action hooks, 'woocommerce_before_cart_contents' and 'woocommerce_before_shipping_calculator' for the tax exemption to take effect without refreshing the checkout page first.

Note: use the same callback function code as above.

like image 42
Jplus2 Avatar answered Oct 30 '22 21:10

Jplus2