Search code examples
phpwordpresswoocommercecoupon

Woocommerce check if coupon already applied?


So on the checkout page, how can i tell if a coupon has previously been applied from the cart page? I can check this condition via jquery but the doesnt function how i want because that doesnt happen until the DOM has already loaded. I want the form-checkout.php page to check for the coupon before its sent to the user, so i can either hide or show <p class="woocommerce-info">Have a coupon? <a href="#" class="showcoupon">Click here to enter your code</a></p>


Solution

  • Try this code. This will hide 'Coupon form' on checkout page, if any coupon is already applied from cart

    add_filter( 'woocommerce_coupons_enabled', 'woocommerce_coupons_enabled_checkout' );
    
    function woocommerce_coupons_enabled_checkout( $coupons_enabled ) {
        global $woocommerce;
        if ( ! empty( $woocommerce->cart->applied_coupons ) ) {
            return false;
        }
        return $coupons_enabled;
    }
    

    Hope this will be helpful