How to Automatically Add a Free Gift to Cart in WooCommerce – 2026

Last updated on May 23rd, 2024 at 06:17 am

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 incentivises 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 – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1132
* Tested with WooCommerce 10.7.0
* "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 – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1132
* Tested with WooCommerce 10.7.0
* "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 – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1132
* Tested with WooCommerce 10.7.0
* "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.
See also  How to Show Product Stock at WooCommerce Cart Page - 2026

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.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Marc
Marc
July 4, 2024 1:54 am

Thanks for the snippet :))
May I have a question, how can I remove the free gift automatically, if the cart total drops under the minimum amount?

Marc
Marc
Reply to  John Cook
July 4, 2024 5:24 pm

Thank you so much! It works perfectly :D!

Daz
Daz
September 8, 2024 12:59 pm

Thank you for the great work, being fairly new to the ins and outs of woocoomerce where can I add this please.
I assume it is the function.php in the theme child

Thanks

Last edited 1 year ago by Daz
Sam
Sam
September 10, 2024 4:08 am

How can I prevent a customer from adding more quantity’s of free items to their cart?

Scroll to Top
7
0
Would love your thoughts, please comment.x
()
x
×