How to Implement WooCommerce Quantity-based Pricing Without a Plugin

In e-commerce stores, some sellers tend to offer discounts based on item quantities. For an instance, if someone adds item quantities between 1-100, then the price per item will be $5. Further, if one adds item quantities from 100-1000, then the price per item will be $4.90 for him. In the end, if you add more than 1001 units to the cart, then the price per item will become $4.75. This is how WooCommerce Quantity based pricing works! 

Furthermore, there are various dynamic pricing plugins. These plugins facilitate complex pricing & dynamic discounts. However, in this article, we will learn simple code to enable item pricing based on quantity for customers. 

Here is an Image preview of how this function will show up after implication. 

Image showing WooCommerce Quantity based pricing for particular item

PHP Snippet: Alter Item Pricing based on Quantity Added to Cart

In this example, let’s assume the original item price to be € 34. You want to apply a 5% discount above 100 units & 10% discount over 1000 units. 

Let’s see how coding will be implemented for above queries. This in turn will enable WooCommerce Quantity based pricing.

add_action( 'woocommerce_before_calculate_totals', 'phpsof_quantity_based_pricing', 9999 );
function phpsof_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.1; // 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 );

Here are screenshots showing how discounted item pricing will appear.

Image showing WooCommerce discounted item price

Image showing WooCommerce discounted bulk item pricing

Where do you add this snippet?

So, enable this WooCommerce Quantity based pricing without a plugin. You can add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. 

Is this snippet still valid?  

So, this is how you can display WooCommerce Quantity based pricing. It will showcase item price discounts for bulk quantities added to the cartI have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected. Share it further if this snippet has saved your time.

Also Read, A Complete Tutorial for WooCommerce Show SKU @ Cart page

WooCommerce Min Purchase Amount for Specific Product

Important links: WooCommerce –

Storefront theme –