Automattic\WooCommerce\StoreApi\Schemas\V1

CartSchema::get_cart_errors()protectedWC 1.0

Get cart validation errors.

Method of the class: CartSchema{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_cart_errors( $cart );
$cart(\WC_Cart) (required)
Cart class instance.

CartSchema::get_cart_errors() code WC 8.7.0

protected function get_cart_errors( $cart ) {
	$controller  = new CartController();
	$errors      = $controller->get_cart_errors();
	$cart_errors = [];

	foreach ( (array) $errors->errors as $code => $messages ) {
		foreach ( (array) $messages as $message ) {
			$cart_errors[] = new \WP_Error(
				$code,
				$message,
				$errors->get_error_data( $code )
			);
		}
	}

	return array_values( array_map( [ $this->error_schema, 'get_item_response' ], $cart_errors ) );
}