Typical BOGO promotions are applied to an entire product line present in your catalog. But this customization will help you to target specific variation IDs and allows you to offer deals and discounts on precise product variations, such as a particular size, color, or style. This level of targeting ensures that the promotion is relevant to the customer’s preferences. Let’s see how the bogo offerings works for variable products.
Solution: Apply BOGO (Buy One Get One) Offer for Variable Products in WooCommerce
The code snippet applies a 50% discount on every second item of a specific product (with ID 15) in the WooCommerce cart.
add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount_2nd_at_50', 10, 1 ); function ts_add_custom_discount_2nd_at_50( $wc_cart ){ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $discount = 0; $items_prices = array(); // Set here your targeted variable product ID $targeted_product_id = 15; foreach ( $wc_cart->get_cart() as $key => $cart_item ) { if( $cart_item['product_id'] == $targeted_product_id ){ $qty = intval( $cart_item['quantity'] ); for( $i = 0; $i < $qty; $i++ ) $items_prices[] = floatval( $cart_item['data']->get_price()); } } $count_items_prices = count($items_prices); if( $count_items_prices > 1 ) foreach( $items_prices as $key => $price ) if( $key % 2 == 1 ) $discount -= number_format($price / 2, 2 ); if( $discount != 0 ){ // Displaying a custom notice (optional) wc_clear_notices(); wc_add_notice( __("You get 50% of discount on the 2nd item"), 'notice'); // The discount $wc_cart->add_fee( 'Discount 2nd at 50%', $discount, true ); } }
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
When the customer adds two quantities of Hoodie-Red items to the WooCommerce cart page, the discount applies to the second item as shown below.
Similarly, you can also implement buy 2 get 50% off on second item in WooCommerce cart page.