mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/63917178/force-coupon-code-before-checkout-in-woocommerce/63917994
9 lines
355 B
Text
9 lines
355 B
Text
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 );
|