首页 文章

WooCommerce - 为一些不适用于Variable产品的特定用户角色启用“零费率”税级

提问于
浏览
0

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

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 );

Its working fine for simple product but for variable product minimum and maximum prices still showing inclusive tax prices.

请给我解决方案如何排除税或对变量产品应用“零利率” .

作为参考,我试过 this solution but didn't worked.

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 );

1 回答

  • 0

    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 ) ;
    

相关问题