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

查看:23
本文介绍了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天全站免登陆