2
votes

Hi I am using this function to apply tax class on WooCommerce Products and also checking user role.

/* Apply a different tax rate based on the user role. */
function wc_diff_rate_for_user( $tax_class, $product ) {
    if ( is_user_logged_in() && current_user_can( 'business' ) ) {
        $tax_class = 'Zero Rate';
    }
    return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );

that function works on simple products, but on the variable products tax is not deducting tax from the product prices.

On the variable product minimum and maximum prices still getting inclusive tax prices.

Looking for function which can apply tax on variable product minimum and maximum prices.

Thanks in advance.

1

1 Answers

0
votes

it's a transient problem. It didn't include the tax class, so the transient didn't know there was a change of tax class... you can fixed it by changing the price hash of the transient... add this code to your functions.php

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