Automattic\WooCommerce\StoreApi\Utilities

CartController::stock_exceptions_to_wp_errors()privateWC 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 6.8.0

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;
}