Creating a simple straightforward BOGO (Buy One, Get One) discount in WooCommerce is a fundamental strategy for any online store looking to enhance their discount offerings. However, as you delve into more advanced strategies involving conditional logic, the BOGO discount can become even more powerful.
In this guide, we will be looking into automatically adding a free product to the cart when customers apply a specific coupon code and meet the minimum spending requirement.
Solution: Add a BOGO (Buy One Get One) Offer with a Coupon Code & for Orders Over $100
The provided code offers a specific benefit while providing BOGO “Buy One Get One” offers to customers when the following two conditions are met:
- The BOGO offer is triggered when customers apply a specific coupon code.
- Also, if the total order amount is equal to or exceeds $100. If any of the condition is not met then the free product is not added to the cart.
function ts_add_free_product_based_on_coupon() { global $woocommerce; $coupon_code = 'newyear2024'; // Set the coupon code to trigger free product $free_product_id = 470; // Set the ID of the free product $min_cart_total = 100; // Set the minimum cart total to trigger free product // Check if the coupon is applied and the cart total is above $100 if ($woocommerce->cart->has_discount($coupon_code) && $woocommerce->cart->subtotal >= $min_cart_total) { // Check if the free product is not already in the cart $product_already_in_cart = false; foreach ($woocommerce->cart->get_cart() as $cart_item) { if ($cart_item['product_id'] == $free_product_id) { $product_already_in_cart = true; break; } } // If the free product is not in the cart, add it if (!$product_already_in_cart) { $woocommerce->cart->add_to_cart($free_product_id); wc_add_notice(__('Free product added!'), 'success'); } } } add_action('woocommerce_before_cart_table', 'ts_add_free_product_based_on_coupon', 10, 0);
This to the shop owners who are running or planning to run BOGO offers on their WooCommerce store…
BOGO deals are great for increasing your sales, but have you thought about which offers are bringing you more revenue and which offers are not performing that great?
Don’t just set a BOGO deal, track the revenue generated by your deals in real-time with the Flexi BOGO for WooCommerce plugin.
Output
The output shows that the free product is added only when the coupon is applied and the cart subtotal is greater than the minimum cart total amount set in the code.
Just like this customization, where we automatically add a free product based on a coupon code and minimum cart value, there are numerous other ways to enhance your WooCommerce store. Explore a variety of promotional strategies, such as automatically adding a product to your cart under different conditions like specific categories, cart totals, or even on website visits.