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.
Return
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 9.7.1
protected function validate_coupon_exists( $coupon ) { if ( ( ! $coupon->get_id() && ! $coupon->get_virtual() ) || 'trash' === $coupon->get_status() ) { /* translators: %s: coupon code */ throw new Exception( sprintf( __( 'Coupon "%s" does not exist!', 'woocommerce' ), esc_html( $coupon->get_code() ) ), 105 ); } return true; }