WC_Helper_Updater::get_renewable_subscriptions │ private static │ WC 11.2.0

Expired and lapsing subscriptions for a product that the merchant should act on.

Every subscription the account holds for the product counts, wherever it is connected, because renewing and buying can be done from any store. Nothing is returned while another subscription still covers the product, so a store that keeps its updates stays quiet.

Method of the class: WC_Helper_Updater{}

No Hooks.

Returns

array. A pair of subscriptions, each an array or false: the expired one, then the lapsing one without auto-renew.

Usage

$result = WC_Helper_Updater::get_renewable_subscriptions( $subscriptions ): array;
$subscriptions(array) (required)
Every subscription the account holds for the product.

Changelog

Since 11.2.0 Introduced.

WC_Helper_Updater::get_renewable_subscriptions() code WC 11.2.2

private static function get_renewable_subscriptions( array $subscriptions ): array {
	if ( empty( $subscriptions ) ) {
		return array( false, false );
	}

	// A lifetime subscription never lapses, so an expired flag on one is nothing to act on.
	$active = array_filter(
		$subscriptions,
		function ( $subscription ) {
			return empty( $subscription['expired'] ) || ! empty( $subscription['lifetime'] );
		}
	);

	// Nothing covers the product any more, so renewing is what restores updates.
	if ( empty( $active ) ) {
		return array( current( $subscriptions ), false );
	}

	$lapsing = array_filter(
		$active,
		function ( $subscription ) {
			return ! empty( $subscription['expiring'] ) && empty( $subscription['autorenew'] );
		}
	);

	// One subscription that outlives the others keeps the product covered.
	if ( count( $lapsing ) !== count( $active ) ) {
		return array( false, false );
	}

	return array( false, current( $lapsing ) );
}