Show only Lowest or Highest prices for variable products | WooCommerce

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.

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

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

show-only-lowest-price-woocommerce-variable-products

Show Only Lowest Price

Variable product price range normally looks like $10 – $20. With this snippet,

[alert-success]With this snippet, you will be able to hide the highest price, plus add a “From: ” in front of the minimum price.[/alert-success].
All you need is pasting the following code in your child theme’s functions.php

/**
 * @snippet       Show only lowest prices in WooCommerce variable products
 * @how-to        Watch tutorial @ https://wpglorify.com/?p=2082
 * @author        Garry Singh
 * @tested        WooCommerce 3.0.8
 */
 
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;
}

 

Highest prices for 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;
}
[alert-warning]If you want to hide the price completely for variable products until the customer selects variation of the product.[/alert-warning]

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).

/**
 * @snippet       Show only lowest prices in WooCommerce variable products
 * @how-to        Watch tutorial @ https://wpglorify.com/?p=2082
 * @author        Garry Singh
 * @tested        WooCommerce 3.0.8
 */

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

Where to add this code?

You can place PHP snippets at the bottom of your functions.php file, We recommend to use child them so you will not lose any changes when updating your theme

Did this snippet work?

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.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
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?

LC

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

Sergey

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

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?

Close
Close