Created
August 21, 2017 14:23
-
-
Save webthread/7b81c3b2b37b592b39e9c2d1da703da9 to your computer and use it in GitHub Desktop.
Tax rate for 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. | |
*/ | |
function wc_diff_rate_for_user( $tax_class, $product ) { | |
$tax_class = 'zero-rate'; | |
// Getting the current user | |
$current_user = wp_get_current_user(); | |
$current_user_data = get_userdata($current_user->ID); | |
if ( is_user_logged_in() && | |
in_array( 'au_export_trade_45', $current_user_data->roles ) || | |
in_array( 'row_trade_45', $current_user_data->roles ) || | |
in_array( 'row_distributor', $current_user_data->roles ) || | |
in_array( 'eu_ext_trade_45', $current_user_data->roles ) || | |
in_array( 'us_distributor_50', $current_user_data->roles ) || | |
in_array( 'us_trade_40', $current_user_data->roles )) { | |
$tax_class = 'Zero Rate'; | |
} | |
return $tax_class; | |
} | |
add_filter( 'woocommerce_product_get_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