While offering BOGO discounts, it is essential to manage these promotions as some WooCommerce products that are currently on sale have already been discounted from their regular prices. So, while providing storewide offers, you can exclude providing offers to these on-sale products. Overall, you can attract customers who are looking for immediate discounts and those who purchase more to avail the free offer.
Solution: Exclude BOGO (Buy One Get One) Offer for On-Sale Products in WooCommerce
This code will add a free product for all products except when on-sale products are added to the cart.
function ts_add_free_product_to_cart( $item_key, $product_id ) { $free_product_id = 470; // Product Id of the free product which will get added to cart $found = false; // Check if the product is on sale $product_is_on_sale = get_post_meta( $product_id, '_sale_price', true ) !== ''; // Check if the product is not on sale before adding it to the cart if ( ! $product_is_on_sale ) { // Check if the free product is already in the cart if ( sizeof( WC()->cart->get_cart() ) > 0 ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if ( $_product->get_id() == $free_product_id ) { $found = true; } } // If the free product is not found, add it to the cart if ( ! $found ) { WC()->cart->add_to_cart( $free_product_id ); } } else { // If no products in the cart, add the free product WC()->cart->add_to_cart( $free_product_id ); } } } add_action( 'woocommerce_add_to_cart', 'ts_add_free_product_to_cart', 10, 2 );
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 below output shows that the free products are not added to the cart, when an on-sale product is added to the cart.
Let’s continue adding a normal product that is not an on-sale to the cart.
When a product that is not on sale is added to the cart, the free gift also gets automatically added to the cart items.
Similar to excluding on-sale products, if you have high-value items and prefer not to apply BOGO offers to them, you can use the BOGO rule in WooCommerce: “Restrict Free Products for Certain Cart Items in WooCommerce“. This rule ensures that specific product IDs will not receive free gifts when added to the cart, allowing you to maintain pricing strategies for your premium items.