繁体   English   中英

在woocommerce中基于角色的税收

[英]Role based taxes in woocommerce

我正在尝试建立一个woocommerce商店,以便具有批发商或设计师角色的用户将自动免税,只需从购物车/结账中消失税。 我使用动态定价插件为不同的角色提供不同的价格,但税收变化没有选项。

有人发布了这段代码:

// 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错误页面吗?)

我无法弄清楚的另一件事是如何添加2个角色而不只是一个角色。

谢谢

以下为我的用户角色“批发商”工作。 添加到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(); 功能。 我认为这可行:

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

我注意到在使用'woocommerce_before_checkout_billing_form'时 ,您必须先更新或刷新结帐页面,然后您必须刷新购物车页面才能使其生效。

使用这些操作挂钩, 'woocommerce_before_cart_contents''woocommerce_before_shipping_calculator'使免税工作生效,而无需先刷新结帐页面。

注意:使用与上面相同的回调函数代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM