Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::prepare_item_for_response()publicWC 1.0

Prepare a single item for response. Handles setting the status based on the payment result.

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

Хуков нет.

Возвращает

\WP_REST_Response. $response Response data.

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

$Checkout = new Checkout();
$Checkout->prepare_item_for_response( $item, $request );
$item(разное) (обязательный)
Item to format to schema.
$request(\WP_REST_Request) (обязательный)
Request object.

Код Checkout::prepare_item_for_response() WC 6.8.0

public function prepare_item_for_response( $item, \WP_REST_Request $request ) {
	$response     = parent::prepare_item_for_response( $item, $request );
	$status_codes = [
		'success' => 200,
		'pending' => 202,
		'failure' => 400,
		'error'   => 500,
	];

	if ( isset( $item->payment_result ) && $item->payment_result instanceof PaymentResult ) {
		$response->set_status( $status_codes[ $item->payment_result->status ] ?? 200 );
	}

	return $response;
}