Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Set Up a BOGO Deal: “Buy 2 and Get 1” Offer in WooCommerce?

Looking to spice up your WooCommerce store with enticing promotions? Let’s say your customers browsing through your online shop, stopped by a “Buy 2, Get 1 Free” offer on their favorite products.

Such BOGO promotions, especially when paierd with WooCommerce Bundled Products makes wonders. For instance, think of an “Electronic Bundle Deal” where buying a TV and a stabilizer together earns customers a high-quality wireless speaker for free. Such offers not only boost sales but also add excitement and value for your shoppers.

In this guide, we’ll show you how to effortlessly set up Buy 2 Get 1 offer programatically in your WooCommerce store.

Solution: Set Up a BOGO Deal: “Buy 2 and Get 1” Offer in WooCommerce

This code snippet sets up a functionality in WooCommerce where a specific gift product (product C) is added to the cart conditionally based on the presence of two other products (product A and product B)

add_action( 'template_redirect', 'ts_add_gift_id_in_cart' );

function ts_add_gift_id_in_cart() {

    if ( is_admin() ) return;
    if ( WC()->cart->is_empty() ) return;

    $product_a_id = 100;
    $product_b_id = 457;
    $product_gifted_id = 470;

    // see if product A in cart
    $product_a_cart_id = WC()->cart->generate_cart_id( $product_a_id );
    $product_a_in_cart = WC()->cart->find_product_in_cart( $product_a_cart_id );

    // see if product B in cart
    $product_b_cart_id = WC()->cart->generate_cart_id( $product_b_id );
    $product_b_in_cart = WC()->cart->find_product_in_cart( $product_b_cart_id );

    // see if gift id 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 both products A and B are in cart, add gift C
    if ( $product_a_in_cart && $product_b_in_cart ) {
        if ( ! $product_gifted_in_cart ) {
            WC()->cart->add_to_cart( $product_gifted_id );
        }
    } else {
        // if not both products A and B are in cart, remove gift C if present
        if ( $product_gifted_in_cart ) {
            WC()->cart->remove_cart_item( $product_gifted_in_cart );
        }
    }
}
flexi bogo cta banner image


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 free product gets automatically added to the cart, only when a customer purchases both products A and B. The free product doesn’t get added if only one of the specified products is added to the cart.

"Buy 2 and Get 1" Offer in WooCommerce

Enhance your promotional efforts and start exploring more BOGO promotions such as to implement buy 1 get 2 free action in WooCommerce which handles the bogo gift offering under various conditions.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x