Created
August 5, 2017 08:28
-
-
Save webthread/1d0447d2d3c218ee23a13c57dd4eeceb to your computer and use it in GitHub Desktop.
WC Apply a different tax rate based on the user role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Apply a different tax rate based on the user role. Updated 2017 | |
*/ | |
function wc_diff_rate_for_user( $tax_class, $product ) { | |
$user_id = get_current_user_id(); | |
$user_data = get_userdata($user_id); | |
if ( is_user_logged_in() && | |
in_array( 'au_export_trade_45', $user_data->roles ) || | |
in_array( 'row_trade_45', $user_data->roles ) || | |
in_array( 'row_distributor', $user_data->roles ) || | |
in_array( 'eu_ext_trade_45', $user_data->roles ) || | |
in_array( 'row_trade_45', $user_data->roles ) || | |
in_array( 'us_distributor_50', $user_data->roles ) || | |
in_array( 'us_trade_40', $user_data->roles )) { | |
$tax_class = 'Zero Rate'; | |
} | |
return $tax_class; | |
} | |
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment