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.

Метод класса: WC_Helper_Updater{}

Хуков нет.

Возвращает

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

Использование

$result = WC_Helper_Updater::get_renewable_subscriptions( $subscriptions ): array;
$subscriptions(массив) (обязательный)
Every subscription the account holds for the product.

Список изменений

С версии 11.2.0 Введена.

Код WC_Helper_Updater::get_renewable_subscriptions() WC 11.2.1

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 ) );
}