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

	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.