Key Takeaways
- Dynamic pricing in WooCommerce can be either about changing how a price is displayed to a customer or about adjusting the actual price based on their actions.
- You don’t need to be a developer to implement custom pricing rules; you can use code for unique display needs or rely on powerful plugins for automated discounts.
- The core goal of dynamic pricing is to create a more flexible and transparent store that encourages sales and improves profitability.
Most WooCommerce stores start with static pricing — you set a fixed price for a product, and it stays that way until you change it. That works fine for many cases, but it can also be limiting. Not all products fit neatly into a single number.
For example, items sold by weight, like beans, make more sense when priced per unit rather than a flat cost. Similarly, offering the same price whether someone buys one item or ten doesn’t always reflect real-world buying behavior.
That’s where dynamic pricing becomes valuable.
Instead of sticking to a one-size-fits-all price, WooCommerce can automatically adjust what customers see based on rules you define. Discounts can kick in when shoppers add more items to their cart, or you can show prices per unit to give better clarity. The idea is to make pricing flexible, fair, and more aligned with how customers actually shop.
In this guide, we’ll explore two practical methods to bring dynamic pricing into your WooCommerce store — whether you prefer a lightweight custom solution or the convenience of a plugin.
What is WooCommerce Dynamic Pricing?
WooCommerce dynamic pricing is a strategy where product prices or discounts automatically adjust based on rules you set. Instead of manually changing numbers in the product editor, you can let your store respond to real conditions like:
- How many items a customer adds to their cart.
- Whether the buyer is a wholesale customer or a retail customer.
- Seasonal promotions or limited-time campaigns.
Think of it as pricing that moves with demand and customer behavior. Sometimes it’s called “surge pricing” or “demand pricing,” depending on whether you’re raising prices during peak demand or lowering them to push sales.
Benefits of Offering Dynamic Pricing in WooCommerce
Why bother with dynamic pricing in the first place? Here are a few real advantages store owners see:
- Boost sales during promotions → Drop prices for a limited time and customers will often buy more.
- Maximize profits in high demand → Increase prices slightly when demand is up and earn more per order.
- Clear out slow-moving stock → Discounts on old inventory help free up shelf space without heavy manual effort.
- Encourage bulk purchases → Volume-based discounts (like we set up in Method 2) reward customers for buying more at once.
- Stay competitive → If other stores keep static pricing, you can stand out by making yours flexible and customer-friendly.
How to Add Custom Dynamic Pricing Display in WooCommerce (2 Methods)
So how do you actually set up dynamic pricing in WooCommerce? There are a few different ways to approach it depending on your comfort level with code.
In this blog, we’ll look at two practical methods you can start using right away:
- Method 1: Build a custom plugin to control how prices are displayed with custom fields.
- Method 2: Use a free WooCommerce plugin to apply dynamic pricing rules, like discounts that change based on what’s in the cart.
Both will give you more flexibility than WooCommerce’s default pricing system, and by the end you’ll know which option fits your store best.
Method 1: Build a Custom Plugin
This method is best if you want a proper long-term solution. A plugin keeps your changes separate from your theme, so they won’t break when you update WordPress or WooCommerce.
In this section, we’ll create a simple plugin, drop in the pricing code, and activate it.
Prerequisites
Before we dive in, make sure you have:
- A working WordPress site with WooCommerce installed.
- Access to your site’s files (via FTP, cPanel, or your hosting file manager).
- A code editor (VS Code, Sublime, or even Notepad++).
- Basic familiarity with where plugins live in WordPress (don’t worry, we’ll walk through it together).
If you can install a plugin, you can do this.
Step 1: Create Your Plugin Folder
First, let’s make a home for our code.
- Go to your WordPress install directory.
- Navigate to:
wp-content/plugins/

- Inside that folder, create a new folder called:
custom-dynamic-pricing

This is where our plugin will live. Think of it as a box we’ll drop our custom code into.
Step 2: Create the Plugin File
Inside that folder, create a file named:
custom-dynamic-pricing.php

