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 ) );
$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 ;
}

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

Written by anna

Leave a Reply