How to control price suffix for B2B users

Some WooCommerce themes (e.g. Flatsome) depending on settings will automatically add "inc. VAT" and "excl. VAT" suffixes to price based on the user's VAT exempt status.

B2BKing sets the user as vat-exempt, but does not directly control the suffix.

If you use a theme that does not automatically modify the suffix, but you would like to better control how this shows for b2b and b2c users, this can be done simply through a code snippet added to functions.php

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_suffix', 99, 4 );
	  
	function add_price_suffix( $html, $product, $price, $qty ){
	    $html = '<small class="woocommerce-price-suffix"> incl. VAT</small>';
	    return $html;
	}
}

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *