Skip to content

Instantly share code, notes, and snippets.

@codezz
Created November 15, 2021 20:02
Show Gist options
  • Select an option

  • Save codezz/36714e0c03b9ddd2818fadd12c4b4608 to your computer and use it in GitHub Desktop.

Select an option

Save codezz/36714e0c03b9ddd2818fadd12c4b4608 to your computer and use it in GitHub Desktop.
Woocommerce mandatory coupon
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