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
The following worked for me for user role “wholesaler”. Added to functions.php.
To add multiple user roles, just add to the
current_user_can();
function. I think this could work: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.