Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Order::calculate_next_payment_date( string $format = 'Y-m-d H:i:s' )
Calculate the next payment due date
Parameters Parameters
- $format
-
(string) (Optional) PHP date format used to format the returned date string.
Default value: 'Y-m-d H:i:s'
Return Return
(string) The formatted next payment due date or an empty string when there is no next payment.
Source Source
File: includes/models/model.llms.order.php
private function calculate_next_payment_date( $format = 'Y-m-d H:i:s' ) { // If the limited plan has already ended return early. $remaining = $this->get_remaining_payments(); if ( 0 === $remaining ) { // This filter is documented below. return apply_filters( 'llms_order_calculate_next_payment_date', '', $format, $this ); } $start_time = $this->get_date( 'date', 'U' ); $next_payment_time = $this->get_date( 'date_next_payment', 'U' ); $last_txn_time = $this->get_last_transaction_date( 'llms-txn-succeeded', 'recurring', 'U' ); // If were on a trial and the trial hasn't ended yet next payment date is the date the trial ends. if ( $this->has_trial() && ! $this->has_trial_ended() ) { $next_payment_time = $this->get_trial_end_date( 'U' ); } else { /** * Calculate next payment date from the saved `date_next_payment` calculated during * the previous recurring transaction or during order initialization. * * This condition will be encountered during the 2nd, 3rd, 4th, etc... recurring payments. */ if ( $next_payment_time && $next_payment_time < llms_current_time( 'timestamp' ) ) { $from_time = $next_payment_time; /** * Use the order's last successful transaction date. * * This will be encountered when any amount of "chaos" is * introduced causing the previously stored `date_next_payment` * to be GREATER than the current time. * * Orders created */ } elseif ( $last_txn_time && $last_txn_time > $start_time ) { $from_time = $last_txn_time; /** * Use the order's creation time. * * This condition will be encountered for the 1st recurring payment only. */ } else { $from_time = $start_time; } $period = $this->get( 'billing_period' ); $frequency = $this->get( 'billing_frequency' ); $next_payment_time = strtotime( '+' . $frequency . ' ' . $period, $from_time ); /** * Make sure the next payment is more than 2 hours in the future * * This ensures changes to the site's timezone because of daylight savings * will never cause a 2nd renewal payment to be processed on the same day. */ $i = 1; while ( $next_payment_time < ( llms_current_time( 'timestamp', true ) + 2 * HOUR_IN_SECONDS ) && $i < 3000 ) { $next_payment_time = strtotime( '+' . $frequency . ' ' . $period, $next_payment_time ); $i++; } } /** * Filter the calculated next payment date * * @since 3.10.0 * * @param string $ret The formatted next payment due date or an empty string when there is no next payment. * @param string $format The requested date format. * @param LLMS_Order $order The order object. */ return apply_filters( 'llms_order_calculate_next_payment_date', date( $format, $next_payment_time ), $format, $this ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.3.0 | Determine if a limited order has ended based on number of remaining payments in favor of current date/time. |
4.9.0 | Fix comparison for PHP8 compat. |
3.37.6 | Now uses the last successful transaction time to calculate from when the previously stored next payment date is in the future. |
3.12.0 | Unknown. |
3.10.0 | Introduced. |