Setup WooCommerce Buy One Get One Discount

How to Setup WooCommerce Buy One Get One Discount (Easy Guide)

We all know that cart abandonment is any eCommerce/WooCommerce store owner’s worst nightmare. Online shops lose a jaw-dropping 4 trillion dollars per year on abandoned carts; that’s 12 zeros!

Do you know the leading reason people abandon your carts?

High cost (48% of shoppers abandon carts due to high costs). However, there’s one way through which you can significantly reduce abandoned carts and boost your sales.

Discounts and coupons. By implementing compelling and effective discount strategies, you can capture the attention of your target customers and increase your sales and revenue manifold.

One of the most popular and enticing discount types is the Buy One, Get One offer, also known as a BOGO deal. These discounts create a sense of urgency and excitement among visitors, ultimately increasing sales and earning customer satisfaction.

In this article, we will explore how to generate a WooCommerce buy one get one discount using different methods.

Let’s get started.

How to Create a WooCommerce Buy One Get One Discount?

Despite having a built-in coupon tool, core WooCommerce doesn’t have the features to create a buy-one-get-one WooCommerce discount.

However, there are multiple ways you can achieve this.

  1. Using custom codes in WooCommerce theme files
  2. Using a coupon plugin for creating buy one get one free WooCommerce coupons
  3. Using a premium discount plugin

Let’s check out how to do buy one get one free on WooCommerce using custom codes.

Creating WooCommerce Buy One Get One Discount using Custom Codes

Do not attempt this method unless you are absolutely sure what you are doing. Make sure you are using a child theme or have a backup of your website files.

Let’s create some WooCommerce buy one get one discounts for the following scenarios.

  • Buy any one product and get an extra quantity of the same product for free
  • Buy a specific product and get an extra quantity of that for free
  • Buy X amount of a product to get one for free
  • Buy X product and get Y for free

Buy Any One Product and Get an Extra Quantity of the Same Product For Free

Here are the steps to create this WooCommerce coupon buy one get one off discount.

Step 1 – Access Theme File

Go to Appearance >> Theme File Editor.

theme file editor

Click on the functions.php file and scroll down to the bottom to enter your custom codes.

functions php
Step 2 – Add Custom Code

Create a function to add free quantity –

  • Check Cart Items:
    • Loop through each item in the cart to identify products and their quantities.
  • Add Free Quantity:
    • For each product, if there is at least one quantity, add an equal quantity of the same product for free.

Here are the codes –

function add_bogo_free_product() {

$cart = WC()->cart->get_cart();

// Loop through cart items to check products

foreach ($cart as $cart_item_key => $cart_item) {

     $product_id = $cart_item['product_id'];

     $quantity = $cart_item['quantity'];

     // Ensure no free items are added

     if (!isset($cart_item['custom_price']) && $quantity > 0) {

         // Check if a free product is already in the cart

         $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;

             }

         }

         // Add free products if not already in the cart

         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');

Create the function to apply the custom price

  1. Set Free Product Price to Zero:
    • Loop through the cart and set the price of any product marked as a free item to zero.

Here are the codes –

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 the functions.php file. Go to your storefront and add any product to the cart.

Go to the cart page, and you will see WooCommerce automatically added an additional quantity of that same product for free.

WooCommerce buy one get one discount

Buy a Specific Product and Get an Extra Quantity of That For Free

Remove the previous code from functions.php and proceed to the following steps.

Add a Function to Add Free Quantity of a Specific Product

Check Cart Items:

  • Loop through the cart items to identify the targeted product and its quantity.

Add Free Quantity:

  • If the targeted product is in the cart, add an equal quantity of the same product for free if not already added.

Here’s the code –

function add_free_product_with_targeted_product() {

// Define the targeted product ID

$targeted_product_id = 123; // Change this to your targeted product ID

// Get the cart items

$cart = WC()->cart->get_cart();

// Initialize flag for targeted product

$targeted_product_count = 0;

$free_product_exists = false;

// Loop through cart items to check for targeted product

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;

         }

     }

}

// Add the free product if the targeted product is in the cart and the free product isn't already in the cart

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');

You must replace the product ID ($targeted_product_id = 123;) with your targeted valid product ID.

Collect the Product ID

WooCommerce auto-generates and assigns a product ID to each product you create in your website. You can easily collect them from the All Products page.

Go to Products >> All Products. After that, hover over the targeted product to collect the ID.

product id

Replace the ID in the code above (e.g., $targeted_product_id = 83).

replace id
Add a Function to Apply Custom Price
  1. Set Free Product Price to Zero:
    • Loop through the cart and set the price of any product marked as a free item to zero.

Here are the codes –

function apply_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_custom_price');

Save your functions.php file and test it out from the front end.

We targeted this product –

add product

Let’s add this to the cart and view the cart page.

