woocommerce中基于角色的税收 [英] Role based taxes in woocommerce

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

问题描述

我正在尝试建立woocommerce商店,以便具有批发商或设计师角色的用户将自动免税,而从购物车/结帐台中消失的税款也将自动免税.我使用了动态定价插件来为不同的角色提供不同的价格,但是没有税收变动的选择.

I am trying to set up a woocommerce store so that users who have a role of wholesaler or designer will automatically be exempt from tax and just have tax disappear from the cart/checkout. I've used the dynamic pricing plugin to provide different prices to different roles but there is no options for tax variations.

有人发布了此代码:

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

这似乎在前端起作用,但破坏了后端.将其添加到functions.php后,当我回到管理区域并看到以下内容: http://i.imgur.com/nNHMSAZ .png (这仅仅是新的chrome错误页面吗?)

This seems to be working on the front end but breaks the backend. after adding it to functions.php when i go back into the admin area and see this: http://i.imgur.com/nNHMSAZ.png (is this just the new chrome error page?)

我不知道的另一件事是如何添加2个角色,而不只是一个.

The other thing I couldn't figure out is how to add 2 roles instead of just one.

谢谢

推荐答案

以下内容对于我的用户角色批发商"有用.已添加到functions.php.

The following worked for me for user role "wholesaler". 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

要添加多个用户角色,只需添加到current_user_can();函数.我认为这可能有效:

To add multiple user roles, just add to the current_user_can(); function. I think this could work:

 if( current_user_can('wholesaler')||current_user_can('another_user_role') ) 

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

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