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

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::add_to_cart() public WC 1.0

Based on the core cart class but returns errors rather than rendering notices directly.

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

Возвращает

Строку|Error.

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

$CartController = new CartController();
$CartController->add_to_cart( $request );
$request(массив) (обязательный)
Add to cart request params.

Код CartController::add_to_cart() WC 5.4.1

<?php
public function add_to_cart( $request ) {
	$cart    = $this->get_cart_instance();
	$request = wp_parse_args(
		$request,
		[
			'id'             => 0,
			'quantity'       => 1,
			'variation'      => [],
			'cart_item_data' => [],
		]
	);

	$request = $this->filter_request_data( $this->parse_variation_data( $request ) );
	$product = $this->get_product_for_cart( $request );
	$cart_id = $cart->generate_cart_id(
		$this->get_product_id( $product ),
		$this->get_variation_id( $product ),
		$request['variation'],
		$request['cart_item_data']
	);

	$this->validate_add_to_cart( $product, $request );

	$existing_cart_id = $cart->find_product_in_cart( $cart_id );

	if ( $existing_cart_id ) {
		if ( $product->is_sold_individually() ) {
			throw new RouteException(
				'woocommerce_rest_cart_product_sold_individually',
				sprintf(
					/* translators: %s: product name */
					__( 'You cannot add another "%s" to your cart.', 'woocommerce' ),
					$product->get_name()
				),
				400
			);
		}
		$cart->set_quantity( $existing_cart_id, $request['quantity'] + $cart->cart_contents[ $existing_cart_id ]['quantity'], true );

		return $existing_cart_id;
	}

	$cart->cart_contents[ $cart_id ] = apply_filters(
		'woocommerce_add_cart_item',
		array_merge(
			$request['cart_item_data'],
			array(
				'key'          => $cart_id,
				'product_id'   => $this->get_product_id( $product ),
				'variation_id' => $this->get_variation_id( $product ),
				'variation'    => $request['variation'],
				'quantity'     => $request['quantity'],
				'data'         => $product,
				'data_hash'    => wc_get_cart_item_data_hash( $product ),
			)
		),
		$cart_id
	);

	$cart->cart_contents = apply_filters( 'woocommerce_cart_contents_changed', $cart->cart_contents );

	do_action(
		'woocommerce_add_to_cart',
		$cart_id,
		$this->get_product_id( $product ),
		$request['quantity'],
		$this->get_variation_id( $product ),
		$request['variation'],
		$request['cart_item_data']
	);

	return $cart_id;
}