I need apply a different tax if the user have a specific role, but only in certains product's categories.
Example: if customer A with role "Vip" buy an item of category "Bravo" or "Charlie" the tax applied will be at 4% instead 22%
This is the code in part wrote by me another part taken on google, but I don't understand where I wrong.
Please someone can help me?
function wc_diff_rate_for_user( $tax_class, $product ) {
global $woocommerce;
$lundi_in_cart = false;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$terms = get_the_terms( $_product->id, 'product_cat' );
foreach ($terms as $term) {
$_categoryid = $term->term_id;
}
if (( $_categoryid === 81 ) || ( $_categoryid === 82 ) )) {
if ( is_user_logged_in() && current_user_can( 'VIP' ) ) {
$tax_class = 'Reduced Rate';
}
}
}
return $tax_class;
}