【问题标题】:WooCommerce - Enabling "Zero rate" tax class to some specific user roles not working for Variable productWooCommerce - 为某些不适用于可变产品的特定用户角色启用“零税率”税级
【发布时间】:2017-10-18 05:58:36
【问题描述】:

我已通过以下代码在商店页面和购物车页面中为批发客户申请“零税率”税级-

function zero_rate_for_custom_user_role( $tax_class, $product ) {
// Getting the current user 
$current_user = wp_get_current_user();
$current_user_data = get_userdata($current_user->ID);

if ( in_array( 'wholesale_customer', $current_user_data->roles ) )
    $tax_class = 'Zero Rate';

return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'zero_rate_for_custom_user_role', 1, 2 );

它适用于简单产品,但对于可变产品最低和最高价格仍显示含税价格。

请给我解决方案,我怎样才能排除税或对可变产品应用“零税率”。

作为参考,我已尝试此解决方案但没有奏效。

function woocommerce_variation_prices_hash($price_hash, $product, $display) {
if ( $display ) 
    $price_hash[] = $product->get_tax_class();
return $price_hash;
}
add_filter( 'woocommerce_get_variation_prices_hash', 'woocommerce_variation_prices_hash', 10, 3 );

【问题讨论】:

    标签: woocommerce


    【解决方案1】:

    Woocommerce 已弃用此挂钩。检查下面的钩子并告诉我。

        public function eh_diff_rate_for_user( $tax_class, $product ) {
      // Getting the current user 
        $current_user = wp_get_current_user();
        $current_user_data = get_userdata($current_user->ID);
    
        if ( in_array( 'administrator', $current_user_data->roles ) || in_array( 'reseller', $current_user_data->roles ) )
            $tax_class = 'Zero Rate';
    
        return $tax_class;
    }
            (WC()->version < '2.7.0') ? add_filter( 'woocommerce_product_tax_class', array($this,'eh_diff_rate_for_user'), 1, 2 ) : add_filter( 'woocommerce_product_get_tax_class', array($this,'eh_diff_rate_for_user'), 1, 2 ) ;
    

    【讨论】:

    • 不工作!。警告 call_user_func_array() 期望参数 1 是有效的回调,第一个数组成员不是有效的类名或对象
    • 您使用的是哪个 woo 商务版?
    猜你喜欢
    • 2017-02-11
    • 2017-04-13
    • 2020-11-17
    • 2021-08-12
    • 2017-06-30
    • 2016-05-04
    • 2021-11-30
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多