dongqishou7471 2019-04-22 14:13
浏览 35

根据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.

  • 写回答

1条回答 默认 最新

  • doumi4676 2019-04-22 15:55
    关注

    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).

    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来