Add your own restriction check
Updated September 15, 2026
You can add your own rule to Better Coupon Restrictions by adding a function to the bcrw_validation_checks filter. Your check runs alongside the built-in ones, and its rejections show in the shop manager hint and in rejection analytics.
How checks work
Each check is a callable that receives the coupon and the cart:
WC_Coupon $coupon: the coupon being validated.WC_Cart $cart: the current cart. Checks only run when a cart exists.
If the rule passes, return nothing. If it fails, call bcrw_fail( $message, $coupon, $section, $value ). It throws an exception that WooCommerce turns into the coupon error, and the remaining checks are skipped.
Example: block a coupon for gift cards
This PHP snippet adds a check that rejects coupons with a _mysite_no_gift_cards meta value of yes when the cart contains a product from the gift-cards category.
add_filter( 'bcrw_validation_checks', function ( $checks ) {
$checks[] = 'mysite_check_no_gift_cards';
return $checks;
} );
add_filter( 'bcrw_validation_check_labels', function ( $labels ) {
$labels['mysite_check_no_gift_cards'] = 'No Gift Cards';
return $labels;
} );
function mysite_check_no_gift_cards( $coupon, $cart ) {
if ( 'yes' !== get_post_meta( $coupon->get_id(), '_mysite_no_gift_cards', true ) ) {
return;
}
foreach ( $cart->get_cart() as $item ) {
if ( has_term( 'gift-cards', 'product_cat', $item['product_id'] ) ) {
bcrw_fail(
__( 'This coupon cannot be used on gift cards.', 'mysite' ),
$coupon,
'cart'
);
}
}
}
Tips
- Use a named function, not a closure. The function name is what appears in analytics and in the admin hint. Closures are labelled “Custom check”.
- Add a label with
bcrw_validation_check_labels, otherwise the name is built from the function name. - Custom messages: the third argument of
bcrw_fail()is a section key. Passing an existing section such ascartmeans that section’s Custom Error Message replaces your default, with{value}swapped for the fourth argument. Adding a new key withbcrw_message_sectionsdoes not add a field to the coupon screen or save one, so you would need to handle that yourself. - Read saved values with
bcrw_get_restriction( $coupon, $meta_key, $default )so global overrides apply. - Cache lookups within the page load with
bcrw_remember( $key, $callback ), as WooCommerce validates coupons several times per request. - Customer details:
bcrw_get_customer_email( $cart )returns the billing or account email, or an empty string when unknown. Return early when it is empty so guests can be re-checked at checkout. - Order: checks run in array order. Prepend to run before the built-in checks.


