LLMS_Voucher::check_voucher( string $code )
Determine if a voucher is valid
Parameters Parameters
- $code
-
(string) (Required) Voucher code.
Return Return
(WP_Error|object) WP_Error if invalid or not redeemable OR a voucher data object.
Source Source
File: includes/class.llms.voucher.php
public function check_voucher( $code ) { $voucher = $this->get_voucher_by_code( $code ); if ( empty( $voucher ) ) { return new WP_Error( 'not-found', sprintf( __( 'Voucher code "%s" could not be found.', 'lifterlms' ), $code ) ); } elseif ( $voucher->redemption_count <= $voucher->used ) { return new WP_Error( 'max', sprintf( __( 'Voucher code "%s" has already been redeemed the maximum number of times.', 'lifterlms' ), $code ) ); } elseif ( '1' === $voucher->is_deleted || 'publish' !== get_post_status( $voucher->voucher_id ) ) { // @todo because get_voucher_code() adds `is_deleted=0` we should never get here, I think. return new WP_Error( 'deleted', sprintf( __( 'Voucher code "%s" is no longer valid.', 'lifterlms' ), $code ) ); } return $voucher; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.37.17 | Ensure the code's parent post is published. |
3.0.0 | Unknown. |
2.0.0 | Introduced. |