I want to set lower tax rates for certain user class / user role in Woocommerce.
1 Answers
Best Answer
Instructions:
- Go to Woocommerce -> Settings -> Tax
- Go to Reduced Rate Rates
- Type in or import the proper tax rates
- If you are importing, note that the “Tax Class” column needs to say “Reduced rate”. Otherwise if you leave it blank, all of the entries will go to the normal rate table
- Use the code below, add the user roles that should have lower tax rate to $not_taxed_roles
- Add the modified code to functions.php of the theme / child theme you are using.
Credit: https://github.com/woocommerce/woocommerce/issues/14939
/** * Apply a different tax rate based on the user role. * * @param $tax_class * @param $product * * @return string */ function woo_diff_rate_for_user( $tax_class, $product ) { $current_user = wp_get_current_user(); $roles = $current_user->roles; $current_user_role = $roles[0]; $not_taxed_roles = array("customer", "administrator"); if (is_user_logged_in() && in_array($current_user_role, $not_taxed_roles)) { //$tax_class = "Zero Rate"; $tax_class = "Reduced Rate"; } return $tax_class; } add_filter( "woocommerce_product_get_tax_class", "woo_diff_rate_for_user", 1, 2 ); add_filter( "woocommerce_product_variation_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
In addition to the above, if you want to have shipping tax rate to have the same changes as above, you need to set your woocommerce tax settings:
- Go to Woocommerce -> Settings -> Tax
- Change Shipping tax class to “Shipping Tax Class based on Cart Items”