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


Description Description


Parameters Parameters

$format

(string) (Optional) return format

Default value: 'Y-m-d H:i:s'


Top ↑

Return Return

(string)


Top ↑

Source Source

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

	private function calculate_next_payment_date( $format = 'Y-m-d H:i:s' ) {

		$start_time = $this->get_date( 'date', 'U' );
		$end_time = $this->get_date( 'date_billing_end', 'U' );
		if ( ! $end_time && $this->get( 'billing_length' ) ) {
			$end_time = $this->calculate_billing_end_date();
			$this->set( 'date_billing_end', date_i18n( 'Y-m-d H:i:s', $end_time ) );
		}
		$next_payment_time = $this->get_date( 'date_next_payment', '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 {

			// assume we'll start from the order start date
			$from_time = $start_time;

			if ( $next_payment_time && $next_payment_time < llms_current_time( 'timestamp' ) ) {
				// if we have a saved next payment that's old we can calculate from there

				$from_time = $next_payment_time;

			} else {

				// check previous transactions and get the date from there
				// this will be true of orders created prior to 3.10 when no payment dates were saved
				$last_txn = $this->get_last_transaction( array( 'llms-txn-succeeded', 'llms-txn-refunded' ), 'recurring' );
				$last_txn_time = $last_txn ? $last_txn->get_date( 'date', 'U' ) : 0;
				if ( $last_txn_time && $last_txn_time < llms_current_time( 'timestamp' ) ) {
					$from_time = $last_txn_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
			// thanks WooCommerce Subscriptions <3
			$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++;
			}
		}// End if().

		// if the next payment is after the end time (where applicable)
		if ( 0 != $end_time && ( $next_payment_time + 23 * HOUR_IN_SECONDS ) > $end_time ) {
			$ret = '';
		} elseif ( $next_payment_time > 0 ) {
			$ret = date_i18n( $format, $next_payment_time );
		}

		return apply_filters( 'llms_order_calculate_next_payment_date', $ret, $format, $this );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.10.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: