Role taxes in woocommerce

I am trying to create a woocommerce store so that users who are engaged in wholesale trade or a designer are automatically exempted from taxes and simply lose tax from the basket / statement. I used the dynamic pricing plugin to offer different prices for different roles, but there are no options for changing taxes.

Someone posted this code:

// Place the following code in your theme 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 ); } } 

It seems to work on the front panel, but breaks the backend. after adding it to functions.php, when will I go back to the administration area and see this: http://i.imgur.com/nNHMSAZ.png (is this just a new Chrome error page)?

To others, I could not figure out how to add 2 roles instead of one.

thanks

+6
source share
2 answers

The following worked for me for the "wholesaler" user role. 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 the function current_user_can(); . I think this might work:

  if( current_user_can('wholesaler')||current_user_can('another_user_role') ) 
+8
source

I noticed that when using 'woocommerce_before_checkout_billing_form' you need to first refresh or refresh the checkout page, then you need 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 first updating the checkout page.

Note: use the same callback function code as above.

+2
source

Source: https://habr.com/ru/post/950303/


All Articles