LLMS_Meta_Box_Order_Details::save_remaining_payments( LLMS_Order $order )

Save remaining payment date for expiring recurring orders


Parameters Parameters

$order

(LLMS_Order) (Required) Order object


Top ↑

Return Return

(int) Returns -1 when there's for invalid order types, 0 when there's no changes to save, and 1 when remaining payment data is updated.


Top ↑

Source Source

File: includes/admin/post-types/meta-boxes/class.llms.meta.box.order.details.php

	protected function save_remaining_payments( $order ) {

		// If it's not a payment plan or cannot modify recurring payment, don't proceed.
		if ( ! $order->has_plan_expiration() || ! $order->supports_modify_recurring_payments() ) {
			return -1;
		}

		$payments  = (int) llms_filter_input( INPUT_POST, '_llms_remaining_payments', FILTER_SANITIZE_NUMBER_INT );
		$remaining = $order->get_remaining_payments();

		// Nothing to save.
		if ( $payments < 1 || $payments === $remaining ) {
			return 0;
		}

		// Determine how to adjust the billing length.
		$adjustment = $payments - $remaining;
		$original   = $order->get( 'billing_length' );
		$new_length = max( $order->get( 'billing_length' ) + $adjustment, 1 );
		$period     = $order->get( 'billing_period' );

		// Update the payment plan.
		$order->set( 'billing_length', $new_length );

		// Record that the payment plan has been modified.
		$order->add_note(
			sprintf(
				// Translators: %1$d is the original billing length; %2$s is the billing period (adjusted for pluralization against the original billing length); %3$d is the new billing length; %4$s is the billing period (adjusted for pluralization against the new billing length).
				__( 'The billing length of the order has been modified from %1$d %2$s to %3$d %4$s.', 'lifterlms' ),
				$original,
				llms_get_time_period_l10n( $period, $original ),
				$new_length,
				llms_get_time_period_l10n( $period, $new_length )
			)
		);

		// Store a use note if one was entered.
		$note = llms_filter_input_sanitize_string( INPUT_POST, '_llms_remaining_note' );
		if ( $note ) {
			$order->add_note( wp_strip_all_tags( $note ), true );
		}

		// Restart scheduled payments.
		if ( ! $order->has_scheduled_payment() ) {
			$order->maybe_schedule_payment();
		}

		return 1;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Return -1 if the recurring payment cannot be modified (the gateway doesn't support this feature).
5.9.0 Stop using deprecated FILTER_SANITIZE_STRING.
5.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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