WooCommerce is a popular eCommerce platform for WordPress. It is known for its ease of use and flexibility.
One of the features that makes WooCommerce so popular is its variable product type. This product type allows you to offer a product with multiple variations, such as size, color, or material.
One of the challenges with variable products is displaying the lowest price on the product page. By default, WooCommerce will show all variation prices, which can be confusing for customers. In this article, we will show you how to show only the lowest price for WooCommerce variable products.
Method 1: Use the Lowest Price Variable Product Plugin
The easiest way to show only the lowest price for WooCommerce variable products is to use the Lowest Price Variable Product plugin. This plugin automatically hides all variation prices and displays only the lowest price on the product page.
Here’s how to set it up:
1. Install and activate the Lowest Price Variable Product plugin.
That’s it. There are no settings for this plugin. It will automatically start hiding all variation prices and showing only the lowest price on your WooCommerce product pages.
Method 2: Show Only Lowest Price Manually Using Code
If you don’t want to use a plugin, then you can add a few lines of code to your child theme’s functions.php file or in a custom plugin.
Here’s how to do it:
1. Edit your child theme’s functions.php file or create a custom plugin and add this code:
add_filter( 'woocommerce_variable_sale_price_html', 'my_custom_variation_price', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'my_custom_variation_price', 10, 2 ); function my_custom_variation_price( $price, $product ) { // Getproduct ID $product_id = $product->get_id(); // Get variations $args = array( 'post-type' => 'product-variation', 'post__in' => array($product), // get all product variations (even those without stock) 'meta-key' => ' regular _ price ', // get only those with a regular price (otherwise we'll get ALL variations including those without stock) ); $available = array(); // create an array of all available variation IDs (those with stock)
2.Save your changes and upload the file to your server.
Conclusion:
There are two methods that you can use to show only the lowest prices for WooCommerce variable products. The first method is to use the Lowest Price Variable Product plugin. The second method is to add a few lines of code to your child theme’s functions.