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

How to Set Up a BOGO Deal: Spend X More and Get a Free Product Based on Cart Amount in WooCommerce?

This WooCommerce snippet allows you to set up a Spend X More to Get a Free Product promotion based on the cart total. In simple terms, it means, “Spend X more to unlock a free gift.” By creating a sense of urgency and excitement, this discount strategy effectively motivates customers to increase their cart value to receive a free product

Solution: Set Up a BOGO Deal: Spend X More and Get a Free Product

The code will automatically add a free product to the cart when a customer’s cart total spending reaches a specified amount. Additionally, it shows a message to encourage customers to spend a bit more to get the free item.

add_action('woocommerce_before_cart', 'ts_add_notice_and_free_product');

function ts_add_notice_and_free_product() {
    // Set the minimum amount for the free product
    $min_amount_for_free_product = 50; // Adjust this to your desired minimum amount
    $free_product_id = 470; // Replace with the actual product ID of the free product

    $cart_subtotal = WC()->cart->subtotal; // Use subtotal
    $remaining_amount = $min_amount_for_free_product - $cart_subtotal;

    // Set a threshold for displaying the notice 
    $notice_threshold = $min_amount_for_free_product - 5;

    // If the cart subtotal is within the threshold, display the specific notice
    if ($cart_subtotal >= $notice_threshold && $cart_subtotal < $min_amount_for_free_product && $remaining_amount > 0) {
        $notice = sprintf("Spend %s more to get a free product!", wc_price($remaining_amount));
    } elseif ($remaining_amount <= 0) {
        // If the threshold is reached, add the free product to the cart
        $product_to_add = wc_get_product($free_product_id);

        if ($product_to_add) {
            WC()->cart->add_to_cart($free_product_id);
            $added_notice = sprintf("Congratulations! You've earned a free %s. It has been added to your cart.", $product_to_add->get_name());
            wc_print_notice($added_notice, 'success');
        }
    }

    // Display the notice, if it is not empty
    if (!empty($notice)) {
        wc_print_notice($notice, 'notice');
    }
}

Output

If the customer’s cart total falls below the specified minimum amount ($50) required for the free product, and the cart total is close to the threshold amount ($5), the notice will be triggered, prompting the message ‘Spend $5 more to receive a free product.’

How to Set Up a BOGO Deal: Spend X More and Get a Free Product Based on Cart Amount in WooCommerce? - Tyche Softwares

When the customer’s cart subtotal has reached the specified minimum amount for free gift, then the free gift will be automatically added to the cart as shown below.

How to Set Up a BOGO Deal: Spend X More and Get a Free Product Based on Cart Amount in WooCommerce? - Tyche Softwares

Similarly, you can take this strategy a step further by offering a “Spend $X to unlock free shipping in WooCommerce” as this encourages customers to spend a bit more to benefit from free shipping.

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