Setup WooCommerce Buy One Get One Discount

How to Set Up a WooCommerce BOGO (Buy One Get One) Discount

WooCommerce doesn’t include native BOGO logic, so setting up a buy one get one discount means either adding custom code to your theme’s functions.php file or using a plugin that handles the rule engine for you. 

This guide covers both paths: a free, no-plugin method using code snippets, and plugin-based methods using Smart Coupons for WooCommerce and Discount Rules for WooCommerce, plus how Disco handles BOGO rules if you want a dedicated dynamic pricing tool.

Here are the three ways to create a WooCommerce buy one get one discount:

  • Custom code in your theme’s functions.php file: free, but requires editing PHP and carries more risk if done incorrectly.
  • A coupon plugin: good for simple, coupon-triggered BOGO offers.
  • A premium discount rules plugin: best for automatic, condition-based BOGO deals without coupon codes.

How to Create a WooCommerce BOGO Discount Without a Plugin (Custom Code)

Only use this method if you’re comfortable editing PHP. Use a child theme or back up your site files first, since a code error in functions.php can break your storefront.

The code below covers four common BOGO scenarios: giving an extra unit of the same product for free, targeting one specific product, requiring a minimum quantity before the free item unlocks, and giving away a different product entirely.

Buy Any Product, Get an Extra Quantity of the Same Product Free

Step 1: Access the theme file.

Go to Appearance > Theme File Editor. Click functions.php and scroll to the bottom to add your code.

Step 2: Add the free-quantity function.

This function loops through the cart and for every quantity of a product added, adds an equal quantity of the same product marked as free:

function add_bogo_free_product() {
$cart = WC()->cart->get_cart();
foreach ($cart as $cart_item_key => $cart_item) {
    $product_id = $cart_item['product_id'];
    $quantity = $cart_item['quantity'];
    if (!isset($cart_item['custom_price']) && $quantity > 0) {
        $free_product_exists = false;
        foreach ($cart as $free_cart_item_key => $free_cart_item) {
            if ($free_cart_item['product_id'] == $product_id && isset($free_cart_item['custom_price'])) {
                $free_product_exists = true;
                break;
            }
        }
        if (!$free_product_exists) {
            WC()->cart->add_to_cart($product_id, $quantity, 0, array(), array('custom_price' => 0));
        }
    }
}
}
add_action('woocommerce_before_calculate_totals', 'add_bogo_free_product');

Then add a second function to force the free item’s price to zero:

function apply_bogo_custom_price($cart_object) {
foreach ($cart_object->get_cart() as $cart_item) {
    if (isset($cart_item['custom_price'])) {
        $cart_item['data']->set_price($cart_item['custom_price']);
    }
}
}
add_action('woocommerce_before_calculate_totals', 'apply_bogo_custom_price');

Step 3: Save and test.

Save functions.php, add any product to your cart, and check the cart page. WooCommerce should automatically add a second, free unit of the same product.

Buy a Specific Product, Get an Extra Quantity of That Product Free

Remove the previous snippet first. This version targets one product ID instead of applying to everything in the cart:

function add_free_product_with_targeted_product() {
$targeted_product_id = 123; // Replace with your product ID
$cart = WC()->cart->get_cart();
$targeted_product_count = 0;
$free_product_exists = false;
foreach ($cart as $cart_item) {
    if ($cart_item['product_id'] == $targeted_product_id) {
        if (!isset($cart_item['custom_price'])) {
            $targeted_product_count += $cart_item['quantity'];
        } else {
            $free_product_exists = true;
        }
    }
}
if ($targeted_product_count > 0 && !$free_product_exists) {
    WC()->cart->add_to_cart($targeted_product_id, $targeted_product_count, 0, array(), array('custom_price' => 0));
}
}
add_action('woocommerce_before_calculate_totals', 'add_free_product_with_targeted_product');

Find your product ID from Products > All Products by hovering over the product link, then replace $targeted_product_id = 123; with your actual ID. Use the same custom-price function from the previous section to zero out the free item’s price.

Buy X Quantity of a Product, Get One Free

