Show Prices Without Tax to Business Customers
Displays shop and cart prices excluding tax for trade roles, while regular shoppers keep seeing tax-inclusive prices.
Opens WPIDE on
Code
$wpide_b2b_display_roles = array( 'wholesale_customer', 'business' ); // Roles that see prices excluding tax.
$wpide_b2b_display = function ( $value ) use ( $wpide_b2b_display_roles ) {
if ( ! is_user_logged_in() ) {
return $value;
}
return array_intersect( $wpide_b2b_display_roles, (array) wp_get_current_user()->roles ) ? 'excl' : $value;
};
add_filter( 'option_woocommerce_tax_display_shop', $wpide_b2b_display );
add_filter( 'option_woocommerce_tax_display_cart', $wpide_b2b_display );
add_filter( 'woocommerce_get_variation_prices_hash', function ( $hash ) use ( $wpide_b2b_display ) {
$hash['wpide_tax_display'] = $wpide_b2b_display( 'default' );
return $hash;
} );
Notes
Only changes how prices are shown; the tax charged at checkout is unchanged.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.