Automattic\WooCommerce\StoreApi\Utilities
CartController::stock_exceptions_to_wp_errors()
This method will take arrays of exceptions relating to stock, and will convert them to a WP_Error object.
Method of the class: CartController{}
No Hooks.
Return
WP_Error
. The WP_Error object returned. Will have errors if any exceptions were in the args. It will be empty if they do not.
Usage
// private - for code of main (parent) class only $result = $this->stock_exceptions_to_wp_errors( $too_many_in_cart_products, $not_purchasable_products, $partial_out_of_stock_products, $out_of_stock_products );
- $too_many_in_cart_products(TooManyInCartException[]) (required)
- Array of TooManyInCartExceptions.
- $not_purchasable_products(NotPurchasableException[]) (required)
- Array of NotPurchasableExceptions.
- $partial_out_of_stock_products(PartialOutOfStockException[]) (required)
- Array of PartialOutOfStockExceptions.
- $out_of_stock_products(OutOfStockException[]) (required)
- Array of OutOfStockExceptions.
CartController::stock_exceptions_to_wp_errors() CartController::stock exceptions to wp errors code WC 9.2.3
private function stock_exceptions_to_wp_errors( $too_many_in_cart_products, $not_purchasable_products, $partial_out_of_stock_products, $out_of_stock_products ) { $error = new WP_Error(); if ( count( $out_of_stock_products ) > 0 ) { $singular_error = $this->get_error_message_for_stock_exception_type( 'out_of_stock', 'singular' ); $plural_error = $this->get_error_message_for_stock_exception_type( 'out_of_stock', 'plural' ); $error->add( 'woocommerce_rest_product_out_of_stock', $this->add_product_names_to_message( $singular_error, $plural_error, $out_of_stock_products ) ); } if ( count( $not_purchasable_products ) > 0 ) { $singular_error = $this->get_error_message_for_stock_exception_type( 'not_purchasable', 'singular' ); $plural_error = $this->get_error_message_for_stock_exception_type( 'not_purchasable', 'plural' ); $error->add( 'woocommerce_rest_product_not_purchasable', $this->add_product_names_to_message( $singular_error, $plural_error, $not_purchasable_products ) ); } if ( count( $too_many_in_cart_products ) > 0 ) { $singular_error = $this->get_error_message_for_stock_exception_type( 'too_many_in_cart', 'singular' ); $plural_error = $this->get_error_message_for_stock_exception_type( 'too_many_in_cart', 'plural' ); $error->add( 'woocommerce_rest_product_too_many_in_cart', $this->add_product_names_to_message( $singular_error, $plural_error, $too_many_in_cart_products ) ); } if ( count( $partial_out_of_stock_products ) > 0 ) { $singular_error = $this->get_error_message_for_stock_exception_type( 'partial_out_of_stock', 'singular' ); $plural_error = $this->get_error_message_for_stock_exception_type( 'partial_out_of_stock', 'plural' ); $error->add( 'woocommerce_rest_product_partially_out_of_stock', $this->add_product_names_to_message( $singular_error, $plural_error, $partial_out_of_stock_products ) ); } return $error; }