Set up different tax rates for B2B and B2C in WooCommerce

In previous articles, we've discussed how to show prices including tax for B2C, and excluding tax for B2B.

This article is NOT about that. In this article, we will discuss how to set different tax rates for B2B and B2C user. For example, this would mean a B2B user could pay a 10% tax in Quebec, while a B2C user could pay 15%. This method also allows you set different taxes for each city, country, postcode, etc.

Let's start and give an example. Follows these steps:

1) First, I go to WooCommerce -> Settings -> Tax and I add 'B2B' as an additional tax class:

1867521542.png

After saving settings, this creates an additional tax tab for 'B2B Rates':

2) Now I add the following PHP code snippet:

add_action('plugins_loaded', function(){
	
	add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 10000, 2 );
	add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10000, 2 );
	function wc_diff_rate_for_user( $tax_class, $product ) {
		$user_id = get_current_user_id();
		$is_b2b = get_user_meta($user_id,'b2bking_b2buser', true);
	    if ($is_b2b === 'yes'){
			$tax_class = 'B2B';
	    }
		return $tax_class;
	}
	
	add_filter( 'b2bking_taxable_fee_tax_class', function($val){
		$user_id = get_current_user_id();
		$is_b2b = get_user_meta($user_id,'b2bking_b2buser', true);
		if ($is_b2b === 'yes'){
			$val = 'B2B';
		}
		return $val;
	});

});

This makes sure that the B2B rate is selected for B2B users (B2B users as defined by the B2BKing plugin = part of a B2B group).

3) To test this, in WooCommerce -> Settings -> Tax -> B2B Rates, I set a 10% rate for Canada

7216138389.png

The standard rate (let's say this is the B2C rate), I set to 20% for Canada:

9438736548.png

Now I add products worth $1000 to cart.

When I'm logged in as a B2C user, the rate applied is the standard rate (20%) and I pay $1200.

When I'm logged in as a B2B user, the B2B rate is applied (10%) and I pay $1100:

Powered by BetterDocs