This version requires a minimum quantity (2, in this example) before the free unit unlocks:

function add_free_product_for_buy_two_get_one($cart) {
$targeted_product_id = 123; // Replace with your product ID
$targeted_product_count = 0;
$free_product_count = 0;
foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
    if ($cart_item['product_id'] == $targeted_product_id) {
        if (isset($cart_item['custom_price'])) {
            $free_product_count += $cart_item['quantity'];
        } else {
            $targeted_product_count += $cart_item['quantity'];
        }
    }
}
$required_free_quantity = floor($targeted_product_count / 2);
if ($required_free_quantity > $free_product_count) {
    $additional_free_quantity = $required_free_quantity - $free_product_count;
    WC()->cart->add_to_cart($targeted_product_id, $additional_free_quantity, 0, array(), array('custom_price' => 0));
}
}
add_action('woocommerce_before_calculate_totals', 'add_free_product_for_buy_two_get_one');

Add the matching custom-price function (identical structure to the ones above) and hook it to woocommerce_before_calculate_totals. With this rule, adding one unit of the product won’t trigger the discount. Adding a second unit will.

Buy X Product, Get Y Product Free (WooCommerce Buy X Get Y)

This scenario offers a different product entirely as the giveaway. For example, add a free product (ID 44) whenever a customer buys a specific product (ID 83):

function add_free_product_when_targeted_product_in_cart() {
$targeted_product_id = 123; // Replace with your target product ID
$free_product_id = 456; // Replace with your free product ID
$cart = WC()->cart->get_cart();
$has_targeted_product = false;
$has_free_product = false;
foreach ($cart as $cart_item) {
    if ($cart_item['product_id'] == $targeted_product_id) {
        $has_targeted_product = true;
    }
    if ($cart_item['product_id'] == $free_product_id && isset($cart_item['custom_price'])) {
        $has_free_product = true;
    }
}
if ($has_targeted_product && !$has_free_product) {
    WC()->cart->add_to_cart($free_product_id, 1, 0, array(), array('custom_price' => 0));
}
}
add_action('woocommerce_before_calculate_totals', 'add_free_product_when_targeted_product_in_cart');

Pair it with the same custom-price function used throughout this guide. Add the targeted product to your cart and confirm that WooCommerce automatically adds the free product alongside it.

How to Create a WooCommerce BOGO Coupon With a Free Plugin

Smart Coupons for WooCommerce includes BOGO functionality in its free version, which makes it a solid option if you’d rather avoid editing code.

Go to Marketing > Coupons, or use the plugin’s dedicated Add Coupon screen. Select BOGO from the Discount Type dropdown, then set how many times the coupon can be used.

Check Apply Coupon Automatically if you want the discount to apply without customers entering a code. You can also choose where a discount banner displays on your site.

In the Giveaway Products section, select which products qualify for the free item. The free version limits this to specific products; you can select multiple products to build a buy X get Y setup.

With auto-apply enabled, the coupon applies as soon as a qualifying product hits the cart. Without it, customers either enter the code manually or click a discount banner you’ve placed on site.

WooCommerce Buy One Get One Half Off Using a Coupon

Use the same coupon setup, but in the Giveaway Products tab, set a percentage value instead of 100% off, for example 50%, to create a half-off second item instead of a fully free one.

You can layer in conditions too: restrict BOGO coupons by payment method, shipping option, user role, or customer location to target specific segments. After creating a coupon, use the Copy Coupon URL option to let customers apply the discount with one click from a link in your banners or email campaigns, instead of typing a code.

How to Create a WooCommerce BOGO Discount With a Premium Plugin

For more advanced conditions (first-order-only deals, tiered ranges, product combinations) a dedicated discount rules plugin is faster than maintaining custom code. Discount Rules for WooCommerce by FlyCart is a widely used option for this.

Same-Product BOGO

After installing the plugin, add a new rule and choose Buy X, Get X. Under Filters, select Products and choose the item you’re targeting. In the Discount tab, set the giveaway value to free, then save and test from the front end.

First-Order BOGO Deals

