• Hi, what I want to achieve is:

    Public site: Price is including VAT
    Trade site: Price is ex VAT with the suffix “ex VAT ({price_including_tax} inc VAT)”. In the cart it the price is inc VAT.

    So far I have set the above suffix to appear to Trade Users to see the price as per this default. I have then set all other users -Admin, guest, customer…- to see the price including tax. Which works, however it doesn’t remove the suffix.

    So, can anyone suggest code that will hide this suffix from all desired users.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter PossiblyMaybe

    (@possiblymaybe)

    .woocommerce-price-suffix {
      display: none;
    }
    .single-product .product-price-wrap .woocommerce-price-suffix {
      display: block !important;
    }

    Found this bit of code to hide the suffix, but how do I make it apply to specific user roles?

    Alternately, is there a code way to add a suffix to a specific user role?

    Thread Starter PossiblyMaybe

    (@possiblymaybe)

    Also found this bit of code but it isnt working for me.

    add_filter('eh_pricing_adjustment_modfiy_price', 'eh_pricing_adjustment_add_price_suffix', 10, 2);
    
    function eh_pricing_adjustment_add_price_suffix($price, $current_user_role) {
    	// Change the text 'Excluding Tax' to desired text.
    	$your_suffix = 'Excluding Tax';
    	if($current_user_role == 'administrator') {
    		$price .= ' '.$your_suffix;
    	}
    	return $price;
    }

    I changed it slightly for my user and suffix, including the Woo shortcode, to

    add_filter('eh_pricing_adjustment_modfiy_price', 'eh_pricing_adjustment_add_price_suffix', 10, 2);
    
    function eh_pricing_adjustment_add_price_suffix($price, $current_user_role) {
    	$your_suffix = 'ex VAT ({price_including_tax} inc VAT)';
    	if($current_user_role == 'default_wholesaler') {
    		$price .= ' '.$your_suffix;
    	}
    	return $price;
    }

    Can anyone advise what might be wrong?

    I have got a big closer with the following:

    function custom_price_suffix( $price, $product ) {
        $your_suffix = 'ex VAT ({price_including_tax} inc VAT)';
    
        // check current user role
        $user = wp_get_current_user();
        $roles = ( array ) $user->roles;
      
        if ( in_array( 'administrator', $roles ) ) {
            $price .= $your_suffix;
        } elseif ( in_array( 'default_wholesaler', $roles ) ) {
            $price .= $your_suffix;
        }
    
        // return $price;
        return apply_filters( 'woocommerce_get_price', $price );
    }
    add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );

    However this is adding the suffix twice. It is also not recognising the Woo shortcode {price_including_tax} and not displaying the price.

    Can anyone help? Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide price display suffix based on user role’ is closed to new replies.