Displaying the price range for products within a specific category can be an excellent way to give customers a quick overview of what they can expect to spend. This feature is particularly useful for stores with a wide range of product prices or for sales promotions. In this guide, we’ll show you how to add a price range display for product categories in your WooCommerce store without the need for additional plugins. This method involves adding custom code directly to your theme’s functions.php file.
Before proceeding, consider creating a child theme to protect your customizations. You can easily generate one using our free WordPress child theme generator.
Step 1: Add Price Range to Category Pages
First, we need to add a function that calculates and displays the price range for each category on the category pages. Add this code to your theme’s functions.php file:
/**
* Snippet: How to Display WooCommerce Product Category Price Range – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1458
* Tested with WooCommerce 10.7.0
* "Display price range for each product category"
*/
function wcsuccess_display_category_price_range($category) {
$products = get_posts([
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'tax_query' => [
[
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $category->slug,
],
],
'fields' => 'ids',
]);
$prices = array();
foreach ($products as $product_id) {
$product = wc_get_product($product_id);
$prices[] = $product->get_price();
}
if (!empty($prices)) {
$min_price = min($prices);
$max_price = max($prices);
if ($min_price !== $max_price) {
$price_range = sprintf(__('Price range: %1$s - %2$s', 'woocommerce'), wc_price($min_price), wc_price($max_price));
} else {
$price_range = sprintf(__('Price: %s', 'woocommerce'), wc_price($min_price));
}
echo '<p class="price-range">' . $price_range . '</p>';
}
}
add_action('woocommerce_after_subcategory_title', 'wcsuccess_display_category_price_range', 10);
This function retrieves all the products in a specific category, calculates the minimum and maximum prices, and displays the range (or a single price if all products have the same price).
Step 2: Ensure the Price Range Updates
To ensure the price range reflects the most current data, especially if you frequently change prices or add new products, you might consider clearing relevant transients or caches when products are updated. Add this code snippet to handle these updates:
/**
* Snippet: How to Display WooCommerce Product Category Price Range – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1458
* Tested with WooCommerce 10.7.0
* "Update price range when products are added or updated"
*/
function wcsuccess_update_price_range_on_save($post_id, $post, $update) {
if ($post->post_type !== 'product') {
return;
}
// Assuming you are using caching, you might need to delete transients or similar here.
// This example doesn't implement caching; it's just a placeholder.
// delete_transient('your_transient_name');
}
add_action('save_post', 'wcsuccess_update_price_range_on_save', 10, 3);
This function is a placeholder to remind you to manage caching or transients if you’re using them to store price range data.
Conclusion
By following these steps, you can display a dynamic price range for each product category in your WooCommerce store, enhancing your customers’ shopping experience by providing clear information about pricing at a glance. This custom code approach ensures that you maintain a lightweight and plugin-free store.
Remember, if you’re new to editing your theme files, it’s wise to use a child theme to safeguard your modifications. Our free WordPress child theme generator can help you with this easily.
For additional customisations, consider exploring our other free tools like the wp-config file generator, .htaccess file generator, robots.txt generator, and the bad bot blocker generator.
Implementing this feature not only improves user experience but also helps set clear expectations regarding the price range of products within specific categories, potentially increasing customer satisfaction and sales. Happy coding!
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

