Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::get_response()publicWC 1.0

Get the route response based on the type of request.

Метод класса: Checkout{}

Хуков нет.

Возвращает

\WP_REST_Response.

Использование

$Checkout = new Checkout();
$Checkout->get_response( $request );
$request(\WP_REST_Request) (обязательный)
Request object.

Код Checkout::get_response() WC 8.7.0

public function get_response( \WP_REST_Request $request ) {
	$this->load_cart_session( $request );
	$this->cart_controller->calculate_totals();

	$response    = null;
	$nonce_check = $this->requires_nonce( $request ) ? $this->check_nonce( $request ) : null;

	if ( is_wp_error( $nonce_check ) ) {
		$response = $nonce_check;
	}

	if ( ! $response ) {
		try {
			$response = $this->get_response_by_request_method( $request );
		} catch ( InvalidCartException $error ) {
			$response = $this->get_route_error_response_from_object( $error->getError(), $error->getCode(), $error->getAdditionalData() );
		} catch ( RouteException $error ) {
			$response = $this->get_route_error_response( $error->getErrorCode(), $error->getMessage(), $error->getCode(), $error->getAdditionalData() );
		} catch ( \Exception $error ) {
			$response = $this->get_route_error_response( 'woocommerce_rest_unknown_server_error', $error->getMessage(), 500 );
		}
	}

	if ( is_wp_error( $response ) ) {
		$response = $this->error_to_response( $response );
	}

	return $this->add_response_headers( $response );
}