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

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

Setting a promotion for a limited time or a seasonal sale creates a sense of urgency, encouraging customers to act quickly to take advantage of the “Buy One Get One” offer. For example, if you run this WooCommerce promotion during the week leading up to Christmas, it can significantly boost your sales. Customers will appreciate the extra value they receive during the holiday season, enhancing their overall shopping experience.

Solution: Set a Scheduled BOGO (Buy One Get One) Offer in WooCommerce

The code checks the order date against the defined start and end date, and if the order falls within the specified date 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_clear_notices();
            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);

Output

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

Don’t limit your promotions to just specific dates! Instead, take advantage of time-sensitive offers and add BOGO buy one get one offers based on time limits in WooCommerce.

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

Share It:

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