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
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 | $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. |