How to Display WooCommerce Product Category Price Range – 2026

Last updated on September 6th, 2024 at 05:41 pm

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

See also  How to Programmatically Add Product to Cart in WooCommerce on Visit - 2026

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.

See also  How to easily align your WooCommerce shop page products

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!

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×