Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::add_data_to_error_object()privateWC 1.0

Adds additional data to the \WP_Error object.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->add_data_to_error_object( $error, $data, $http_status_code, $include_cart );
$error(\WP_Error) (обязательный)
The error object to add the cart to.
$data(массив) (обязательный)
The data to add to the error object.
$http_status_code(int) (обязательный)
The HTTP status code this error should return.
$include_cart(true|false)
Whether the cart should be included in the error data.
По умолчанию: false

Код Checkout::add_data_to_error_object() WC 8.7.0

private function add_data_to_error_object( $error, $data, $http_status_code, bool $include_cart = false ) {
	$data = array_merge( $data, [ 'status' => $http_status_code ] );
	if ( $include_cart ) {
		$data = array_merge( $data, [ 'cart' => wc()->api->get_endpoint_data( '/wc/store/v1/cart' ) ] );
	}
	$error->add_data( $data );
	return $error;
}