Skip to content

Instantly share code, notes, and snippets.

/**
* 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 ) ||
@webthread
webthread / gist:1d0447d2d3c218ee23a13c57dd4eeceb
Created August 5, 2017 08:28
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 ) ||