Automattic\WooCommerce\StoreApi\Utilities

CartController::get_product_quantity_in_cart()protectedWC 1.0

Gets the qty of a product across line items.

Method of the class: CartController{}

No Hooks.

Return

Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_product_quantity_in_cart( $product );
$product(\WC_Product) (required)
Product object.

CartController::get_product_quantity_in_cart() code WC 9.4.2

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 isset( $product_quantities[ $product_id ] ) ? $product_quantities[ $product_id ] : 0;
}