LLMS_Order::init( LLMS_Student $person, LLMS_Access_Plan $plan, LLMS_Payment_Gateway $gateway, LLMS_Coupon $coupon = false )

Initialize a pending order


Description Description

Used during checkout. Assumes all data passed in has already been validated.


Top ↑

Parameters Parameters

$person

(LLMS_Student) (Required) The LLMS_Student placing the order.

$plan

(LLMS_Access_Plan) (Required) The purchase LLMS_Access_Plan.

$gateway

(LLMS_Payment_Gateway) (Required) The LLMS_Payment_Gateway used.

$coupon

(LLMS_Coupon) (Optional) LLMS_Coupon if a coupon was used or false.

Default value: false


Top ↑

Return Return

(LLMS_Order)


Top ↑

Source Source

File: includes/models/model.llms.order.php

	public function init( $person, $plan, $gateway, $coupon = false ) {

		// User related information.
		$this->set( 'user_id', $person->get_id() );
		$this->set( 'user_ip_address', llms_get_ip_address() );
		$this->set( 'billing_address_1', $person->get( 'billing_address_1' ) );
		$this->set( 'billing_address_2', $person->get( 'billing_address_2' ) );
		$this->set( 'billing_city', $person->get( 'billing_city' ) );
		$this->set( 'billing_country', $person->get( 'billing_country' ) );
		$this->set( 'billing_email', $person->get( 'user_email' ) );
		$this->set( 'billing_first_name', $person->get( 'first_name' ) );
		$this->set( 'billing_last_name', $person->get( 'last_name' ) );
		$this->set( 'billing_state', $person->get( 'billing_state' ) );
		$this->set( 'billing_zip', $person->get( 'billing_zip' ) );
		$this->set( 'billing_phone', $person->get( 'phone' ) );

		// Access plan data.
		$this->set( 'plan_id', $plan->get( 'id' ) );
		$this->set( 'plan_title', $plan->get( 'title' ) );
		$this->set( 'plan_sku', $plan->get( 'sku' ) );

		// Product data.
		$product = $plan->get_product();
		$this->set( 'product_id', $product->get( 'id' ) );
		$this->set( 'product_title', $product->get( 'title' ) );
		$this->set( 'product_sku', $product->get( 'sku' ) );
		$this->set( 'product_type', $plan->get_product_type() );

		$this->set( 'payment_gateway', $gateway->get_id() );
		$this->set( 'gateway_api_mode', $gateway->get_api_mode() );

		// Trial data.
		if ( $plan->has_trial() ) {
			$this->set( 'trial_offer', 'yes' );
			$this->set( 'trial_length', $plan->get( 'trial_length' ) );
			$this->set( 'trial_period', $plan->get( 'trial_period' ) );
			$trial_price = $plan->get_price( 'trial_price', array(), 'float' );
			$this->set( 'trial_original_total', $trial_price );
			$trial_total = $coupon ? $plan->get_price_with_coupon( 'trial_price', $coupon, array(), 'float' ) : $trial_price;
			$this->set( 'trial_total', $trial_total );
			$this->set( 'date_trial_end', $this->calculate_trial_end_date() );
		} else {
			$this->set( 'trial_offer', 'no' );
		}

		$price = $plan->get_price( 'price', array(), 'float' );
		$this->set( 'currency', get_lifterlms_currency() );

		// Price data.
		if ( $plan->is_on_sale() ) {
			$price_key = 'sale_price';
			$this->set( 'on_sale', 'yes' );
			$sale_price = $plan->get( 'sale_price', array(), 'float' );
			$this->set( 'sale_price', $sale_price );
			$this->set( 'sale_value', $price - $sale_price );
		} else {
			$price_key = 'price';
			$this->set( 'on_sale', 'no' );
		}

		// Store original total before any discounts.
		$this->set( 'original_total', $price );

		// Get the actual total due after discounts if any are applicable.
		$total = $coupon ? $plan->get_price_with_coupon( $price_key, $coupon, array(), 'float' ) : $$price_key;
		$this->set( 'total', $total );

		// Coupon data.
		if ( $coupon ) {
			$this->set( 'coupon_id', $coupon->get( 'id' ) );
			$this->set( 'coupon_amount', $coupon->get( 'coupon_amount' ) );
			$this->set( 'coupon_code', $coupon->get( 'title' ) );
			$this->set( 'coupon_type', $coupon->get( 'discount_type' ) );
			$this->set( 'coupon_used', 'yes' );
			$this->set( 'coupon_value', $$price_key - $total );
			if ( $plan->has_trial() && $coupon->has_trial_discount() ) {
				$this->set( 'coupon_amount_trial', $coupon->get( 'trial_amount' ) );
				$this->set( 'coupon_value_trial', $trial_price - $trial_total );
			}
		} else {
			$this->set( 'coupon_used', 'no' );
		}

		// Get all billing schedule related information.
		$this->set( 'billing_frequency', $plan->get( 'frequency' ) );
		if ( $plan->is_recurring() ) {
			$this->set( 'billing_length', $plan->get( 'length' ) );
			$this->set( 'billing_period', $plan->get( 'period' ) );
			$this->set( 'order_type', 'recurring' );
			$this->set( 'date_next_payment', $this->calculate_next_payment_date() );
		} else {
			$this->set( 'order_type', 'single' );
		}

		$this->set( 'access_expiration', $plan->get( 'access_expiration' ) );

		// Get access related data so when payment is complete we can calculate the actual expiration date.
		if ( $plan->can_expire() ) {
			$this->set( 'access_expires', $plan->get( 'access_expires' ) );
			$this->set( 'access_length', $plan->get( 'access_length' ) );
			$this->set( 'access_period', $plan->get( 'access_period' ) );
		}

		do_action( 'lifterlms_new_pending_order', $this, $person );

		return $this;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.3.0 Don't set unused legacy property date_billing_end.
3.8.0
3.10.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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