Automattic\WooCommerce\Blocks\StoreApi\Utilities
CartController::set_cart_item_quantity() public WC 1.0
Based on core set_quantity method, but validates if an item is sold individually first.
{} Это метод класса: CartController{}
Хуков нет.
Возвращает
Null. Ничего.
Использование
$CartController = new CartController(); $CartController->set_cart_item_quantity( $item_id, $quantity );
- $item_id(строка) (обязательный)
- Cart item id.
- $quantity(числоeger)
- Cart quantity.
Код CartController::set_cart_item_quantity() CartController::set cart item quantity WC 5.0.0
public function set_cart_item_quantity( $item_id, $quantity = 1 ) {
$cart_item = $this->get_cart_item( $item_id );
if ( empty( $cart_item ) ) {
throw new RouteException( 'woocommerce_rest_cart_invalid_key', __( 'Cart item does not exist.', 'woocommerce' ), 404 );
}
$product = $cart_item['data'];
if ( ! $product instanceof \WC_Product ) {
throw new RouteException( 'woocommerce_rest_cart_invalid_product', __( 'Cart item is invalid.', 'woocommerce' ), 404 );
}
if ( $product->is_sold_individually() && $quantity > 1 ) {
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 = $this->get_cart_instance();
$cart->set_quantity( $item_id, $quantity );
}