-5

I want to show custom label and lowest variation price in product listing pages including Home page. Search throughout but didn't found any solution. enter image description here

I have no idea for this. Can somebody help me with this. Any help highly appreciated.

Thanks in advance

WP Learner
  • 788
  • 1
  • 13
  • 34

1 Answers1

1

I've used the below for this...

/**
 * Create our custom pricing format
 *
 * @param float $price
 * @param object $product
 * @return string
 */
function reformat_pricing_labels( $price, $product ) {

    $label = __( 'Starting', 'textdomain' );

    $min_price_regular = $product->get_variation_regular_price( 'min', true );
    $min_price_sale = $product->get_variation_sale_price( 'min', true );

    $max_price = $product->get_variation_price( 'max', true );
    $min_price = $product->get_variation_price( 'min', true );

    if ( $min_price_sale === $min_price_regular ) {
        $price = wc_price( $min_price_regular );
    }

    return $min_price === $max_price ? $price : sprintf( '%s %s', $label, $price );

}
add_filter( 'woocommerce_variable_sale_price_html', 'reformat_pricing_labels', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'reformat_pricing_labels', 10, 2 );

Change the $label value to your needs.

Levi Cole
  • 3,561
  • 1
  • 21
  • 36
  • thank you. Code showing both min price and max price as well. Also, label not showing for all products. Any idea please? – WP Learner Aug 04 '21 at 07:46
  • @WPLearner The label not showing for all products is probably caused by the return condition `$min_price === $max_price` which basically means if the max and min prices are the same, then don't show the label because it's redundant. It doesn't make sense to have the 'Starting' label if the price doesn't vary. – Levi Cole Aug 04 '21 at 07:48
  • If you do want the label to always show despite the price not varying just change the return statement to `return sprintf( '%s %s', $label, $price );` – Levi Cole Aug 04 '21 at 07:50