Automattic\WooCommerce\StoreApi\Routes\V1

Patterns::get_route_response()protectedWC 1.0

Fetch a single pattern from the PTK to ensure the API is available.

Method of the class: Patterns{}

No Hooks.

Return

WP_Error|\WP_HTTP_Response|WP_REST_Response.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_route_response( $request );
$request(WP_REST_Request) (required)
Request object.

Patterns::get_route_response() code WC 9.3.1

protected function get_route_response( WP_REST_Request $request ) {
	$ptk_client = Package::container()->get( PTKClient::class );

	$response = $ptk_client->fetch_patterns(
		array(
			'per_page' => 1,
		)
	);

	if ( is_wp_error( $response ) ) {
		throw new RouteException(
			wp_kses( $response->get_error_message(), array() ),
			wp_kses( $response->get_error_code(), array() )
		);
	}

	return rest_ensure_response(
		array(
			'success' => true,
		)
	);
}