Quantcast
Channel: Themelocation
Viewing all articles
Browse latest Browse all 103

How to display minimum price from multiple variations in WooCommerce?

$
0
0

One of my customers had a product that has multiple variations such as sizes, types, colors, etc. And by default in WooCommerce, variable product displays a range of price from lowest to highest.

But my client wanted the system to show the lowest price among variations.

So, how do we go about this?

Here’s a step by step guide on how we did it and how you can get any variable product to display the lowest price.

First, you have to go ahead and create a variable product with attributes and different variations.

 

woocommerce

woocommerce

After that, save the product.

Now on the front end, you’ll see the price range for the variable product you’ve just created.

On shop page:

woocommerce

And the product page:

woocommerce

The next thing you want to do is to display the minimum price among the variations.

So, how do you do that?

To do this, you want to add the following lines of code at the end of your theme’s functions.php file:

add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2); 

function custom_variation_price( $price, $product ) { 

     $price = '';

     $price .= wc_price($product->get_price()); 

     return $price;
}

You can access functions.php file here:

woocommerce

Please, ensure you save the file. And when you’ve done that, head back to the Front-end. You’ll see the lowest price already displayed.

This is how the shop page is going to look like:

woocommerce

And also check out the product page:

woocommerce

So, that’s it. As you can see, we have successfully hidden the variable product price range, which was displaying £10-£20. We now have a variable product that shows only the lowest price-£10.

You can easily customize your WooCommerce variable product to display the lowest price by following the steps outlined above.

I hope you’ve found this post useful? Let me know if you have any question concerning this tutorial.


Viewing all articles
Browse latest Browse all 103

Trending Articles