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

How to Disable Coupon Field When a BOGO (Buy One Get One) Offer is Applied in WooCommerce?

When you have special deals like Buy One Get One (BOGO) in your WooCommerce store, it’s a smart move to disable coupons. The key to a successful BOGO promotion lies in it’s clarity and value. By disabling coupon field, you ensure that the BOGO deal stands out as the main attraction, making it easier for customers to focus only on the BOGO offer and motivating them to complete their purchases.

Solution: Disable Coupon Field When a BOGO (Buy One Get One) Offer is Applied in WooCommerce

The code snippet helps you to disable the coupon field on both the cart and checkout pages when you’re running specific BOGO promotions.

add_action('wp_loaded', 'ts_bogo_offer');

function ts_bogo_offer() {
    // Check if WooCommerce is active
    if (class_exists('WooCommerce') && is_object(WC()->cart)) {
        // Define the product IDs for comparison
        $product_gifted_id = 470;

        // Check if any product is in the cart
        $product_in_cart = false;

        foreach (WC()->cart->get_cart() as $cart_item) {
            if ($cart_item['product_id']) {
                $product_in_cart = true;
                break;
            }
        }

        // see if gift id in cart
        $product_gifted_cart_id = WC()->cart->generate_cart_id($product_gifted_id);
        $product_gifted_in_cart = WC()->cart->find_product_in_cart($product_gifted_cart_id);

        // if no product in cart, remove gift; else, add gift
        if (!$product_in_cart) {
            if ($product_gifted_in_cart) {
                WC()->cart->remove_cart_item($product_gifted_in_cart);
            }
        } else {
            if (!$product_gifted_in_cart) {
                WC()->cart->add_to_cart($product_gifted_id);
            }
        }
    }
}

function ts_disable_coupon_field($enabled) {
    if (is_cart() || is_checkout()) {
        $enabled = false;
    }
    return $enabled;
}
add_filter('woocommerce_coupons_enabled', 'ts_disable_coupon_field');
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

When a customer adds any product to the cart, a complimentary item is automatically included, and the code will also hide the coupon field to prevent customers from applying additional coupons.

Disable Coupon Field When a BOGO (Buy One Get One) Offer is Applied

The coupon field is also removed from the checkout page which will help to prevent customers from applying a coupon during the checkout process.

How to Disable Coupon Field When a BOGO (Buy One Get One) Offer is Applied in WooCommerce? - Tyche Softwares

Let’s examine how the cart and checkout pages, with coupon fields, appeared before applying the code

How to Disable Coupon Field When a BOGO (Buy One Get One) Offer is Applied in WooCommerce? - Tyche Softwares

This is how the coupon field appears on the checkout page before implementing the code.

How to Disable Coupon Field When a BOGO (Buy One Get One) Offer is Applied in WooCommerce? - Tyche Softwares

Let’s also look into the alternative approach where you can tie BOGO offers to coupons such as to add a bogo buy one get one offer with a coupon code for orders over 100 in WooCommerce. This approach will let you have control over discounts but still offering great value to customers, keeping them satisfied.

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