Add Gift To The Card

How to Automatically Add a Free Gift to the Cart in WooCommerce without a plugin

Introduction

If you’re running an online store using WooCommerce, enhancing customer experience is crucial for driving sales and customer loyalty. One effective strategy is to automatically add a free gift to the cart during checkout. In this blog post, we will cover how to streamline this process.

Setting Up WooCommerce for Free Gifts

First, you’ll need to ensure that your WooCommerce plugin is up to date. There are various extensions available that facilitate adding free gifts to the cart. Most function by setting conditions, such as spending a minimum amount, to automatically include an item as a gift.

Implementing the Free Gift Feature

To implement this feature, consider using a dedicated code snippets instead of plugin.

In the world of online retail, offering a free gift with a purchase can significantly enhance customer satisfaction and increase sales. For WooCommerce store owners, automating this process can save time and ensure consistent application of your promotion rules. This guide will walk you through how to automatically add a free gift to cart in WooCommerce, a strategy that can help drive bigger cart values and improve overall shopping experiences.

Understanding the Benefit

Automatically adding a free gift in WooCommerce not only excites customers but also incentivizes larger purchases. Whether it’s a limited-time offer or a permanent perk for reaching a certain spending threshold, this tactic can lead to increased order sizes and more repeat customers.

Step 1: Define the Free Gift Criteria

Before implementing any code, decide under what conditions a free gift should be added. Common criteria include a minimum spend amount, purchasing specific products, or buying during a promotional period.

Step 2: Add the Free Gift to the Cart Automatically

Here’s how you can automatically add a free gift to the cart once the predefined conditions are met:

/* * Snippet: How to Automatically Add a Free Gift to Cart in WooCommerce – 2025
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1132
* Tested with WooCommerce 9.3.3
* “Check if cart meets conditions for adding a free gift and add it” */ function wcsuccess_add_free_gift_to_cart() { $minimum_amount = 100; // Minimum spend of $100 to qualify for the free gift $free_gift_product_id = 123; // The WooCommerce product ID of the free gift if ( WC()->cart->total >= $minimum_amount ) { $found = false; foreach ( WC()->cart->get_cart() as $cart_item ) { if ( $cart_item[‘product_id’] == $free_gift_product_id ) { $found = true; break; } } if ( !$found ) { WC()->cart->add_to_cart( $free_gift_product_id ); } } } add_action(‘woocommerce_cart_updated’, ‘wcsuccess_add_free_gift_to_cart’);

Step 3: Prevent the Free Gift from Being Purchased or Removed

Once the free gift is in the cart, it’s crucial to ensure that customers cannot purchase it as a regular product or remove it from the cart. Here’s how to handle these scenarios:

/* Snippet: How to Automatically Add a Free Gift to Cart in WooCommerce – 2025
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1132
* Tested with WooCommerce 9.3.3
* “Prevent the free gift from being purchased directly”
*/
function wcsuccess_prevent_purchasing_free_gift($purchasable, $product) {
if ($product->get_id() == 123) { // Check if the product is the free gift
return false;
}
return $purchasable;
}
add_filter(‘woocommerce_is_purchasable’, ‘wcsuccess_prevent_purchasing_free_gift’, 10, 2);
/* Snippet: How to Automatically Add a Free Gift to Cart in WooCommerce – 2025
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1132
* Tested with WooCommerce 9.3.3
* “Prevent the free gift from being removed from the cart”
*/
function wcsuccess_prevent_free_gift_removal($cart_item_key) {
$product_id = WC()->cart->cart_contents[$cart_item_key][‘product_id’];
if ($product_id == 123) {
// Check if the product is the free gift
WC()->cart->remove_cart_item($cart_item_key); }
}
add_action(‘woocommerce_before_cart_item_quantity_zero’, ‘wcsuccess_prevent_free_gift_removal’);

How to Automatically Add a Free Gift to Cart in WooCommerce – Use Cases

  1. Holiday Promotions: During holiday seasons, automatically adding a themed gift can make shopping more engaging.
  2. First-Time Buyers: Encourage first-time purchases by offering a special gift when newcomers spend over a certain amount.
  3. Loyalty Rewards: Reward returning customers by automatically adding a gift to their cart once they reach a cumulative spending threshold.

Conclusion

Learning how to automatically add a free gift to cart in WooCommerce can significantly enhance your online store’s appeal and effectiveness. It’s a strategy that not only drives sales but also builds customer loyalty and satisfaction. By following the steps outlined above, you can seamlessly integrate this feature into your WooCommerce store, ensuring your promotions run automatically and efficiently.