WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::stock_exceptions_to_wp_errors() private WC 1.0

This method will take arrays of exceptions relating to stock, and will convert them to a WP_Error object.

{} Это метод класса: CartController{}

Хуков нет.

Возвращает

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.

Использование

// private - только в коде основоного (родительского) класса
$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[]) (обязательный)
Array of TooManyInCartExceptions.
$not_purchasable_products(NotPurchasableException[]) (обязательный)
Array of NotPurchasableExceptions.
$partial_out_of_stock_products(PartialOutOfStockException[]) (обязательный)
Array of PartialOutOfStockExceptions.
$out_of_stock_products(OutOfStockException[]) (обязательный)
Array of OutOfStockExceptions.

Код CartController::stock_exceptions_to_wp_errors() WC 5.3.0

<?php
private function 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_error     = new WP_Error();
	$out_of_stock_error         = new WP_Error();
	$partial_out_of_stock_error = new WP_Error();
	$not_purchasable_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' );

		$out_of_stock_error->add(
			'woocommerce-blocks-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' );

		$not_purchasable_error->add(
			'woocommerce-blocks-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' );

		$too_many_in_cart_error->add(
			'woocommerce-blocks-too-many-of-product-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' );

		$partial_out_of_stock_error->add(
			'woocommerce-blocks-product-partially-out-of-stock',
			$this->add_product_names_to_message( $singular_error, $plural_error, $partial_out_of_stock_products )
		);
	}

	return array_filter(
		[
			$too_many_in_cart_error,
			$partial_out_of_stock_error,
			$out_of_stock_error,
			$not_purchasable_error,
		],
		function( $error ) {
			return $error->has_errors();
		}
	);
}