To limit a BOGO offer to first-time customers, select All Products as the target, then in the Rules tab add a condition and choose First Order from the condition type dropdown. You can also set expiry dates and usage limits here.

Tiered and Ranged BOGO Deals

Checking the Recursive box repeats the discount for every matching pair in the cart (2 products in the cart gives 2 free, and so on). Unchecking it lets you build custom ranges instead, for example: buy 1, get 10% off the second; buy 3, get 1 free; or buy 7–10, get the last two at a reduced price.

WooCommerce Buy One Get One Half Off

Select the percentage discount type in the Discount tab and set the value to 50% for a half-off second item, or use a fixed amount instead.

Combination BOGO (Buy X Get Y Across Different Products)

To offer a free item when a customer buys two different products together, for example a free cap when buying a hoodie and a T-shirt, select Buy X Get Y as the discount type, choose the required products, set the mode to Auto-add, define the minimum buy quantity, and select the free giveaway product. Then add a Product Combination condition in the Rules tab and select the same products with the combine option enabled.

Best WooCommerce Discount Plugin for BOGO Deals: Disco

Disco – WooCommerce Dynamic Pricing & Discount Rules Plugin builds BOGO and buy X get Y offers using a visual rule engine, so you can set conditions on products, categories, and cart totals without writing code.

It’s built specifically around WooCommerce’s product and pricing structure, which keeps rule setup consistent whether you’re running a simple same-product BOGO or a multi-product combination deal.

Key Features

  • Buy X, Get Y rules: Set a required purchase quantity and a separate free or discounted item.
  • Percentage and fixed giveaway pricing: Offer items fully free, at a percentage off, or at a fixed reduced price.
  • Category and cart-based conditions: Trigger BOGO rules by product, category, or cart total instead of individual coupon codes.
  • Automatic application: Discounts apply in the cart without requiring a coupon code.
  • Rule scheduling: Set start and end dates for time-limited BOGO campaigns.

Pricing details and the current feature list are available on the official Disco plugin page. Check there before publishing any specific pricing claims, since plans can change.

Frequently Asked Questions

How do I set up a WooCommerce BOGO discount without a plugin?

Add custom code to your theme’s functions.php file using two functions: one that adds a free unit of the qualifying product to the cart, and one that sets that free item’s price to zero. Back up your site or use a child theme before editing, since a code error can break your storefront.

What does buy X get Y in WooCommerce?

Buy X get Y is a BOGO variation where the free or discounted item is different from the item the customer purchased, for example buying a hoodie and receiving a free cap. It requires a rule that checks for both a target product and a separate giveaway product.

Can I offer a WooCommerce BOGO deal only to first-time customers?

Yes. Plugins like Discount Rules for WooCommerce support a First Order condition, which limits the BOGO offer to customers placing their first order on your store.

How do I create buy one get one coupons in WooCommerce?

Use a coupon plugin such as Smart Coupons for WooCommerce, select the BOGO discount type, choose your giveaway products, and optionally enable auto-apply so the coupon triggers without a code.

Does WooCommerce support BOGO discounts by default?

No. WooCommerce’s built-in coupon system doesn’t include BOGO logic. You need either custom code or a plugin that adds a rule engine for quantity-based and product-based giveaways.

Key Takeaways

  • WooCommerce has no native BOGO feature, so a buy one get one discount always needs either custom code or a plugin.
  • Custom code works for free, but requires editing functions.php and carries more risk if a snippet is misconfigured.
  • Smart Coupons for WooCommerce handles simple, coupon-triggered BOGO and buy X get Y offers in its free version.
  • Discount Rules for WooCommerce and Disco both support automatic, no-coupon BOGO rules, including tiered ranges, product combinations, and first-order-only deals.
  • Buy X get Y setups, where the free item differs from the purchased item, need a rule that checks for both products separately.
  • Half-off and percentage-based giveaways use the same rule structure as fully free BOGO deals, just with a different discount value.
Leave a Reply

8,519,129+ Downloads. 724+ plus 5-star ratings. Promote products on any platform you want.