E-Commerce WordPress Solutions

Change Product Price based on Popularity in WooCommerce

Pricing popular items dynamically can nudge buyers and protect your margins at once. Here is how to change product price based on popularity in WooCommerce, so your store reacts to demand on its own.

Praveen Chauhan Praveen Chauhan 3 min read

Price Settings WooCommercePlugins are usually created for regular use cases. Which makes sense. Even an advanced plugin like WooCommerce, with so many of it’s features, cannot satisfy every use case. This is where a custom extension or add-on comes in to use. Consider a use case where you want to dynamically set the price of the product, based on the popularity of a product. This post is not about the Dynamic Pricing extension, but I will be mentioning it.

 

Let’s continue. I’ll explain my use case in detail. Say, I want to set the price of the product, based on the number of units sold. Thus price of the product is not based on the number of units being purchased, it depends on how many units have been purchased.

 

Are there any existing WooCommerce extensions that allow for variable pricing?

The Dynamic Pricing extension for WooCommerce, allows you to set a different price, or offer a discount, based on the number of product units purchased. A feature to be mentioned here is that, it allows you to set the price based on user roles. So if you want special pricing only for a special group of people, you can use this extension and customize it. But this extension by itself is not what we want.

[space]

Creating your own Custom Extension

The WooCommerce plugin provides several hooks for easy customization. So, when you do not find what you are looking for, you can easily create a custom extension or an add-on for the WooCommerce plugin. Our extension will set a different price for the product based on the number of items sold. For example, say the base price is $20. Once 100 items are sold, the price will be $25.

WooCommerce tracks the sales per product in the custom meta field, total_sales. Using the value for this field, we will know the total number of items sold, per product. This value, can be used to set the price using woocommerce_get_price filter. What we can do is create a simple WordPress plugin, and add the following code.

[pre]add_filter(‘woocommerce_get_price’, get_custom_product_price, $val, 2);

function get_custom_product_price($val) {
global $product;

// get the total number of items sold
$units_sold = get_post_meta( $product->id, ‘total_sales’, true );

if($units_sold >= 100)
{
return ‘25’;
}
else
{
// return original price 20
return $product->price;
}
}[/pre]
[space]

Okay, agreed that not every customization is simple. You could even extend this functionality to set prices based on product ratings. And to provide better usability for such a plugin, you will have to create an admin UI which allows users to set price ranges, rules, etc.

 

Get a FREE Consultation

Let's build something that lasts.

Share what's on your mind — a clear brief, a half-formed idea, or just a sense that something needs to change. We'll listen first, ask the right questions, and point you toward what's actually worth building.

We take on a handful of projects each quarter,ones where we can truly make a difference.

  • Receive a human response within 24 hours
  • Get a detailed scope and quote upfront
  • We're happy to sign an NDA upon request

    Free 30-Min Strategy Call

    Your Name *

    Your Phone No *

    Work Email *

    Your Budget*

    Project Details *