根据WooCommerce(包括田纳西州)中的用户角色消除所有税收

I need to eliminate all taxes for certain user roles. In my case, they are wholesale customers with a customer wholesale user role/account. I've gotten it to mostly work but in the US, the state of Tennessee is an exception. For some reason, TN still charges tax, even with the code snippets I've tried. I don't know if the tax is being applied to the shipping or the cart total. I know that TN has special tax rules so it's possible that has something to do with it.

(site is littlethingsstudio.com)

I've tried 2 code snippets so far and both don't work completely:

1) from Stackoverflow Role based taxes in woocommerce

add_action( 'woocommerce_before_checkout_billing_form', 'prevent_wholesaler_taxes' );

function prevent_wholesaler_taxes() {

 global $woocommerce;

 if ( current_user_can( 'customer_net30_wholesale' ) || current_user_can( 'customer_wholesale' ) ) {

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

     } else {

          $woocommerce->customer->set_is_vat_exempt(false);
     }
}

2) and from the WooCommerce docs

function wc_diff_rate_for_user( $tax_class, $product ) {
if ( current_user_can( 'customer_net30_wholesale' ) || current_user_can( 'customer_wholesale' ) ) {
    $tax_class = 'Zero Rate';
}
return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );

Here are some screenshots (site is littlethingsstudio.com)

Screenshots showing tax for different states in the US

  • I'm using the Snippets plugin to activate/deactivate code snippets
  • WordPress 5.1.1
  • Flatsome Theme 3.6.2
  • Woo 3.6.1
  • WooCommerce Dynamic Pricing 3.1.13 (for changing product price based on role)
  • WooCommerce Stripe Gateway 4.1.16 (for processing payments)
  • WooCommerce Services 1.19.0 (for automated tax calculation, shipping label printing, and smoother payment setup)

Any help would be greatly appreciated.

The hook woocommerce_product_tax_class is deprecated and replaced. Try the following:

// For products and product variations
add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_tax_rate_by_user_role', 10, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_tax_rate_by_user_role', 10, 2 );
function wc_diff_tax_rate_by_user_role( $tax_class, $product ) {
    if ( ( current_user_can( 'customer_net30_wholesale' ) || current_user_can( 'customer_wholesale' ) ) ) {
        $tax_class = 'Zero Rate';
    }
    return $tax_class;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works (even for Tennessee).