WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::get_cart_item_errors() public WC 1.0

Validate all items in the cart and get a list of errors.

{} It's a method of the class: CartController{}

No Hooks.

Return

WP_Error[]. An array of WP_Errors describing the cart's error state.

Usage

$CartController = new CartController();
$CartController->get_cart_item_errors();

Code of CartController::get_cart_item_errors() WC 5.8.0

public function get_cart_item_errors() {
	$errors     = [];
	$cart_items = $this->get_cart_items();

	$too_many_in_cart_exceptions     = [];
	$not_purchasable_exceptions      = [];
	$partial_out_of_stock_exceptions = [];
	$out_of_stock_exceptions         = [];

	foreach ( $cart_items as $cart_item_key => $cart_item ) {
		try {
			$this->validate_cart_item( $cart_item );
		} catch ( RouteException $error ) {
			$errors[] = new WP_Error( $error->getErrorCode(), $error->getMessage() );
		} catch ( TooManyInCartException $error ) {
			$too_many_in_cart_exceptions[] = $error;
		} catch ( NotPurchasableException $error ) {
			$not_purchasable_exceptions[] = $error;
		} catch ( PartialOutOfStockException $error ) {
			$partial_out_of_stock_exceptions[] = $error;
		} catch ( OutOfStockException $error ) {
			$out_of_stock_exceptions[] = $error;
		}
	}

	if ( count( $errors ) > 0 ) {
		return $errors;
	}

	return $this->stock_exceptions_to_wp_errors( $too_many_in_cart_exceptions, $not_purchasable_exceptions, $partial_out_of_stock_exceptions, $out_of_stock_exceptions );
}