I am using a B2B plugin that allows me to create different pricing for different user groups. The standard pricing is shown for all users until they sign up and account and are added to a group with better pricing (for wholesale customers etc).
I have added some code to say Retail Pricing after the standard pricing. The problem is I don't want this suffix to show once a user is logged in OR to certain user groups as the pricing is no longer retail for these customers, its wholesale.
The code I used is:
function woo_text_after_price( $price ) {
$price .= ' Retail Price';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'woo_text_after_price' );
add_filter( 'woocommerce_cart_item_price', 'woo_text_after_price' );
The B2B plugin I am using is called WooCommerce B2B and was purchased from Code Canyon developed by code4lifeitalia.
Thank you in advance.
I have not tried any resolution yet as I don't know what to try. I know I would need some kind of filter or rule but I don't know how to create one.
The "user group" is called in WordPress a "user role", so in the code below try to define the correct user role(s) slug(s), for your user group(s):
function woo_text_after_price( $price ) {
global $current_user;
// Here below, define the correct user role(s) slug(s) for your user group(s)
$targeted_user_roles = array('user-group1', 'user-group2');
if ( ! array_intersect($targeted_user_roles, $current_user->roles) ) {
$price .= __(' Retail Price');
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'woo_text_after_price' );
add_filter( 'woocommerce_cart_item_price', 'woo_text_after_price' );
It should work.
The same but for unlogged users (without targeting user groups):
function woo_text_after_price( $price ) {
if ( ! is_user_logged_in() ) {
$price .= __(' Retail Price');
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'woo_text_after_price' );
add_filter( 'woocommerce_cart_item_price', 'woo_text_after_price' );