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

How To Add BOGO (Buy One Get One)offer for Downloadable Products in WooCommerce?

BOGO offers especially for ‘downloadable’ product type in WooCommerce can encourage customers to explore and download more digital products as they get access to their digital products instantly. This code ensures that when a downloadable product is in the cart, a corresponding free downloadable product is added, simulating a BOGO offer.

add_action('woocommerce_cart_calculate_fees', 'ts_bogo_downloadable_products');

function ts_bogo_downloadable_products($cart) {
    if (is_admin() && !defined('DOING_AJAX')) {
        return;
    }

    // Check if the cart is empty
    if ($cart->is_empty()) {
        return;
    }

    // Initialize variables for the free downloadable product
    $free_downloadable_product_id = 671; // Replace with your free downloadable product ID

    // Check if the cart contains any downloadable product
    $downloadable_product_in_cart = false;
    foreach ($cart->get_cart() as $cart_item) {
        if ($cart_item['data']->is_downloadable()) {
            $downloadable_product_in_cart = true;
            break;
        }
    }

    // If any downloadable product is in the cart, add the free downloadable product
    if ($downloadable_product_in_cart) {
        // Check if the free product is not already in the cart
        $free_product_in_cart = false;
        foreach ($cart->get_cart() as $cart_item) {
            if ($cart_item['product_id'] == $free_downloadable_product_id && $cart_item['data']->is_downloadable()) {
                $free_product_in_cart = true;
                break;
            }
        }

        // If the free product is not in the cart, add it
        if (!$free_product_in_cart) {
            $cart->add_to_cart($free_downloadable_product_id, 1);
        }
    }
}

    

Output

The output represents that whenever a customer adds a ‘downloadable’ product type, the specific free product specified in the code gets automatically added to the cart.

Adding Buy One Get One offer for WooCommerce Downloadable Products

Similarly, you can also provide Buy One Get One Offers based on product categories. Refer to our post that guides you well to automatically add a free product to your WooCommerce cart based on 6 different conditions.

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