Show only Lowest or Highest prices for variable products

If you are using woocommerce as an e-commerce platform you probably get annoyed the way variable products show the price in woocommerce.

Yes, It’s just standard way to show variable prices on any e-commerce platform out there, but that doesn’t mean it is the best way to do it in every scenario.

It is your personal choice as a store owner or maybe some kind of magic trick to boost the conversion rate.

  1. Show the lowest price
  2. Show the highest price
  3. Hide price until variations are selected

Okay… I don’t want to waste your precious time so, Let’s jump to the solution.

SHOW ONLY LOWEST OR HIGHEST PRICES FOR VARIABLE PRODUCTS

Show Only the Lowest Price

Variable product price range normally looks like $10 – $20. With the help of below snippet, you will be able to hide the highest price, plus add a “From: ” in front of the minimum price.

All you need is pasting the following code in your child theme’s functions.php

// Show only lowest prices in WooCommerce variable products

add_filter( 'woocommerce_variable_sale_price_html', 'wpglorify_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wpglorify_variation_price_format', 10, 2 );
 
function wpglorify_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( __( 'From: %1$s', '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( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
 
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
}
return $price;
}

Show only the Highest prices on variable products

If for some reason you want to show the maximum price instead of minimum price use the following snippet.

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

If you want to hide the price completely for variable products until the customer selects a variation of the product.

Guess what!

We got the solution for that as well.

Hide Price until user select variations of a product

Instead of the above code, use the code snippet below ( make sure don’t use both snippets together to avoid any conflict).

add_filter( 'woocommerce_variable_sale_price_html', 'wpglorify_remove_variation_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wpglorify_remove_variation_price', 10, 2 );
 
function wpglorify_remove_variation_price( $price ) {
$price = '';
return $price;
}

HOW TO ADD PHP CODE

The Code Snippets plugin makes it very easy to not just add PHP snippets to your website but also manage all the snippets you add.

You can activate and deactivate certain snippets, and even adds notes about what they do. It even has better error handling to avoid the PHP error scenarios.

To install it, simply go to Plugins > Add New and search for Code Snippets.

The traditional or normal way to add PHP snippets to your theme is to add directly in your theme’s functions.php file.

However, make sure you are using a child theme otherwise you will lose all changes once you update your theme.


Please let us know in the comments if the snippet worked as expected. We would be happy to revise the code if you report otherwise or in case you need more assistance.

13
Leave a Reply

  Subscribe  
Notify of
pvd

Same question as a few other people here have: How can I show the ‘From ‘ variation price on the overview pages and Hide the variation price on the detail page (until variation selected). So actually a combination of the 2 codes that you show in this post.

Would be really awesome if you could help me with this!

Thanks a lot 🙂

Xander

Any way to show both the max and min price at the same time? We have a download product that is available cheaper to download and more if posted. I tried to edit the code but its outside my ability.

Thanks

Sarah

Worked out perfectly! Youre my hero. Thankyouuuu

Defne

I didn’t need the “from: “, so i removed it from string, now it only shows price. It works perfectly. Thank you very much!

G

This worked beautifully! One question, when using the “From” code, can I have it change that portion to the updated price once selections have been made? Right now it says “From $100.00” and once options are selected, the final price shows below, showing two prices. I’d like to eliminate the second instance and only have the top price change. Is this possible?

Sergey

If i need show lowest price on main shop page, and hide price on product page?

LC

What do I need to change to have it show the maximum price instead of the minimum price? THanks!

Bondi

nice this is what i was looking for. Is there the possibility to have this in the wordpress plugin repository, to have it always up to date?