How to control price suffix for B2B users / VAT exempt users

Table of Contents

UPDATE: Since version 3.7.1, B2BKing can directly set the price suffix based on the user's VAT-exempt status. This is controlled through the setting in B2BKing -> Settings -> Other -> Modify price suffix for VAT-exempt users

By default the plugin uses 'ex. VAT' and 'inc. VAT'. If you would like to change / translate this:

  • You can translate it with a plugin such as Loco Translate.
  • Another option is to modify it by using filter code snippets. The 2 filter hooks that can be used are b2bking_price_suffix_ex_vat and b2bking_price_suffix_inc_vat

Snippet example:

add_filter('b2bking_price_suffix_inc_vat', function($val){
	return 'including VAT';
}, 10, 1);

Another filter you can use is "apply_filters('b2bking_modify_suffix', true, $user_id". This can allow you to show the suffix for some users, but not for others. Here is an example of a code snippet to allow you to show the suffix only to logged in users (but not logged out users).

add_filter('b2bking_modify_suffix', function($val, $user_id){
	if ($user_id === 0){
		return false;
	}
	return $val;
}, 10, 2);

Additional Info #

Some WooCommerce themes depending on settings will automatically add "inc. VAT" and "excl. VAT" suffixes to price based on the user's VAT exempt status. In this case, you can simply disable B2BKing's setting if necessary.

If you want to control the suffix differently, such as based on B2BKing B2B groups, you can disable that setting and use the below code snippet.

The code below sets "excl. VAT" for b2b users and "incl. VAT" for b2c users as suffixes:

// get if user is b2b
$user_is_b2b = get_user_meta(get_current_user_id(),'b2bking_b2buser', true);

if ($user_is_b2b === 'yes'){
	add_filter( 'woocommerce_get_price_suffix', 'add_price_suffix', 99, 4 );
	  
	function add_price_suffix( $html, $product, $price, $qty ){
	    $html = '<small class="woocommerce-price-suffix"> excl. VAT</small>';
	    return $html;
	}
} else {
	add_filter( 'woocommerce_get_price_suffix', 'add_price_suffixtwo', 99, 4 );
	  
	function add_price_suffixtwo( $html, $product, $price, $qty ){
	    $html = '<small class="woocommerce-price-suffix"> incl. VAT</small>';
	    return $html;
	}
}

Powered by BetterDocs