Skip to content

Instantly share code, notes, and snippets.

@webthread
Created August 5, 2017 08:28
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/1d0447d2d3c218ee23a13c57dd4eeceb to your computer and use it in GitHub Desktop.
Save webthread/1d0447d2d3c218ee23a13c57dd4eeceb to your computer and use it in GitHub Desktop.
WC Apply a different tax rate based on the user role
/**
* 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