LLMS_Coupon::is_valid( int $plan_id )
Perform all available validations and return a success or error message
Parameters Parameters
- $plan_id
-
(int) (Required) WP Post ID of an LLMS Access Plan
Return Return
(WP_Error|true) If true, the coupon is valid, if WP_Error, there was an error
Source Source
File: includes/models/model.llms.coupon.php
public function is_valid( $plan_id ) { $msg = false; $plan = new LLMS_Access_Plan( $plan_id ); if ( ! $this->has_remaining_uses() ) { $msg = __( 'This coupon has reached its usage limit and can no longer be used.', 'lifterlms' ); } elseif ( $this->is_expired() ) { $msg = sprintf( __( 'This coupon expired on %s and can no longer be used.', 'lifterlms' ), $this->get_date( 'expiration_date', 'F d, Y' ) ); } elseif ( ! $this->applies_to_product( $plan->get( 'product_id' ) ) ) { $msg = sprintf( __( 'This coupon cannot be used to purchase "%s".', 'lifterlms' ), get_the_title( $plan->get( 'product_id' ) ) ); } elseif ( ! $this->applies_to_plan( $plan ) ) { $msg = sprintf( __( 'This coupon cannot be used to purchase "%s".', 'lifterlms' ), $plan->get( 'title' ) ); } // Error encountered. if ( $msg ) { $ret = new WP_Error(); $ret->add( 'error', apply_filters( 'lifterlms_coupon_validation_error_message', $msg, $this ) ); } else { $ret = true; } return apply_filters( 'llms_coupon_is_valid', $ret, $plan, $this ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |