LLMS_Order::init( obj $person, obj $plan, obj $gateway, mixed $coupon = false )
Initialize a pending order Used during checkout Assumes all data passed in has already been validated
Description Description
Parameters Parameters
- $person
-
(obj) (Required) LLMS_Student
- $plan
-
(obj) (Required) LLMS_Access_Plan
- $gateway
-
(obj) (Required) LLMS_Gateway
- $coupon
-
(mixed) (Optional) LLMS_Coupon or false
Default value: false
Return Return
(obj) $this
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' ); if ( $plan->get( 'length' ) ) { $this->set( 'date_billing_end', date_i18n( 'Y-m-d H:i:s', $this->calculate_billing_end_date() ) ); } $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; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.8.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: