WC_Helper::get_subscriptions()public staticWC 1.0

Get the connected user's subscriptions.

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

Хуков нет.

Возвращает

Массив.

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

$result = WC_Helper::get_subscriptions();

Код WC_Helper::get_subscriptions() WC 8.7.0

public static function get_subscriptions() {
	$cache_key = '_woocommerce_helper_subscriptions';
	$data      = get_transient( $cache_key );
	if ( false !== $data ) {
		return $data;
	}

	$request_uri = wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
	$source      = '';
	if ( stripos( $request_uri, 'wc-addons' ) ) :
		$source = 'my-subscriptions';
	elseif ( stripos( $request_uri, 'plugins.php' ) ) :
		$source = 'plugins';
	elseif ( stripos( $request_uri, 'wc-admin' ) ) :
		$source = 'inbox-notes';
	elseif ( stripos( $request_uri, 'admin-ajax.php' ) ) :
		$source = 'heartbeat-api';
	elseif ( defined( 'WP_CLI' ) && WP_CLI ) :
		$source = 'wc-cli';
	endif;

	// Obtain the connected user info.
	$request = WC_Helper_API::get(
		'subscriptions',
		array(
			'authenticated' => true,
			'query_string'  => '' !== $source ? esc_url( '?source=' . $source ) : '',
		)
	);

	if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
		set_transient( $cache_key, array(), 15 * MINUTE_IN_SECONDS );
		return array();
	}

	$data = json_decode( wp_remote_retrieve_body( $request ), true );
	if ( empty( $data ) || ! is_array( $data ) ) {
		$data = array();
	}

	set_transient( $cache_key, $data, 1 * HOUR_IN_SECONDS );
	return $data;
}