display the lowest price
-
How can I make it so that the shop page only shows the lowest price of the products and not the lowest and highest price?
The page I need help with: [log in to see the link]
-
How can I make it so that the shop page only shows the lowest price of the products and not the lowest and highest price?
From what I understand, you’re looking to modify the display on your shop page so it only shows the lowest price for variable products, instead of the range from lowest to highest.
In WooCommerce, the default setting for variable products is to show a price range. However, you can modify this with a bit of custom code.
Here’s a simple solution: You can add the following code snippet to your theme’s functions.php file:
add_filter('woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2); add_filter('woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2); function wc_wc20_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 = '' . $saleprice . ' ' . $price . ''; } return $price; }
This code will modify the display of your product prices to show only the lowest price with a “From:” prefix.
Here’s an image for your reference:
Image Link: https://snipboard.io/eXniIh.jpg
You should add this code to your child theme’s
functions.php
file or via a plugin that allows custom functions to be added, like the Code Snippets plugin. Please note that it’s not advisable to add custom code directly to your parent theme’sfunctions.php
file. Doing so could lead to the code being erased when the theme is updated.Alternatively, you can use the ‘WooCommerce – Show only lowest prices in variable products‘ plugin. This plugin is designed to achieve exactly what you’re looking for and can be an easier option if you’re not comfortable editing code.
?? Just a quick reminder: Before you make any changes, we strongly recommend that you create a backup of your full site and database. This is a crucial step to ensure that in case anything goes wrong, you can easily restore your site to its previous, functioning state.
I hope this helps! If you have any other questions or need further assistance, please don’t hesitate to ask.
perfect thanks I’ll try immediately
perfect thanks I’ll try immediately
You’re welcome! I’m glad to hear that the solution provided seems to be a good fit for your needs.
Remember, if you’re not comfortable with editing code, the ‘WooCommerce – Show only lowest prices in variable products‘ plugin could be a simpler solution. And always, always backup your site before making any changes.
If you encounter any issues or have any further questions, don’t hesitate to reach out. I’m here to help!
Best of luck with your updates, and I look forward to hearing how it goes!
I have solved my problem, thank you very much!
I copied your code and pasted it into the snippets plugin and it works!
It doesn’t show me the lowest price (for 12 pieces for example the price is 32 euros each) but it shows me the price for the single piece that is the lowest compared to the total of the others (which increases with quantity), but I’d say that’s OK too.Thanks again ??
I’m thrilled to hear that you’ve successfully resolved your issue! It’s great to know that the code snippet worked well for you when added via the Snippets plugin.
As for the price display, the code is designed to show the lowest price for a single piece, as you’ve noticed. If you ever want to change this to display the lowest price for a specific quantity (like 12 pieces), that would require additional custom code. But as long as you’re happy with the current setup, that’s what matters most!
I really appreciate your kind words and the time you took to update me on your progress. I’ll go ahead and mark this thread as resolved. However, if you ever have more questions or issues in the future, don’t hesitate to kick off a new topic.
We’d be thrilled if you could spare a few minutes to leave us a review at ?? https://www.ads-software.com/support/plugin/woocommerce/reviews.
Cheers!
- The topic ‘display the lowest price’ is closed to new replies.