Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::add_data_to_error_object()privateWC 1.0

Adds additional data to the \WP_Error object.

Method of the class: Checkout{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->add_data_to_error_object( $error, $data, $http_status_code, $include_cart );
$error(\WP_Error) (required)
The error object to add the cart to.
$data(array) (required)
The data to add to the error object.
$http_status_code(int) (required)
The HTTP status code this error should return.
$include_cart(true|false)
Whether the cart should be included in the error data.
Default: false

Checkout::add_data_to_error_object() code 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;
}