Now open that file in your editor and paste this in:
<?php
/**
* Plugin Name: Custom Dynamic Pricing Display
* Description: A lightweight plugin to customize WooCommerce price display with unit pricing or custom fields.
* Author: Your Name
* Version: 1.0
* License: GPL2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

This doesn’t do anything yet — it’s just the header that tells WordPress “hey, this is a plugin.”
Step 3: Write the Price Display Logic
Now comes the fun part: telling WooCommerce how to display our custom pricing.
We’re going to use something called a filter. Filters are little hooks that let you change what WooCommerce shows before it prints it out.
Here’s the code we’ll add under the header:
// Change price display on product & shop pages
add_filter( 'woocommerce_get_price_html', 'cdp_change_product_html', 10, 2 );
function cdp_change_product_html( $price_html, $product ) {
// Check if the product has a custom unit_price field
$unit_price = get_post_meta( $product->get_id(), 'unit_price', true );
if ( ! empty( $unit_price ) ) {
$price_html = '<span class="amount">' . wc_price( $unit_price ) . ' per kg</span>';
}
return $price_html;
}
// Change price display inside the cart
add_filter( 'woocommerce_cart_item_price', 'cdp_change_product_price_cart', 10, 3 );
function cdp_change_product_price_cart( $price, $cart_item, $cart_item_key ) {
$unit_price = get_post_meta( $cart_item['product_id'], 'unit_price', true );
if ( ! empty( $unit_price ) ) {
$price = wc_price( $unit_price ) . ' per kg';
}
return $price;
}

Let’s break this down:
- woocommerce_get_price_html → controls how prices are shown on the shop page and single product pages.
- woocommerce_cart_item_price → controls how prices are shown inside the cart.
- get_post_meta → grabs a custom field from the product (we’ll add this in a second).
- wc_price() → makes sure the price is displayed in the correct WooCommerce format (currency, decimals, etc.).
So if your product has a custom field called unit_price, WooCommerce will now show:
$X per kg
Instead of just $X.
Step 4: Activate Your Plugin
- Head to your WordPress dashboard → Plugins.
- You’ll see Custom Dynamic Pricing Display in the list.

- Click Activate.
Your plugin is now live.
Step 5: Add a Custom Field to a Product
Right now, our code is looking for a field called unit_price. Let’s add it.
- Go to Products → All Products in your WordPress dashboard.

- Edit a product.

- Scroll down to the Product Data section.

- Make sure Custom Fields is enabled (if you don’t see it, click Screen Options in the top-right and check the box).

- Now, scroll down in your product editor until you see the Custom Fields box.

- In the section that says “Add Custom Field”, click the dropdown.

- If unit_price is not already in the list, choose “Enter new” (button right below the dropdown).

- In the Name field (the text box that appears after you click “Enter new”), type:
unit_price
- In the Value field (the box right next to it),, for example:
15

- Don’t add $ or currency symbols here — WooCommerce will handle formatting with wc_price().
- Click the Add Custom Field button.
- Finally, scroll up and Update or Publish the product.

Step 6: Test It Out
- Go to your Shop page → The product should now say $15 per kg.

- Open the Single Product page → Same thing.

- Add it to your Cart → The cart price display should also say $15 per kg.

So, what exactly did we do with our plugin?
We created a rule that makes our price display dynamic. Instead of a fixed price for every product, our code now checks for a custom field called unit_price. If it finds that field, it dynamically changes the price display to include “per kg.
If the field isn’t there, the price just displays normally. This gives you the flexibility to apply this special pricing display only where it’s needed.
This dynamic pricing display is perfect for any store selling products by weight, volume, or measure. Think about businesses that sell:
- Spices or Coffee Beans
- Loose-leaf Tea
- Fabrics or Yarn
- Bulk Foods
For these products, customers aren’t just looking at the total price—they’re trying to figure out the value. By dynamically showing the price as “$X per kg,” you’re giving them exactly the information they need to compare products and make a confident purchase.
It adds a layer of transparency that builds trust and makes the shopping experience feel much more intuitive.
Expanding Method 1: Add a Custom Pricing Field to All Products
So far, we manually added a unit_price field to a single product. That works for testing, but it’s not practical for a whole store.
A better approach is to add a dedicated “Unit Price” field inside the WooCommerce Product Data panel, so it shows up on every product by default. This way, you don’t need to mess with Custom Fields manually.
Here’s how to set it up:
Step 1: Update the Plugin
Replace the old plugin code with the new version.
Right now, your plugin only displays a unit_price if you manually add that custom field to a product (like we did earlier).
We’ll now upgrade this plugin so that:
Every product automatically has a Unit Price field inside the Product Data → General tab.
Store managers can simply type the value when editing a product.
That value will automatically show up on the shop page, single product page, and cart.
Step 2: Replace Your Current Code With This
<?php
/**
* Plugin Name: Custom Dynamic Pricing Display
* Description: A lightweight plugin to customize WooCommerce price display with unit pricing or custom fields.
* Author: Abdul Rehman
* Version: 1.1
* License: GPL2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
// ------------------------------
// 1. Add custom Unit Price field in Product Data (backend)
// ------------------------------
add_action( 'woocommerce_product_options_pricing', 'cdp_add_unit_price_field' );
function cdp_add_unit_price_field() {
woocommerce_wp_text_input( array(
'id' => 'unit_price',
'label' => __( 'Unit Price', 'cdp' ),
'placeholder' => 'Enter unit price',
'desc_tip' => true,
'description' => __( 'Set a custom unit price (e.g., per kg, per box).', 'cdp' ),
'type' => 'number',
'custom_attributes' => array(
'step' => '0.01',
'min' => '0'
),
) );
}
// ------------------------------
// 2. Save the Unit Price field
// ------------------------------
add_action( 'woocommerce_process_product_meta', 'cdp_save_unit_price_field' );
function cdp_save_unit_price_field( $post_id ) {
$unit_price = isset( $_POST['unit_price'] ) ? sanitize_text_field( $_POST['unit_price'] ) : '';
update_post_meta( $post_id, 'unit_price', $unit_price );
}
// ------------------------------
// 3. Change price display on product & shop pages
// ------------------------------
add_filter( 'woocommerce_get_price_html', 'cdp_change_product_html', 10, 2 );
function cdp_change_product_html( $price_html, $product ) {
$unit_price = get_post_meta( $product->get_id(), 'unit_price', true );
if ( ! empty( $unit_price ) ) {
$price_html = '<span class="amount">' . wc_price( $unit_price ) . ' per kg</span>';
}
return $price_html;
}
// ------------------------------
// 4. Change price display inside the cart
// ------------------------------
add_filter( 'woocommerce_cart_item_price', 'cdp_change_product_price_cart', 10, 3 );
function cdp_change_product_price_cart( $price, $cart_item, $cart_item_key ) {
$unit_price = get_post_meta( $cart_item['product_id'], 'unit_price', true );
if ( ! empty( $unit_price ) ) {
$price = wc_price( $unit_price ) . ' per kg';
}
return $price;
}
What Changed From Your Old Code?
- Meta box function added → We introduced woocommerce_product_options_pricing to register a Unit Price input field inside the product editor.
- Save function added → We hooked into woocommerce_process_product_meta so the Unit Price gets saved when you update a product.
- Existing display logic kept → The woocommerce_get_price_html and woocommerce_cart_item_price filters from your old code remain the same, but now they pull from the new Unit Price field instead of a manually added custom field.
Save the file and make sure the plugin is still Activated inside WordPress → Plugins.
Step 3: Add a Unit Price to a Product (Backend)
- Go to Products → All Products in your WordPress dashboard.
- Edit any product.
- In the Product Data, you’ll now see a new field labeled Unit Price.

- Enter your value (e.g., 20).
- Don’t type $ or any symbols — WooCommerce will format it.
- Update/Publish the product.
Step 4: Check the Frontend (Shop / Product Page)
- Go to your Shop page → you’ll see the product now displays the custom price (e.g., $15 per kg).

- Open the Single Product page → the same display will show there.

Step 5: Check the Cart (Frontend)
- Add that product to your cart.
- Go to the Cart page → the price shown in the cart will also use the custom display (e.g., $20 per kg).

Method 2: Add Dynamic Pricing Rules with a Free WooCommerce Plugin
In Method 1, we built a small custom plugin that pulled a custom field (unit_price) from a product and displayed it in the store. That approach is great if you want full control and don’t mind writing some PHP.
But what if coding isn’t your thing, or you just want something ready to go?
That’s where this method comes in. Instead of creating a plugin yourself, we’ll use a free WordPress plugin to add real-time price adjustments like bulk discounts or promotions.
Here’s how:
Step 1: Install the Plugin
- Head over to your WordPress dashboard and navigate to Plugins → Add New.
- In the search bar, type “Dynamic Pricing With Discount Rules for WooCommerce” (by Acowebs).

- Once it pops up, click Install Now, then hit Activate.

Step 2: Open the Pricing Rules Panel
- After activation, you’ll notice a new Pricing Rules menu in your WordPress admin sidebar.

- Click Add New Rule — this is where you’ll set up your first pricing logic.

Step 3: Configure Your Discount Rule
- Give your rule a clear name (something like “Volume Discount” works well).

- Now choose your Discount Type: percentage or fixed price.

- Next, decide which Products or Categories the rule applies to — this tells WooCommerce where your dynamic rule should kick in. I’ll choose All Products. So think of it like a store wide sale.

- Finally, choose the discount value. I’ll choose “2”. This will take off €2 from the total price.

With this plugin approach, we’ve taken what we built in Method 1 a step further. Now the price itself changes dynamically — in our case, automatically taking €2 off once the condition we set was met.
This is what makes it “dynamic pricing”: the store automatically adjusts the price in real time based on rules you define, without you needing to edit each product manually.
Step 4: Save and Test
Click the Publish button and head to your storefront. Add items to the cart to confirm your rule is working as expected.

As you can see, as per our rule, €2 has been deducted from €14, bringing the total to €12.
Expanding Method 2: Add Smarter Dynamic Rules
In our first pass, we applied a flat discount store-wide. That worked, but it wasn’t very “dynamic.” Let’s make things more interesting by changing prices based on how many items a customer adds to their cart.
Here’s how we can do this:
Step 1: Create a New Rule
- Go to Pricing Rules → Add New Rule.
- Let’s call our rule: Buy More, Save More
- Select discount type as: Quantity Based Discount

Step 2: Choose the Product Filter
- For Product Filter, leave this to default which’ll apply the rule to all products.

Step 3: Configure the Quantity Discount
- In the Quantity Based Discount section:
- Choose the type you want. I’ll choose: Discount on cart quantity

- Next choose discount type, Percentage or Fixed.
- Finally, add the discount percentage. I’ll type 50%.
Step 4: Save and Test
- Hit Publish to save your rule.
- Go to your storefront, add 3 or more products to the cart, and watch the total update automatically.

As you can see, when we added 3 products to the cart, a 5% discount was applied dynamically.
Wrapping Up!
So, this wraps up our blog on how to add custom dynamic pricing display in WooCommerce.
In this blog, we explored two methods for implementing dynamic pricing:
Method 1: We built a custom plugin that dynamically changes how the price is displayed based on a custom value you enter. This is perfect for stores that sell products by weight and want to provide clear, transparent unit pricing.
Method 2: We then explored a more traditional approach to dynamic pricing by using a free plugin. This method is truly dynamic because the price your customer sees changes in real time based on their actions, helping you encourage bulk purchases.
Of course, there are many more ways to add custom dynamic pricing to your store. But this blog gives you a basic idea of what custom dynamic prices are in WooCommerce and how you can implement them in your store.
If you have any questions, let me know in the comments.
Frequently Asked Questions
1. What’s the difference between changing the price display and changing the actual price in WooCommerce?
Changing the price display (like we did with the custom plugin) only affects how prices appear to customers — it doesn’t change WooCommerce’s stored product price. Dynamic pricing rules (via plugins) actually recalculate the price at checkout.
2. Do I need coding knowledge to add dynamic pricing to WooCommerce?
No. If you’re comfortable with code, you can create a lightweight custom plugin to control display logic. If not, free plugins like “Dynamic Pricing With Discount Rules” let you set rules visually, no coding required.
3. Can I combine custom code and plugins for dynamic pricing?
Yes, but carefully. You could use custom code for specific display needs (like unit pricing per kg) and a plugin for discounts or promotions. Just make sure the rules don’t conflict, and always test on a staging site first.
Owais Khan
Owais works as a Marketing Manager at Cloudways (managed hosting platform) where he focuses on growth, demand generation, and strategic partnerships. With more than a decade of experience in digital marketing and B2B, Owais prefers to build systems that help teams achieve their full potential.