LLMS_Order::init( array|LLMS_Student|WP_User|integer $user_data, LLMS_Access_Plan $plan, LLMS_Payment_Gateway $gateway, LLMS_Coupon $coupon = false )
Initializes a new order with user, plan, gateway, and coupon metadata.
Description Description
Assumes all data passed in has already been validated.
Parameters Parameters
- $user_data
-
(array|LLMS_Student|WP_User|integer) (Required) User info for the person placing the order. See LLMS_Order::set_user_data() for more info.
- $plan
-
(LLMS_Access_Plan) (Required) The purchase access plan.
- $gateway
-
(LLMS_Payment_Gateway) (Required) Gateway being used.
- $coupon
-
(LLMS_Coupon) (Optional) Coupon object or
false
if no coupon used.Default value: false
Return Return
Source Source
File: includes/models/model.llms.order.php
$date = $this->get_next_payment_due_date(); return is_wp_error( $date ) ? false : true; } /** * Determine if the order has a trial * * @since 3.0.0 * * @return boolean True if has a trial, false if it doesn't. */ public function has_trial() { return ( $this->is_recurring() && 'yes' === $this->get( 'trial_offer' ) ); } /** * Determine if the trial period has ended for the order * * @since 3.0.0 * @since 3.10.0 Unknown. * * @return boolean True if ended, false if not ended. */ public function has_trial_ended() { return ( llms_current_time( 'timestamp' ) >= $this->get_trial_end_date( 'U' ) ); } /** * Initializes a new order with user, plan, gateway, and coupon metadata. * * Assumes all data passed in has already been validated. * * @since 3.8.0 * @since 3.10.0 Unknown. * @since 5.3.0 Don't set unused legacy property `date_billing_end`. * @since 7.0.0 Use `LLMS_Order::set_user_data()` to update user data. * * @param array|LLMS_Student|WP_User|integer $user_data User info for the person placing the order. See * {@see LLMS_Order::set_user_data()} for more info. * @param LLMS_Access_Plan $plan The purchase access plan. * @param LLMS_Payment_Gateway $gateway Gateway being used. * @param LLMS_Coupon $coupon Coupon object or `false` if no coupon used. * @return LLMS_Order */ public function init( $user_data, $plan, $gateway, $coupon = false ) { $this->set_user_data( $user_data ); // 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.
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
7.0.0 | Use LLMS_Order::set_user_data() to update user data. |
5.3.0 | Don't set unused legacy property date_billing_end . |
3.8.0 | |
3.10.0 | Introduced. |