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

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::validate_cart_item() public WC 1.0

Validates an existing cart item and returns any errors.

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

Хуки из метода
Возвращает

null. Ничего.

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

$CartController = new CartController();
$CartController->validate_cart_item( $cart_item );
$cart_item(массив) (обязательный)
Cart item array.

Код CartController::validate_cart_item() WC 5.5.2

<?php
public function validate_cart_item( $cart_item ) {
	$product = $cart_item['data'];

	if ( ! $product instanceof \WC_Product ) {
		return;
	}

	if ( ! $product->is_purchasable() ) {
		throw new NotPurchasableException(
			'woocommerce_rest_cart_product_not_purchasable',
			$product->get_name()
		);
	}

	if ( $product->is_sold_individually() && $cart_item['quantity'] > 1 ) {
		throw new TooManyInCartException(
			'woocommerce_rest_cart_product_sold_individually',
			$product->get_name()
		);
	}

	if ( ! $product->is_in_stock() ) {
		throw new OutOfStockException(
			'woocommerce_rest_cart_product_no_stock',
			$product->get_name()
		);
	}

	if ( $product->managing_stock() && ! $product->backorders_allowed() ) {
		$qty_remaining = $this->get_remaining_stock_for_product( $product );
		$qty_in_cart   = $this->get_product_quantity_in_cart( $product );

		if ( $qty_remaining < $qty_in_cart ) {
			throw new PartialOutOfStockException(
				'woocommerce_rest_cart_product_partially_no_stock',
				$product->get_name()
			);
		}
	}

	/**
	 * Fire action to validate add to cart. Functions hooking into this should throw an \Exception to prevent
	 * add to cart from occurring.
	 *
	 * @param \WC_Product $product Product object being added to the cart.
	 * @param array       $cart_item Cart item array.
	 */
	do_action( 'wooocommerce_store_api_validate_cart_item', $product, $cart_item );
}