Filter
rpress_is_discount_valid
On this page
Filters whether a discount code is valid at the time of purchase.
Runs at the end of RPRESS_Discount::is_valid(). The incoming value is true only when the cart is not empty and the discount is active, started, not maxed out, not used, and meets its product, category and minimum price requirements. Returning false rejects the code even if every built-in check passed.
Available since RestroPress 1.0.6.
Parameters#
| Parameter | Type | Description |
|---|---|---|
$return | bool | Whether the discount is valid. |
$ID | int | Discount ID. |
$code | string | Discount code. |
$user | string | User info (email address or user identifier) the check was run for. |
Return value#
bool. True if the discount is valid.
Example#
function my_discount_is_valid( $return, $discount_id, $code, $user ) {
// Only allow the WELCOME10 code on weekdays.
if ( 'WELCOME10' === strtoupper( $code ) && (int) gmdate( 'N' ) > 5 ) {
return false;
}
return $return;
}
add_filter( 'rpress_is_discount_valid', 'my_discount_is_valid', 10, 4 );
Notes#
The docblock describes the first parameter as the used state; in practice it is the validity result.
Source#
Applied in:
includes/class-rpress-discount.php(line 1793), inRPRESS_Discount::is_valid()
See also#
Was this page helpful?
