Automattic\WooCommerce\StoreApi\Utilities
CartController::get_product_quantity_in_cart
Gets the qty of a product across line items.
Метод класса: CartController{}
Хуков нет.
Возвращает
int.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_product_quantity_in_cart( $product );
- $product(WC_Product) (обязательный)
- Product object.
Код CartController::get_product_quantity_in_cart() CartController::get product quantity in cart WC 11.0.1
protected function get_product_quantity_in_cart( $product ) {
$cart = $this->get_cart_instance();
$product_quantities = $cart->get_cart_item_quantities();
$product_id = $product->get_stock_managed_by_id();
return $product_quantities[ $product_id ] ?? 0;
}