Select Page

If you sell a variable product on WooCommerce, it’s quite likely that different options come with different prices. In your store, customers can then choose a certain variation and will be charged the according price.

When selling many different options, in some cases store owners don’t want their customers to look at the full price spectrum when they get started. One reason could be, that customers sometimes don’t want to pay more, if they now the cheapest price from the start. Or customers shouldn’t be able to immediately compare their version to the highest price. Just as 2 possible examples.

To Remove the Price Range from being displayed, but still show the prices of Simple Products and Variable Products with the same price right underneath the title, you can add the following to your child themes function.php

//Remove Price Range
add_filter( 'woocommerce_variable_sale_price_html', 'detect_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'detect_variation_price_format', 10, 2 );
function detect_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
if ($prices[0] !== $prices[1]) {
$price = $prices[0] !== $prices[1] ? sprintf( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
}
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}

It will turn this:

AnnaWerner_Variable-Product-with-Price-Range

Variable Product With Price Range

To this:

AnnaWerner_Variable-Product-without-Price-Range

Variable Product Without Price Range

Additional helpful snippets:

Hide price range only on single product pages

If you still like to show the price range on archives and category pages, you can change the code below main price to:

// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
if ($prices[0] !== $prices[1] && is_product()) {
$price = $prices[0] !== $prices[1] ? sprintf( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
}

Move variant price above variations

You might want to keep the look and feel of all the other products and display the price above the variations. It might be, where your customers look first, as this is where the price usually displays. (Though keep in mind – if you have a long description and/or many variations options it could be too far from the add to cart button.)

If you do want to use it, add this code as well to your functions.php

//Move Variations price above variations to have the same template even if variations prices are the same
remove_action( ‘woocommerce_single_variation’, ‘woocommerce_single_variation’, 10 );
add_action( ‘woocommerce_before_variations_form’, ‘woocommerce_single_variation’, 10 );

Thank you mag for this snippet