LLMS_Order::maybe_schedule_payment( $recalc = true )

Schedules the next payment due on a recurring order


Description Description

Can be called without consequence on a single payment order. Will always unschedule the scheduled action (if one exists) before scheduling another.


Top ↑

Return Return

(void)


Top ↑

Source Source

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

	public function maybe_schedule_payment( $recalc = true ) {

		if ( ! $this->is_recurring() ) {
			return;
		}

		if ( $recalc ) {
			$this->set( 'date_next_payment', $this->calculate_next_payment_date() );
		}

		$date = $this->get_next_payment_due_date();

		// Unschedule and reschedule.
		if ( $date && ! is_wp_error( $date ) ) {

			$this->schedule_recurring_payment( $date );

		} elseif ( is_wp_error( $date ) ) {

			if ( 'plan-ended' === $date->get_error_code() ) {

				// Unschedule the next action (does nothing if no action scheduled).
				$this->unschedule_recurring_payment();

				// Add a note that the plan has completed.
				$this->add_note( __( 'Order payment plan completed.', 'lifterlms' ) );
				$this->set( 'plan_ended', 'yes' );

			}
		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.2.0 Move scheduling recurring payment into a proper method.
4.7.0 Add plan_ended metadata when a plan ends.
3.32.0 Update to use latest action-scheduler functions.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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