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

 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce?

While promotions and offers are attempted to make customers complete a purchase, this strategy of BOGO (Buy One Get One) offer on order status change can loop othem into ongoing customer engagaement. With this customization, you can offer a free product or a BOGO deal during a specific order status change such as ‘completed’ can encourage them to be repeat customers.

Solution: Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce

This code is designed to automatically add a free product to an order when the order status is changed to ‘completed’ and customize the content of the customer’s completed order email to display information about any added free gift.

function order_has_specific_product( $product_id, $order ) {
    // Loop through order items to check if a product is on the current order
    foreach ( $order->get_items() as $item ) {
        if ( in_array( $product_id, array($item->get_product_id(), $item->get_variation_id()) ) ) {
            return true;
        }
    }
    return false;
}

add_action( 'woocommerce_order_status_changed', 'ts_add_free_product_on_order_enquiry_status', 20, 4 );
function ts_add_free_product_on_order_enquiry_status( $order_id, $old_status, $new_status, $order ){
    $product_id = '470'; // Free product to be added only once

    if ( "completed" === $new_status && ! order_has_specific_product( $product_id, $order ) ) {
        $product = wc_get_product( $product_id );
        $order->add_product( $product );
        $order->calculate_totals(); // calculate taxes, totals and save (method includes save() method)
    }
}
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

By default, when the customer places an order the order status gets changed to ‘on-hold’ in WooCommerce. As mentioned in the code, we will offer the free gift only when the status gets changed from ‘on-hold’ to ‘completed’ status.

 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? - Tyche Softwares

But when the order status is ‘on-hold’ the gift doesn’t get added to the order details/thank you page and on the admin order details page.

 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? - Tyche Softwares
 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? - Tyche Softwares

Just like BOGO offers linked to order status, you can also implement BOGO strategies easily by automatically adding products to the WooCommerce cart based on parameters such as cart total, categories, and website visits.

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