Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Apply Bulk Quantity Discount (Buy 10 Get 1 Free) in WooCommerce?

In an online store, having just great products isn’t enough—it demands smart sales strategies to stand out. With a “Buy 10 Get 1 Free” promotion in WooCommerce, you can simply boost your store’s average order value. For instance, when customers buy 10 boxes of coffee pods, they get 1 box for free. This helps you clear stocks quickly and customers also feel that their purchase is valuable as they get a bonus when purchased in bulk.

Solution: Apply Bulk Quantity Discount (Buy 10 Get 1 Free) in WooCommerce

This guide focuses on the implementation of a BOGO-like discount, where customers receive a 100% discount after purchasing a specified quantity that applies well for both simple and variable products.

add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount_11th_at_100', 10, 1 );

function ts_add_custom_discount_11th_at_100( $wc_cart ){
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;

    $discount = 0;
    $items_prices = array();

    // Set HERE your targeted product ID
    $targeted_product_id = 396;

    foreach ( $wc_cart->get_cart() as $key => $cart_item ) {
        $product_id = $cart_item['product_id'];
        $qty = intval( $cart_item['quantity'] );

        // Use the correct method to get the product object
        $product = $cart_item['data'];

        // Get the product price, considering variable products
        $price = $product->is_type('variable') ? $product->get_price() : $product->get_price($qty);

        for ( $i = 0; $i < $qty; $i++ ) {
            $items_prices[] = floatval( $price );
        }
    }

    $count_items_prices = count($items_prices);

    if( $count_items_prices > 10 ) {
        foreach( $items_prices as $key => $price ) {
            if( $key % 11 == 1 ) {
                $discount -= number_format($price / 1, 11 );
            }
        }
    }

    if( $discount != 0 ){
        // Displaying a custom notice (optional)
        wc_clear_notices();
        wc_add_notice( __("Buy 10 Get 1 Free"), 'notice');

        // The discount
        $wc_cart->add_fee( 'Buy 10 Get 1 Free', $discount, true  );
        # Note: Last argument in add_fee() method is related to applying the tax or not to the discount (true or false)
    }
}
flexi bogo cta banner image


This to the shop owners who are running or planning to run BOGO offers on their WooCommerce store…

BOGO deals are great for increasing your sales, but have you thought about which offers are bringing you more revenue and which offers are not performing that great?

Don’t just set a BOGO deal, track the revenue generated by your deals in real-time with the Flexi BOGO for WooCommerce plugin.

Output

When the customer adds the targeted product ID set in the code to the cart and continues to add the same product (ID 396) to the cart, reaching a total quantity of 10. Upon adding the 11th product, the code implies offering a 100% discount to that 11th product.

How to Apply Bulk Quantity Discount (Buy 10 Get 1 Free) in WooCommerce? - Tyche Softwares

Also, you can explore an easy way to provide WooCommerce bulk quantity-tiered discounts based on the based on the total quantity of the items present in the cart.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x