Hide the Price Range Until a Variation Is Chosen
Removes the "10.00 to 50.00" range at the top of variable product pages, so the exact price appears only once the shopper picks options.
Opens WPIDE on
Code
add_filter( 'woocommerce_get_price_html', function ( $html, $product ) {
if ( ! is_product() || ! $product->is_type( 'variable' ) || $product->get_id() !== get_queried_object_id() ) {
return $html;
}
if ( doing_action( 'woocommerce_single_product_summary' ) && $product->get_variation_price( 'min' ) !== $product->get_variation_price( 'max' ) ) {
return '';
}
return $html;
}, 20, 2 );
add_filter( 'woocommerce_show_variation_price', '__return_true' );
Notes
Shop listings keep their price range, and the variation price shows even when all variations cost the same.
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.