WC_Helper::fetch_helper_connection_infopublic staticWC 1.0

Get details of the current WooCommerce.com connection.

Method of the class: WC_Helper{}

No Hooks.

Returns

Array|WP_Error.

Usage

$result = WC_Helper::fetch_helper_connection_info();

WC_Helper::fetch_helper_connection_info() code WC 10.3.3

public static function fetch_helper_connection_info() {
	$data = self::get_cached_connection_data();
	if ( false !== $data ) {
		return $data;
	}

	$request = WC_Helper_API::get(
		'connection-info',
		array(
			'authenticated' => true,
			'query_string'  => '?url=' . rawurlencode( home_url() ),
		)
	);

	$status = wp_remote_retrieve_response_code( $request );
	if ( 200 !== $status ) {
		return new WP_Error(
			'invalid_response',
			'Invalid response from WooCommerce.com',
			array( 'status' => $status )
		);
	}

	$connection_data = json_decode( wp_remote_retrieve_body( $request ), true );

	$url = $connection_data['url'] ?? '';

	if ( ! empty( $url ) ) {
		$auth        = WC_Helper_Options::get( 'auth' );
		$auth['url'] = $url;
		WC_Helper_Options::update( 'auth', $auth );
		set_transient( self::CACHE_KEY_CONNECTION_DATA, $connection_data, 1 * HOUR_IN_SECONDS );
	}

	return $connection_data;
}