• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / CartController::get_cart_item_errors() – Validate all items in the cart and get a list of errors.

You appear to be a bot. Output may be restricted

Description

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

Usage

$WP_Error[] = CartController::get_cart_item_errors();

Parameters

Returns

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

Source

File name: woocommerce/packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php


Lines:

1 to 32 of 32
  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 );
  }
 

 View on GitHub View on Trac

Published: 21st August 2020 | Last updated: 19th April 2021

Primary Sidebar

Information

Function name: CartController::get_cart_item_errors
Class ref: CartController
Plugin ref: WooCommerce
Version: 5.2.2
Sourcefile: packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php
File ref: packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php
Deprecated?: No
API Letters: C,E,G,I

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites