Hi. How can we help?

Role Based Price - How to change the price display for variable products

If you want change the price display for variable products (size range from 100 $ -200 $ to format From: $ 100)
Add this php code to the file functions.php of your theme:

 

if( defined( 'YWCRBP_PREMIUM') && function_exists( 'YITH_Role_Based_Prices_Product' ) ) {
add_filter( 'ywcrbp_variable_regular_price_html', 'ywcrbp_my_wc_custom_variable_price_html', 10, 4 );
add_filter( 'ywcrbp_variable_sale_price_html', 'ywcrbp_my_wc_custom_variable_price_html', 10, 4 );
add_filter( 'ywcrbp_variable_your_price_html', 'ywcrbp_my_wc_custom_variable_price_html', 10, 4 );
/**
* @param string $price
* @param WC_Product_Variable $product
* @return string
*/
function ywcrbp_my_wc_custom_variable_price_html( $price, $product, $min, $max )
{

if( $product->get_type() == 'variable' ) {

$suffix = YITH_Role_Based_Prices_Product()->get_price_suffix( $product );

$current_filter = current_filter();
$price_html = sprintf( __( 'From %s', 'your-text-domain' ), wc_price( $min ) . $suffix );
if( 'ywcrbp_variable_regular_price_html' == $current_filter || 'ywcrbp_variable_sale_price_html' == $current_filter ){

if( 'no_price' !== YITH_Role_Based_Prices_Product()->get_role_based_price( $product ) ){

$price_html = '<del>'.$price_html.'</del>';
}
}
// Return price if min is equal to max.
if( $min === $max ) {
return $price;
}
return $price_html;
}
return $price;
}
}
Was this article helpful?
3 out of 10 found this helpful

Back to Help Center >