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?

You’ve probably seen Buy One Get One (BOGO) deals often used for physical products online. However, when it comes to digital products, discounts are usually the norm. But what if you could apply BOGO deals specifically to downloadable products in WooCommerce? This approach not only adds excitement for customers but also has the potential to increase the sales of downloadable products significantly.

Solution: Add BOGO (Buy One Get One)offer for Downloadable Products in WooCommerce

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);
        }
    }
}

    
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

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.

BOGO (Buy One Get One)offer for Downloadable Products

Similarly, you can also implement such product based Buy One Get One Offers and on different conditions such as 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
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x