Add a custom label to the max price for Woocommerce variable products

Viewed 637

In WooCommerce, I should need to show all variation prices like in this site koenigvineyards.com, with the Min price and the "Wine club price" (Max price).

How I can add a custom label before the Max price of a variable product in WooCommerce?

1 Answers

To add a custom text label to the Max price of a variable product (like "Wine club price"), you can use this function hooked in woocommerce_format_price_range filter hook this way:

add_filter( 'woocommerce_format_price_range', 'custom_format_price_range', 10, 3 );
function custom_format_price_range( $price, $from, $to ) {
    $text_max = '<span class"wine-club-label">'.__( "Wine club price" ).': </span>';
    $price = sprintf( _x( '%1$s &ndash; %2$s', 'Price range: from-to', 'woocommerce' ), is_numeric( $from ) ? wc_price( $from ) : $from, is_numeric( $to ) ? $text_max . wc_price( $to ) : $text_max . $to );
    return $price;
}

Code goes in function.php file of your active child theme (or active theme) or in any plugin file.

Tested and works.

Related