Created
November 15, 2021 20:02
-
-
Save codezz/36714e0c03b9ddd2818fadd12c4b4608 to your computer and use it in GitHub Desktop.
Woocommerce mandatory coupon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mandatory_coupon_code() { | |
| $applied_coupons = WC()->cart->get_applied_coupons(); | |
| if ( empty ( $applied_coupons ) ) { | |
| // Not found: display an error notice | |
| wc_add_notice( __( 'Add coupon before checkout.', 'woocommerce' ), 'error' ); | |
| } | |
| } | |
| add_action( 'woocommerce_check_cart_items', 'mandatory_coupon_code', 10, 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment