WC_Helper::get_subscriptions()
Get the connected user's subscriptions.
Method of the class: WC_Helper{}
No Hooks.
Return
Array
.
Usage
$result = WC_Helper::get_subscriptions();
WC_Helper::get_subscriptions() WC Helper::get subscriptions code WC 9.2.3
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 ( stripos( $request_uri, 'installer' ) ) : $source = 'wccom-site-installer'; 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; }