Woocommerce - How to activate "zero rate" tax class for a user type and for a specific category?

Asked

Viewed 14 times

0

On the Woocommerce site that I am developing, I will be selling not only to the end customer, but also to resellers. The problem is that dealers are exempt from TAX and therefore need a custom function to activate the zero tax rate for certain type of user.

Therefore, my problem is that the code I have works perfectly (when the user is an administrator or reseller), but I do not know how to make these changes to reflect only one product category (wine).

Here’s the code I’m using:

function wc_diff_rate_for_user( $tax_class, $product ) {
    $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;
}
add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );

How can I make this work only in one product category?

1 answer

0

You can use $product->get_categories() to list the product categories.

So you can check whether or not the product is included in the desired category, and create a new conditional, just like you did for the user roles.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.