Question

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>

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top