In today’s competitive retail landscape, offering the right price at the right time is crucial for driving sales and maximizing profits. But what if your pricing strategy could adapt automatically, rewarding customers who buy in bulk?
Enter bulk dynamic pricing, a powerful tool that allows you to create tiered discounts based on quantity.
We’re here looking to assign different product prices based on the quantity added to Cart, for example from quantity 1-100 price is $5, from 101-1000 price is $4.90 and from 1001 the price becomes $4.75.
This blog post will be your one-stop guide to setting up bulk dynamic pricing for your WooCommerce store – enjoy!
PHP Snippet: Change Product Price Based on Quantity Added to Cart (Bulk Pricing)
In our example, our product price is €34 and I want to apply a 5% discount above 100 units and a 10% discount above 1000 units. Screenshots for threshold 1 and threshold 2 are below the snippet.
/**
* @snippet Bulk (Dynamic) Pricing - WooCommerce
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
add_action( 'woocommerce_before_calculate_totals', 'bbloomer_quantity_based_pricing', 9999 );
function bbloomer_quantity_based_pricing( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return;
// Define discount rules and thresholds
$threshold1 = 101; // Change price if items > 100
$discount1 = 0.05; // Reduce unit price by 5%
$threshold2 = 1001; // Change price if items > 1000
$discount2 = 0.10; // Reduce unit price by 10%
foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
if ( $cart_item['quantity'] >= $threshold1 && $cart_item['quantity'] < $threshold2 ) {
$price = round( $cart_item['data']->get_price() * ( 1 - $discount1 ), 2 );
$cart_item['data']->set_price( $price );
} elseif ( $cart_item['quantity'] >= $threshold2 ) {
$price = round( $cart_item['data']->get_price() * ( 1 - $discount2 ), 2 );
$cart_item['data']->set_price( $price );
}
}
}
Advanced Plugin: WooCommerce Quantity Discounts, Rules & Swatches
If you’d love to code but don’t feel 100% confident with programming, I decided to look for reliable plugins that achieve the same result (and more).
As usual, I select WooCommerce plugin vendors based on reputation, support quality, code cleanliness, long-term reliability and visibility within the WordPress ecosystem.
With the WooCommerce Quantity Discounts, Rules & Swatches plugin by Studio Wombat, you can enable tiered pricing, as well as quantity swatches, min & max quantities, tooltips and multilingual support – all from the same settings panel.
Great tutorial,
How can I display in the cart and checkout the initial price too before the discount?
Hello Vasilis, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Useful post as usual. But how about bulk pricing in single product page? I mean I whould also change the price, based on selected quantity before add an item to the cart, from the product page, and then eventually change it on cart. Is there a hook for single product page?
Thank you in advance, awesome job.
Hello Giovanni, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Rodolfo,
Thanks for all you help and support with this info.
In the case of being able to apply this code, how would it be so that the discount only applies when another product is added to the cart?
Thank you very much
Hi Francisco, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi, thanks for the great work as always! Is there a way to create a rule that applies a % discount based on categories? I’d like to try to do this with code because using plugins my facebook store never shows the discount price only full price. So I thought maybe there’s a way to solve this with code.
Hi Nicholas, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi everybody,
I have change the code to make it work with a fix price with more quantity but it does work for the other quantity. Any tips will be appreciated.
Thanks you a lot for your help.
Sorry guys I just fixe my code…
Here is the code with 5 + quantity discount.
Cool
Hi there, spectacular resource by the way…
Our client would like each product to have its own bulk discount price ie. they are a promotional company.
To this end we have created custom fields via ACF Pro in order for the thresholds to be applied per product.
Unfortunately we can’t seem to define the variable via the ACF field eg.
What are we missing here?
Kindest, Andy
Hey Andy thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
How can we show the total amount of discounts made to the customer?
Hi Hakan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Not working for me (latest woo-version), price do not change.
Sorry Daniel, works here
This wasn’t working for me either, but after removing the following line, it works perfectly:
FYI- I am skipping the cart, and going straight to checkout using Daniel’s code
Thanks for your feedback!
Hi!
I’m looking for a code to add custom discount (%) based on user role. I’ve added now 3 custom user role.
Can You help me?
Thanks in advance!
Hi Istvan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Rodolfo Melogli,
I would like to have nth product free.
For example 5 products added, 6th added price should be 0.
I works when all product quantities are 1, but if you have same product with quantity = 6, how to make it’s TOTAL price of product_price_of_quantity_1 * 5 ?
Hi Marius, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi,
Thanks for the code! It helps me a lot. With a little search in your tutorials and your other articles I changed the code.
I need a discount for a specific product and a fixed price, not a percentage.
With a little search in your tutorials and your other articles I changed the code.
Best regards,
Mieke
Nice!
Hi!
Could you give me a help for a specific product only?
I would like to add a discount only
Thx
Hi there, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi , I am trying to understand what one line in this code does
You appear to creating a variable $product_id but I cannot see this variable used anywhere else in the code.
Can you explain please.
thank you
You’re right, it’s not needed!
Hi Rodolfo,
Very informative post for the price object. I was wondering why are you subtracting 1 from the $discount variables? Thanks in advance.
Hi Edder, thank you! It was easier for me. To calculate discounted price, I do price*0.95 in case it’s 5% off (0.05 discount). So the formula actually becomes price*(1-0.05)
Ho Rodolfo,
I’ve got my shop set up using WooCommerce Product Table – would your code need changing to work? I’ve adjusted to the below to test and price doesn’t change once threshold reached…
Just need to clarify. It does work if I hit “Update Cart” on the cart page. Just wanting price to change on the fly on the shop page if someone reaches the threshold… Ajax I suppose?. Is this possible?
It should work. I see PHP errors in your custom functions, maybe fixing those might help
It did not work for me. Maybe should I try a different setting for my store or something like that? Thank you!
Weird, it should work if you have set up everything correctly. Can you try with a different theme and no other plugins please?
I am looking for a plugin where the customer selects from a drop down menu 1-100 and based on which amount they choose, the price changes. For example default is 1 in the dropdown list and price $100, but if you select 10 in the dropdown list, the price changes to $1000 – can your plugin or code help?
Hi Jake, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
You can do this without a plugin or integration my friend. Just switch from “Simple Product” to “Variable Product” on the product page and then create your attributes.
Does it work in a multi-currency environment?
Your code is perfect when running in the default currency. (REALLY APPRECIATE!!), but in multi-currency environment, sounds have some problem,
To be exact, I found that the displayed price in Single Product Price has double multiplied the currency rate.
For example: If the product is US$63.95, it should be HK$498 (fix exchange rate between HKD & USD set as 7.8). However, the display price become $63.95 x 7.8 x7.8 = HK$3,890.72…….
Here’s a video capture for your reference: https://jmp.sh/AxbNJ43
P.S. I’m Using Villatheme’s MultiCurrency Plugin. (https://villatheme.com/extensions/woo-multi-currency/)
P.P.S The Above example is: offer 15% discount for order 3 unit or above.
Great Thanks!
Hello Joe, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi,
Thanks for the code it is amazing! 🙂 Is it possibly to apply it for just specific products ?
Hello Jozsef, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Amazing like always!!!
Just a question, what do I need to write if I want to add another level (i.e: +5 = 5%, +10=10% and +20=20%) ?
Thank you for all Rodolpho
Hi Stan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello! Your blog is really great!
Is there a way to apply a percentage discount to all products older than 100 days from today’s date?
Without a plugin…
Hey Fabio, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi
Great … Can the settings ( my price rule) show up on the single product page? So the customer can see if he/she added a few more the price would drop?
I am only targeting 1-2 products that both have variants and quantity is low:
1 = full price (100$)
3 = 10% off / OR 89$ pr. item
5 = 15% off / OR 85$ pr. item
Best regards
Peter
Hello Peter, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
I’m wondering if this could be amended to shipping costs
– For example if a “flat” rate were set to say: $10 per order. Then if more than one item were placed in the cart, the ( $cart_item[‘quantity’] ) would check for more than one – and use the threshold function to apply it to the “flat rate” amount replacing it with: $14 instead.
What do you think?
Hey Wulfgen, I think this solves your problem: https://businessbloomer.com/woocommerce-setup-tiered-shipping-rates-order-amount/
Congratulations ! I think it’s a good post to do this action in an online Woocommerce store without using a plugin. Is it possible to apply different price and different quantity conditions for each product? Thank you
Thanks so much! Yes, it is possible – I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