woocommerce/购物车页面中的基于角色的税收 [英] Role based taxes in woocommerce / Cart page

查看:77
本文介绍了woocommerce/购物车页面中的基于角色的税收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个拥有多个用户(B2C和B2B)的woocommerce商店.其中一些将自动免税,只是从购物车/结帐台中消失了税款.我使用了动态定价插件来为不同的角色提供不同的价格,但是没有税收变动的选择.

I've set up a woocommerce store with multiple users (B2C & B2B). Some of them will automatically be exempt from tax and just have tax disappear from the cart/checkout. I've used a dynamic pricing plugin to provide different prices to different roles but there is no options for tax variations.

我找到了这个答案,并试图将其放置在 woocommerce中基于角色的税项中但正如@ Jplus2所讲的那样,@ dryan144解决方案不是很好,因为它仅在结帐期间应用,而不是在购物车上应用.我试图找出方法,但仍然必须刷新我的购物车"页面将税显示为0(因为这些税已包含在来宾"或客户"的价格中,那么当我的购物车页面被调用时,是否有任何帮助启动该操作的帮助?

I found this answer and tried to put it in place Role based taxes in woocommerce but as @Jplus2 is telling, @dryan144 solution is not good because it is only applied during the checkout and not on the cart. I tried to figure out the way to do it but I still do have to refresh my 'cart' page to display taxes to 0 (as they are included in the price for "guest" or "customer", any help to launch the action when my cart page is called?

我做了以下事情:

add_filter( 'woocommerce_before_cart_contents', 'prevent_wholesaler_taxes' );
add_filter( 'woocommerce_before_shipping_calculator', 'prevent_wholesaler_taxes' );
add_filter( 'woocommerce_before_checkout_billing_form', 'prevent_wholesaler_taxes' );

function prevent_wholesaler_taxes() {
     global $woocommerce;
     if ( is_user_logged_in() && !(current_user_can('customer'))){
              $woocommerce->customer->set_is_vat_exempt(false);
         } else {
              $woocommerce->customer->set_is_vat_exempt(true);
         }
} //end prevent_wholesaler_taxes

有时它会立即工作,但大多数情况下只有在刷新购物车后才能工作,这不好.尝试添加 https://eshoes.com.au/product/test-shoes08/放入购物车,然后->查看您的购物篮

It's working straight away sometimes but most of the time it's only after working after a refresh of my cart which is not good. Try to add https://eshoes.com.au/product/test-shoes08/ to the cart then -> View your basket

任何帮助将不胜感激;)

Any help would be greately appreciated ;)

欢呼

推荐答案

此解决方案效果很好,而不是使用 set_is_vat_exempt(),我只使用了$ tax)class =零费率":

This solution works perfectly, instead of using set_is_vat_exempt() I simply used $tax)class = 'Zero Rate':

add_filter( 'woocommerce_before_cart_contents', 'wc_diff_rate_for_user', 1, 2 );
add_filter( 'woocommerce_before_shipping_calculator', 'wc_diff_rate_for_user', 1, 2);
add_filter( 'woocommerce_before_checkout_billing_form', 'wc_diff_rate_for_user', 1, 2 );
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );
function wc_diff_rate_for_user( $tax_class ) {

    if ( !is_user_logged_in() || current_user_can( 'customer' ) ) {
        $tax_class = 'Zero Rate';
    }
    return $tax_class;
}

这篇关于woocommerce/购物车页面中的基于角色的税收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