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 ) {
$rule_price = YITH_Role_Based_Prices_Product()->get_variable_product_rule_price( $product );
if ( ! empty( $rule_price['rules']['min'] ) ) {
$price_html = '<del>' . $price_html . '</del>';
}
}
// Return price if min is equal to max.
if ( $min === $max ) {
return $price;
}
return $price_html;
}
return $price;
}
}