WooCommerce buy one get one discount

As you can see, WooCommerce automatically added an additional amount of that product for free.

Buy X Amount of a Product to Get One For Free – WooCommerce Buy One Get One Discount

Let’s say you want to offer a WooCommerce BOGO offer where customers need to add 2 items of a targeted product to get one for free.

Here’s the code –

function add_free_product_for_buy_two_get_one($cart) {

// Define the targeted product ID

$targeted_product_id = 123; // Change this to your targeted product ID

// Initialize counts

$targeted_product_count = 0;

$free_product_count = 0;

// Loop through cart items to count quantities

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'];

        }

     }

}

// Calculate the required free quantity

$required_free_quantity = floor($targeted_product_count / 2);

// Add free products if needed

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');

Again, you must replace the product ID with a valid one. Let’s target a different product this time.

collect id

Next, add a function to apply the custom price.

function apply_free_product_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_free_product_custom_price');

Let’s add our targeted product to the cart and jump to the cart page.

add to cart

No WooCommerce buy one get discount applied, right?

no applied

This is because we set the minimum targeted quantity to 2, which means your customers must add 2 quantities of this product to avail themselves of WooCommerce buy two, get one free.

WooCommerce BOGO deal

As you can see, the cart page adds a free product when you increase the quantity to 2.

Buy X Product and Get Y For Free

Let’s say you want to offer a different but specific product for free when the customers adds a targeted product. For instance, we want to offer the previous example’s 44 ID product for free when customers add the 83 ID product to the cart.

Make sure you remove all your previously added codes from the above examples.

Here’s the code for this WooCommerce buy one get one free offer –

function add_free_product_when_targeted_product_in_cart() {

$targeted_product_id = 123; // Change this to your targeted product ID

$free_product_id = 456; // Change this to your free product ID

$cart = WC()->cart->get_cart();

$has_targeted_product = false;

$has_free_product = false;

// Loop through cart items to check for targeted and free products

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;

     }

}

// Add the free product if the targeted product is in the cart and the free product isn't already in the cart

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');

You must replace the IDs with your actual IDS.

In our case, it should be –

$targeted_product_id = 83; // Change this to your targeted product ID
$free_product_id = 44; // Change this to your free product ID

Now, apply the custom price –

