-
-
Save woogist/48c776c39df23d53df8d to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* 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( 'administrator' ) ) { | |
$tax_class = 'Zero Rate'; | |
} | |
return $tax_class; | |
} | |
add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 1, 2 ); | |
add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 1, 2 ); |
OK, then use this code. Maybe can help you.
add_filter( 'woocommerce_get_price_html', 'custom_price_message' ); function custom_price_message($price) { $new_price = $price . ' <span class="custom-price-prefix">' . __('<br>(plus VAT)').'</span>'; return $new_price; }
Yeah I already did that, the problem is that it's just a change for the suffix, not the final price ! The price is still without taxes and I need to force the VAT to be applied on the final price :)
It does not work when a product is added or edit in the Order Admin Page, it is probably another hook that's called, if anyone know please tell me
Hi ! Is there anyone who used this function for Woocommerce Membership Plugin which has Membership Plans?
For reference, this is what I now use:
/** * Apply a zero tax rate for 'administrator' user role. */ function wc_diff_rate_for_user( $tax_class, $product ) { $user_id = get_current_user_id(); $user = get_user_by( 'id', $user_id ); if ( is_user_logged_in() && ! empty( $user ) && in_array( 'administrator', $user->roles ) ) { $tax_class = 'Zero Rate'; } return $tax_class; } add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 1, 2 );
Hello, can you please help, i need to apply zero tax to everyone except wholesaler role. How is that possible?
Hello
I used this code and worked great for simple products. For variable products i still see prices with VAT.
Please advise
OK, then use this code. Maybe can help you.
add_filter( 'woocommerce_get_price_html', 'custom_price_message' ); function custom_price_message($price) { $new_price = $price . ' <span class="custom-price-prefix">' . __('<br>(plus VAT)').'</span>'; return $new_price; }