Show "From" Price Instead of a Price Range
Replaces price ranges like "$10 - $40" on variable products with a shorter "From $10", which reads better on shop pages.
Opens WPIDE on
Code
add_filter( 'woocommerce_variable_price_html', function ( $html, $product ) {
$prefix = 'From'; // Text shown before the lowest price.
$min = $product->get_variation_price( 'min', true );
$max = $product->get_variation_price( 'max', true );
if ( '' === $min || $min === $max ) {
return $html;
}
return sprintf( '<span class="wpide-from">%s</span> %s', esc_html( $prefix ), wc_price( $min ) . $product->get_price_suffix() );
}, 10, 2 );
Notes
When all variations cost the same, the normal single price is shown.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.