Running irresistible BOGO deals that customers can’t resist is a key strategy that sets your store apart. With custom code snippets, you can effortlessly introduce Buy One, Get One (BOGO) offers that add excitement to shopping carts. These tweaks not only enhance the shopping experience for your customers but also boost your sales.
Let’s explore how implementing the ‘Buy one Get 50% off’ customization can easily elevate your store and drive more purchases.
Solution: Offer a BOGO Deal: Buy One and Get 50% Off on Product B
The code snippet will apply the discount like this: When you buy one you will get 50% off on the automatically added free product.
add_action('woocommerce_cart_calculate_fees', 'ts_add_gift_id_in_cart'); function ts_add_gift_id_in_cart() { if (is_admin()) return; if (WC()->cart->is_empty()) return; $discount = 0; $product_gifted_id = 922; // Check if gift id is in cart $product_gifted_cart_id = WC()->cart->generate_cart_id($product_gifted_id); $product_gifted_in_cart = WC()->cart->find_product_in_cart($product_gifted_cart_id); if ($product_gifted_in_cart) { $product_gifted = wc_get_product($product_gifted_id); $price = $product_gifted->get_price(); $discount -= ($price * 20) / 100; // apply 50% discount on the other product } // If gift is not in cart, add it if (!$product_gifted_in_cart) { WC()->cart->add_to_cart($product_gifted_id); } if ($discount != 0) { WC()->cart->add_fee('Discount', $discount, true); # Note: Last argument in add_fee() method is related to applying the tax or not to the discount (true or false) } }
Output
When the customer adds any product to the cart, the free product is automatically added with the discount amount specified in the code.
![How to Offer a BOGO Deal: Buy One and Get 50% Off on Product B in WooCommerce? 1 How to Offer a BOGO Deal: Buy One and Get 50% Off on Product B in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/Gift-Product-added-to-cart-with-50-Off-1024x741.png)
While implementing such BOGO promotions, you will have some expectations like when some categories of your products or high valued product is added to cart, then the free product should not be added. If that is the case, then you can aslo can restrict the free product to be added for certain cart items.