0
votes

I have applied "Zero rate" tax class for wholesale customer in shop page and cart page by following code-

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.

Please, give me solution how can I exclude the tax or applied "Zero rate" for variable product too.

For reference I have tried 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

1 Answers

0
votes

Woocommerce Deprecated this hook. Check below hook and let me know.

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