While promotions and offers are attempted to make customers complete a purchase, this strategy to offer BOGO 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) } }
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? 1 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/Free-Product-Added-on-specific-Order-status-changed-1024x606.png)
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? 2 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/order-details-2-1024x700.png)
![How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? 3 How to Add a BOGO (Buy One Get One) Offer on Order Status Change in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/admin-order-details-724x1024.png)
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.