WC_Helper::fetch_helper_connection_info
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() WC Helper::fetch helper connection info code WC 10.8.1
public static function fetch_helper_connection_info() {
$data = self::get_cached_connection_data();
if ( false !== $data ) {
if ( ! empty( $data['maybe_deleted_connection'] ) ) {
return new WP_Error( 'deleted_connection', 'Connection may have been deleted' );
}
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 );
$body = json_decode( wp_remote_retrieve_body( $request ), true );
$connection_data = is_array( $body ) ? $body : array();
$message = $connection_data['message'] ?? '';
if ( 200 !== $status ) {
if ( 'Connected site not found.' === $message || 'Invalid access token' === $message ) {
set_transient( self::CACHE_KEY_CONNECTION_DATA, array( 'maybe_deleted_connection' => true ), 1 * HOUR_IN_SECONDS );
}
return new WP_Error(
'invalid_response',
'Invalid response from WooCommerce.com',
array( 'status' => $status )
);
}
$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;
}