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

How to Set a Scheduled BOGO (Buy One Get One) Offer in WooCommerce?

Setting a promotion for a limited duration of days or a seasonal sale creates a sense of urgency to buy the product and act quickly to avail of the “buy one get one” offer. Also, this kind of limited offer always leads to a positive impact on sales.

The code checks the order date against the defined start and end date, and if the order falls within that range, the free gift is added to the customer’s cart during the checkout process.

function ts_schedule_periodic_discount_with_free_gift($cart) {
    // Define the start and end dates for the promotion
    $start_date = strtotime('2024-01-10'); // Replace with your start date
    $end_date   = strtotime('2024-02-25'); // Replace with your end date

    // Get the current date
    $current_date = current_time('timestamp');

    // Check if the current date is within the promotion period
    if ($current_date >= $start_date && $current_date <= $end_date) {
        // Set the product ID for the free gift
        $free_gift_product_id = 470; // Change this to your actual free gift product ID

        // Check if the free gift is not already in the cart
        if (!in_array($free_gift_product_id, array_column($cart->get_cart(), 'product_id'))) {
            // Add the free gift to the cart
            $cart->add_to_cart($free_gift_product_id, 1, 0, array(), array('free_gift' => true));

            // Display a custom notice (optional)
            wc_add_notice(__('Limited Time Offer! Free gift added to your cart.'), 'notice');

// Hook the function to the woocommerce_cart_calculate_fees action
add_action('woocommerce_cart_calculate_fees', 'ts_schedule_periodic_discount_with_free_gift', 10, 1);


If a customer places an order within the specified time frame set in the code (between the start and end dates), they will receive a complimentary gift along with their purchase that gets added to the cart items.

How to Set a Scheduled BOGO (Buy One Get One) Offer in WooCommerce? - Tyche Softwares

Similarly, you can also provide limited start and end-time offers. Check out this guide on how to add BOGO buy one get one offers with time limits in WooCommerce.

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

Share It:

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x