Share X in ✉

How to offer a free gift in WooCommerce

Last updated
Read time
7 min
Category
How to offer a free gift in WooCommerce

To offer a WooCommerce free gift, you extend the core plugin with rule-based logic tied to products, cart contents, categories, or customer history, since WooCommerce has no native “free gift with purchase” setting. You can do this with a custom code snippet, a coupon plugin’s BOGO rules, or a dedicated discount plugin like Disco, which automatically applies gift-add logic at checkout for scenarios such as “buy X, get Y,” category-based gifts, or a free item above a cart threshold.

This guide walks through all three methods so you can pick the one that fits your store and your comfort with code.

Ways to add a free gift in WooCommerce

There’s no single “correct” method here. It comes down to how much developer time you want to spend versus how much you’re willing to pay for a plugin that handles it for you.

  • Custom code added to functions.php
  • A coupon, using a coupon plugin
  • A dedicated free gift or discount rules plugin

Custom code costs nothing but means you’re maintaining PHP snippets that can break on a theme or WooCommerce update. The two plugin routes cost time upfront to configure, but they survive updates and don’t need a developer on call. Here’s each one in detail, starting with the code.

Add a free gift using custom code in functions.php

Both examples below hook into woocommerce_before_calculate_totals to check the cart, then add a free item when the condition is met. Back up your site before editing functions.php, since a syntax error here can take the front end down. Edit the file through Appearance > Theme Editor > functions.php, or over FTP/cPanel if you’d rather not touch the dashboard editor.

Give a free product when the cart has 2+ items

Say you want to give away a cap once someone adds two products to their cart, regardless of what those products are. Paste this into functions.php:

function add_free_product_with_two_items() {

  // Define the targeted product ID for free offer

  $free_product_id = 123; // Replace with your actual product ID

  // Define the minimum required product count (excluding free product)

  $minimum_product_count = 2;

  // Get the cart items

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

  // Initialize variables

  $non_free_product_count = 0;

  $free_product_exists = false;

  // Loop through cart items

  foreach ($cart as $cart_item) {

// Check if it's not the free product (based on custom price)

if (!isset($cart_item['custom_price'])) {

   // Increase non-free product count

   $non_free_product_count++;

} else {

   // Check if free product is already added

   $free_product_exists = true;

}

  }

  // Add the free product if conditions are met

  if ($non_free_product_count >= $minimum_product_count && !$free_product_exists) {

WC()->cart->add_to_cart($free_product_id, 1, 0, array(), array('custom_price' => 0));

  }

}

// Hook the function to 'woocommerce_before_calculate_totals'

add_action('woocommerce_before_calculate_totals', 'add_free_product_with_two_items');

The $minimum_product_count variable sets how many non-free items trigger the offer. The loop counts cart items that don’t already have a custom_price set, then checks whether the free product is already in the cart so it doesn’t get added twice.

To find the product ID for the free item, go to Products > All Products and hover over the product. The ID shows up in the edit link. Replace 123 with that number.

Add this second snippet below the first one to force the free item’s price to zero:

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

Add any two products to the cart to test it. You don’t need to add the free item yourself, the code does that automatically once the cart hits the threshold.

Restrict the free gift to one category

The first snippet gives away a free product for any two items. This one is narrower: it only counts items from a specific category, so you could give a free cap only when someone buys two hoodies, not two random products.

// Function to add free cap when buying 2 hoodies

function add_free_cap_for_hoodies_offer() {

// Define the hoodie product category slug

$hoodie_category_slug = 'hoodies';

// Define the free cap product ID

$free_cap_product_id = 164; // Replace with your free cap product ID

// Get the cart items

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

// Initialize counters and flags

$hoodie_count = 0;

$cap_in_cart = false;

// Count the number of hoodies in the cart and check if the free cap is already added

foreach ($cart as $cart_item) {

 	$product_id = $cart_item['product_id'];

 	if (has_term($hoodie_category_slug, 'product_cat', $product_id)) {

     	$hoodie_count += $cart_item['quantity'];

 	}

 	if ($product_id == $free_cap_product_id) {

     	$cap_in_cart = true;

 	}

}

// Add the free cap if there are at least 2 hoodies and the free cap is not already in the cart

if ($hoodie_count >= 2 && !$cap_in_cart) {

 	WC()->cart->add_to_cart($free_cap_product_id, 1, 0, array(), array('free_cap_offer' => true));

}

}

add_action('woocommerce_before_calculate_totals', 'add_free_cap_for_hoodies_offer');

Swap $hoodie_category_slug for your own category slug and $free_cap_product_id for your free item’s ID. The has_term() check is what limits the count to that one category instead of the whole cart.

Add the price override, using a different flag (free_cap_offer) so it doesn’t collide with the first snippet if you’re running both:

