Skip to content

Instantly share code, notes, and snippets.

@webthread
Created August 21, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webthread/7b81c3b2b37b592b39e9c2d1da703da9 to your computer and use it in GitHub Desktop.
Save webthread/7b81c3b2b37b592b39e9c2d1da703da9 to your computer and use it in GitHub Desktop.
Tax rate for user role
/**
* 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