WC_Discounts::validate_coupon_exists
Ensure coupon exists or throw exception.
A coupon is also considered to no longer exist if it has been placed in the trash, even if the trash has not yet been emptied.
Method of the class: WC_Discounts{}
No Hooks.
Returns
true|false.
Usage
// protected - for code of main (parent) or child class $result = $this->validate_coupon_exists( $coupon );
- $coupon(WC_Coupon) (required)
- Coupon data.
Changelog
| Since 3.2.0 | Introduced. |
WC_Discounts::validate_coupon_exists() WC Discounts::validate coupon exists code WC 10.6.2
protected function validate_coupon_exists( $coupon ) {
if ( ( ! $coupon->get_id() && ! $coupon->get_virtual() ) || 'trash' === $coupon->get_status() ) {
throw new Exception(
sprintf(
/* translators: %s: coupon code */
esc_html__( 'Coupon "%s" cannot be applied because it does not exist.', 'woocommerce' ),
esc_html( $coupon->get_code() )
),
105
);
}
return true;
}