// Function to apply custom price (if required)

function apply_custom_price($cart_object) {

foreach ($cart_object->get_cart() as $cart_item) {

 	if (isset($cart_item['free_cap_offer'])) {

     	$cart_item['data']->set_price(0);

 	}

}

}

add_action('woocommerce_before_calculate_totals', 'apply_custom_price');

Add two hoodies to the cart and confirm the free cap shows up at $0.

Add a free gift with a coupon plugin

If editing PHP isn’t something you want to do regularly, Smart Coupons for WooCommerce (free, by WebToffee) adds BOGO logic on top of WooCommerce’s native coupon tool without touching code.

Create a new coupon and set the discount type to BOGO. Set an expiry date and a per-customer usage limit if you want one.

To restrict the offer to specific purchased products, go to the Usage Restriction tab and add those products under the products section. Then go to the Giveaway Products tab, search for the free item, and set its discount to 100%.

Add a coupon code and publish.

You can apply this a few ways: link directly to the coupon URL in marketing emails so it auto-applies, let customers enter the code manually at checkout, or turn on the plugin’s automatic-apply option so the discount kicks in the moment the required products hit the cart. With automatic apply turned off, the plugin can show a banner on the cart page instead, and clicking it applies the coupon.

Add a free gift with Disco

For anything beyond a single BOGO rule, such as gifts tied to cart subtotal, customer lifetime spend, or category, Disco (WebAppick’s own discount rules plugin) handles it through a discount campaign builder rather than a separate coupon per offer.

To give away a free item once the cart reaches $100, create a new discount campaign and choose BOGO as the discount type. Select the products the offer applies to, then add a subtotal condition in the rules section and set it to $100.

To limit a gift to loyal customers instead of a cart total, use a “total spent” condition in the same rules area and set your minimum, optionally filtering by order status so only completed orders count toward it.

Disco’s interface has changed since this walkthrough was last checked against the live plugin, so confirm the exact field names and screenshots against your installed version before publishing.

Types of free gift offers you can run

Once you’ve picked a method, the next decision is what triggers the gift. These are the most common conditions stores use, and most plugins (including Disco and Smart Coupons) support several of them out of the box.

TriggerExample
Minimum cart totalFree gift once the cart hits $50
Tiered spendFree tote at $25+, free water bottle at $50+
Buy X, get YBuy one t-shirt, get a free pair of socks
Category purchaseFree travel pouch with any travel-accessory purchase
First orderFree gift on a customer’s first purchase only
Loyalty / repeat customerFree gift for customers who’ve placed multiple orders
Free shipping + gift comboFree shipping and a gift once a cart total is reached
Limited-time promotionGift available only during a set date range

Frequently Asked Questions

Does WooCommerce have a built-in free gift feature?

No. WooCommerce doesn’t have a native setting for “free gift with purchase.” You need custom code, a coupon plugin with BOGO rules, or a dedicated discount plugin to add this behavior to your store.

Can I offer more than one free gift in the same store?

Yes. Both Smart Coupons and Disco let you run multiple gift campaigns at once, each with its own trigger. With custom code, you’d need a separate function and a distinct flag for each gift, similar to how the two code examples above use different keys so they don’t conflict.

Can a free gift be automatically added to the cart, or does the customer have to do something?

It depends on the method. The custom code examples here add the gift automatically once the condition is met. Coupon plugins can auto-apply too, or require a code or a banner click, depending on how you configure the automatic-apply setting.

Can I limit a free gift to first-time customers only?

Yes, through a “first order” or “customer history” condition in a discount plugin. This isn’t something the custom code examples above cover; you’d need to check order history for the customer, which adds more complexity than a cart-based condition.

Key takeaways

  • WooCommerce has no built-in free gift feature. Every method here works around that gap.
  • Custom code is free but requires ongoing maintenance and breaks more easily on updates.
  • Smart Coupons handles BOGO-style free gifts without touching code, using WooCommerce’s native coupon system.
  • Disco handles more advanced conditions, like cart subtotal or total customer spend, through a discount campaign builder.
  • Common gift triggers include minimum cart value, buy X get Y, category purchase, first order, and loyalty status.
  • A free gift with purchase can meaningfully lift conversions and repeat purchases when the trigger matches how your customers actually shop.
[CTA] Stop reading. Start fixing.
Fix your product feed with CTX Feed Pro.

Free version on WordPress.org. Every Pro licence includes a 30-day money-back guarantee.

[0] Comments
Join the discussion
Leave a comment →

Leave a comment.

[NEWSLETTER] Field Notes, monthly

One email a month.
Zero fluff.

Channel-spec changes, plugin releases, the occasional deep dive on something we broke.