I added this code on a page I am building:
<div class="coupon">
<?php if( !WC()->cart->get_coupons() ) {
?>
<form class="checkout_coupon woocommerce-form-coupon" method="post">
<p style="color:white;"><?php esc_html_e( 'Kortingscode', 'woocommerce' ); ?></p>
<p class="form-row form-row-first">
<input type="text" name="coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="coupon_code" value="" />
</p>
<p class="form-row form-row-last">
<button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?></button>
</p>
<div class="clear"></div>
</form><?php
}
?>
<?php if( !WC()->cart->get_coupons() ) { ?>
<p class="wrong-code">Wrong coupon entered</p>
<?php } ?>
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
<p>Active coupon: <?php echo esc_attr( sanitize_title( $code ) ); ?></p>
<p><?php wc_cart_totals_coupon_html( $coupon ); ?></p>
<?php endforeach; ?>
</div>
Now the text 'Wrong coupon entered' is shown from the beginning before there is any coupon submitted. Only if a right coupon is submitted it doesn't show up. I want to add another rule to it which also checks for the last submitted code if it is valid or not so the wrong coupon text only shows up when the customer submitted a coupon AND it is invalid.