function apply_custom_price_for_free_product($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_custom_price_for_free_product');

Go to the 83 IDs product page and add the item to the cart.

WooCommerce buy one get one discount

As you can see, WooCommerce automatically added the ID-44 product for free when the ID-83 product is added to the cart.

Using a Coupon Plugin for Creating BOGO Discounts

We will use a buy one get one free WooCommerce plugin named Smart Coupons For WooCommerce. This plugin has BOGO features in its free version.

WooCommerce buy one get one discount coupon plugin

However, you can try the premium version for full features. Go to Marketing >> Coupons or from Smart Coupons >> Add Coupon.

add coupon

The plugin adds additional settings to the core WooCommerce coupon settings.

coupon window

Most importantly, it adds WooCommerce buy one get one discount features.

BOGO features

Select the BOGO option from the Discount Type dropdown. You can also appoint the number of times the coupon may be used.

select BOGO

If you checkmark the Apply coupon automatically box, the plugin will automatically apply the coupon without customers needing to input the code manually.

apply coupon auto

Additionally, you can assign where on your site you want to display a discount banner.

Jump to the Giveaway Products window.

select free product

The free version of the WooCommerce coupon buy one get one plugin only allows you to select specific products.From the Products box, you can select the products on which you want the coupon or discount to apply.

select free products

Search and select the product and set the values. You can also select multiple products to setup Buy X Get Y deal.

select multiple products

Now, if you have check-marked the Apply coupon automatically box, the coupon will be auto-applied when a customer adds the selected products to the cart.

WooCommerce buy one get one discount

If not, customers will have to enter the code manually. Alternatively, you can display a coupon banner on your pages, and customers can click to apply the coupon.

banner page

Here’s the cart page again. Click the coupon banner to apply.

coupon banner

As we selected multiple giveaway products, the cart added all of them as a giveaway. Select a single product in the Giveaway tab to offer a WooCommerce buy-one-get-one-free coupon.

WooCommerce buy one get one discount

WooCommerce Buy One Get One Half Off Using Coupon

Let’s check how to do a buy one get one half WooCommerce coupon. All the settings will be the same as before.

You only need to go to the Giveaway Products tab and set the percentage of the giveaway product.

50% off

Here’s how it looks in the front end.

WooCommerce BOGO half off

Additionally, you can also create BOGO (Buy One, Get One) coupons with various conditions to make your offers even more appealing. Imagine offering BOGO deals for customers who use specific payment methods, choose particular shipping options, belong to certain user roles, or live in specific locations.

checkout options

This way, you can tailor your promotions to target and reward specific groups of customers, creating a more personalized shopping experience and boosting customer loyalty.

Another valuable feature of the plugin is the Copy Coupon URL option. After you create a coupon, this option appears at the top, beside the coupon code.

WooCommerce buy one get one discount coupon url

Using this URL, users can automatically apply the coupon on the cart page. Simply link it to your banners and promotional content, and your customers will enjoy the discount effortlessly. This makes it easy for them to take advantage of your offer with just a click!

Creating a WooCommerce Buy One Get One Discount Using a Premium Discount Plugin

The methods we have seen so far are a good starting point for offering a WooCommerce buy-one-get-one discount. However, if you want to offer more advanced and flexible BOGO deals tailored to your customers’ needs and aligned with your marketing strategies, you need to use a premium plugin.

The plugin we will use to demonstrate advanced BOGO deals is Discount Rules for WooCommerce. This plugin allows you to create discounts with minimum effort, whether you want to create automated discounts based on complex conditions, bundle discounts or bulk discounts, quantity discounts or category discounts, or even reward your first-time customers.

In our previous articles, we have thoroughly explored different discount types and settings for this plugin. Today, we will directly jump to create a WooCommerce buy-one-get-one discount.

Create WooCommerce Buy One Get One Discount for the Same Product

After you install and activate the plugin, go to its dedicated menu and add a new rule.

add WooCommerce buy one get one discount rule

The plugin has dedicated options for BOGO deals. Select Buy X, Get X to start with.

Select WooCommerce BOGO

As we are creating the BOGO deal for a specific product, we need to select the product. From the Filters tab, select Products. Search and select the product you are targeting.

select products

From the Discount tab, set your giveaway value and make sure you set it to free.

WooCommerce buy one get one discount value

Save the rule and add the targeted product from your front end to test this discount.

WooCommerce buy one get one discount

As you can see, WooCommerce automatically added an additional quantity of the same product for free.

Creating BOGO Deals for First Time Customers

Offering a WooCommerce buy one get one discount to first-time customers is a great strategy to entice your visitors and convert them into buying customers. You can create a BOGO deal for first orders using the plugin.

We will offer a BOGO deal for any products to first-time purchasers. Therefore, select All Products.

all products

Keep other settings the same. In the Rules tab, add a condition.

add condition

Select the condition First Order from the condition type dropdown.

first order

You can also set rule limits and expiry dates from the settings.

first order WooCommerce buy one get one discount

Now, your new customers will enjoy a free product along with their purchases for the first time.

WooCommerce buy one get one discount

Creating WooCommerce BOGO Deals for Different Ranges

If you select the Recursive checkbox, the discount will be repeatedly applied to every other product. This means if customers add 2 products, they will get 2 more for free, and so on.

recursive checkbox

You can also add more ranges to your BOGO deal. For example, let’s say you want to offer buy one and get a 10% discount on the second one; buy 3, get 1 free, or 7-10 and get the last two at $30.

First, uncheck the recursive box. After that, add ranges and set values.

ranges for WooCommerce buy one get one discount

For example, let’s add 7 products to the cart.

WooCommerce buy one get one discount

As you can see, because this falls under the 7-10 range, the last two are priced at $15 each, $30 in total.

Create WooCommerce Buy One Get One Half Off

Simply select the percentage option from the discount type in the Discount tab.

percentage discount

Finally, set the percentage value to 50 to offer 50% off.

half off

You can also offer a fixed discount on the giveaway product.

fixed discount

Combination WooCommerce Buy One Get One Discount

Let’s say you want to offer a free cap when a customer buys a hoodie and a T-shirt together. This type of combination discount is the most popular among customers as it provides more value.

Select the Buy X Get Y option from the discount type dropdown.

Buy X Get Y

Select the products customers must add to the cart to avail of the discount.

select products

Next, do the following from the Discount tab.

Buy x Get Y settings
  1. Set the Y discount type to Buy X Get Y – Products.
  2. Select the mode  – Auto-add.
  3. Set the minimum buy quantity.
  4. Select the product you want to offer for free and set its quantity.
  5. Select the discount type to free.

Afterward, go to the Rules tab and add the Product Combination condition.

product combination

Select the products again and ensure you select the combine option.

Let’s check the WooCommerce buy-one-get-one discount from the main site. Add the targeted products to the cart and check your cart page.

WooCommerce buy one get one discount

Voila! Working perfectly.

Wrap up

WooCommerce BOGO deals are the perfect marketing strategy for you to grab the attention of new and old customers and increase your overall sales. Moreover, you can use these deals to clear out your slow-moving stocks and create space for new products.

We hope this guide on WooCommerce buy one get one discount will help you create compelling BOGO deals for your online store.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

5,974,910+ Downloads. 610+ plus 5-star ratings. Promote products on any platform you want.