WC_REST_WCCOM_Site_SSR_Controller::handle_ssr_request()publicWC 7.8.0

Generate SSR data and submit it to WooCommerce.com.

Method of the class: WC_REST_WCCOM_Site_SSR_Controller{}

No Hooks.

Return

WP_REST_Response.

Usage

$WC_REST_WCCOM_Site_SSR_Controller = new WC_REST_WCCOM_Site_SSR_Controller();
$WC_REST_WCCOM_Site_SSR_Controller->handle_ssr_request( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 7.8.0 Introduced.

WC_REST_WCCOM_Site_SSR_Controller::handle_ssr_request() code WC 9.4.2

public function handle_ssr_request( $request ) {
	$ssr_controller = new WC_REST_System_Status_Controller();
	$data           = $ssr_controller->get_items( $request );
	$data           = $data->get_data();

	// Submit SSR data to WooCommerce.com.
	$request = WC_Helper_API::post(
		'ssr',
		array(
			'body'          => wp_json_encode( array( 'data' => $data ) ),
			'authenticated' => true,
		)
	);

	$response_code = wp_remote_retrieve_response_code( $request );

	if ( 201 === $response_code ) {
		$response = rest_ensure_response(
			array(
				'success' => true,
				'message' => 'SSR data submitted successfully',
			)
		);
	} else {
		$response = rest_ensure_response(
			array(
				'success'       => false,
				'error_code'    => 'failed_submitting_ssr',
				'error_message' => "Submitting SSR data failed with response code: $response_code",
			)
		);
	}

	return $response;
}