WC_Cart::get_cart_item_quantities()publicWC 1.0

Get cart items quantities - merged so we can do accurate stock checks on items across multiple lines.

Method of the class: WC_Cart{}

No Hooks.

Return

Array.

Usage

$WC_Cart = new WC_Cart();
$WC_Cart->get_cart_item_quantities();

WC_Cart::get_cart_item_quantities() code WC 9.4.2

public function get_cart_item_quantities() {
	$quantities = array();

	foreach ( $this->get_cart() as $values ) {
		$product = $values['data'];
		$quantities[ $product->get_stock_managed_by_id() ] = isset( $quantities[ $product->get_stock_managed_by_id() ] ) ? $quantities[ $product->get_stock_managed_by_id() ] + $values['quantity'] : $values['quantity'];
	}

	return $quantities;
}