One of the smartest ways to increase conversions in WooCommerce is by offering automatic free gifts.
Customers love bonuses, and even a small free product can dramatically improve average order value.
In this tutorial, you will learn how to automatically add a free product to the cart
when the customer reaches a specific cart total using a WooCommerce hook.

Why This Strategy Works
Automatic free gifts create a psychological effect that encourages customers to spend more.
For example:
- Spend $50 and get a free sticker pack
- Spend $100 and receive a free mug
- Spend $200 and unlock a premium gift
This technique is commonly used by large eCommerce brands because it increases:
- Average order value
- Conversion rates
- Customer satisfaction
- Repeat purchases
The WooCommerce Hook We Will Use
WooCommerce provides a powerful hook called:
woocommerce_before_calculate_totals
This hook allows us to inspect and modify the cart before WooCommerce calculates totals.
Perfect for adding free products dynamically.
The Full Code
Add this code inside your theme’s functions.php file
or inside a custom plugin.
add_action('woocommerce_before_calculate_totals', 'add_free_gift_to_cart');
function add_free_gift_to_cart($cart) {
if (is_admin() && !defined('DOING_AJAX')) {
return;
}
$free_product_id = 123;
$minimum_amount = 100;
$cart_total = $cart->subtotal;
$gift_in_cart = false;
foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['product_id'] == $free_product_id) {
$gift_in_cart = true;
}
}
if ($cart_total >= $minimum_amount && !$gift_in_cart) {
$cart->add_to_cart($free_product_id);
} elseif ($cart_total < $minimum_amount && $gift_in_cart) { foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['product_id'] == $free_product_id) {
$cart->remove_cart_item($cart_item_key);
}
}
}
}
How the Code Works
The function checks the cart subtotal every time WooCommerce recalculates the cart.
- If the customer spends more than the required amount, the free gift is added automatically
- If the cart total drops below the limit, the gift is removed
- The code also prevents duplicate gifts from being added
Important Notes
- Replace 123 with your actual WooCommerce product ID
- You should create a hidden or virtual product for the free gift
- Test the functionality with coupons and taxes enabled
Bonus Improvement
You can improve this feature even more by displaying a progress bar like:
Spend $15 more to unlock your free gift!
This creates urgency and motivates customers to add more products to their cart.
