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
- Holiday Promotions: During holiday seasons, automatically adding a themed gift can make shopping more engaging.
- First-Time Buyers: Encourage first-time purchases by offering a special gift when newcomers spend over a certain amount.
- 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.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch


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?
Thank you so much! It works perfectly :D!
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
Hi Daz, yes, add it to your functions.php file of your child theme
How can I prevent a customer from adding more quantity’s of free items to their cart?
Hi Sam, the easiest way would be to limit 1 per order on the free product edit screen under the inventory tab.
