Automattic\WooCommerce\StoreApi\Utilities

CartController::get_cart_errors()publicWC 1.0

Validate the cart and get a list of errors.

Method of the class: CartController{}

No Hooks.

Return

WP_Error. A WP_Error instance containing the cart's errors.

Usage

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

CartController::get_cart_errors() code WC 8.6.1

public function get_cart_errors() {
	$errors = new WP_Error();

	try {
		$this->validate_cart();
	} catch ( RouteException $error ) {
		$errors->add( $error->getErrorCode(), $error->getMessage(), $error->getAdditionalData() );
	} catch ( InvalidCartException $error ) {
		$errors->merge_from( $error->getError() );
	} catch ( \Exception $error ) {
		$errors->add( $error->getCode(), $error->getMessage() );
	}

	return $errors;
}