LLMS_Order_Generator::validate_coupon()

Validates the coupon.


Return Return

(boolean|WP_Error) Returns true on success or an error object.


Top ↑

Source Source

File: includes/class-llms-order-generator.php

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
protected function validate_coupon() {
 
    // If a coupon is being used, validate it.
    if ( ! empty( $this->data['llms_coupon_code'] ) ) {
 
        $code = sanitize_text_field( $this->data['llms_coupon_code'] );
 
        // Locate the coupon post ID.
        $coupon_id = llms_find_coupon( $code );
        if ( ! $coupon_id ) {
            return $this->error(
                self::E_COUPON_NOT_FOUND,
                sprintf(
                    // Translators: %s = The user-submitted coupon code.
                    __( 'Coupon code "%s" not found.', 'lifterlms' ),
                    $code
                )
            );
        }
 
        // Validate the coupon for the current plan.
        $coupon = llms_get_post( $coupon_id );
        $valid  = $coupon->is_valid( $this->plan->get( 'id' ) );
        if ( is_wp_error( $valid ) ) {
            return $this->error( self::E_COUPON_INVALID, $valid->get_error_message() );
        }
 
        $this->coupon = $coupon;
 
    }
 
    return true;
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.