Automattic\WooCommerce\StoreApi\Utilities

QuantityLimits::adjust_product_quantity_limitprotectedWC 1.0

Get the limit for the total number of a product allowed in the cart.

This is based on product properties, including remaining stock, and defaults to a maximum of 9999 of any product in the cart at once.

Method of the class: QuantityLimits{}

No Hooks.

Returns

Int|float.

Usage

// protected - for code of main (parent) or child class
$result = $this->adjust_product_quantity_limit( $purchase_limit, $product, $cart_item );
$purchase_limit(int|float) (required)
The purchase limit from the product. Usually maps to get_max_purchase_quantity.
$product(WC_Product) (required)
Product instance.
$cart_item(array|null)
Optional cart item associated with the product.
Default: null

QuantityLimits::adjust_product_quantity_limit() code WC 10.9.1

protected function adjust_product_quantity_limit( $purchase_limit, \WC_Product $product, $cart_item = null ) {
	$limits = [ $purchase_limit > 0 ? $purchase_limit : 9999 ];

	// If managing stock and backorders are not allowed, get the remaining stock considering active carts.
	if ( $product->managing_stock() && ! $product->backorders_allowed() ) {
		$limits[] = $this->get_remaining_stock( $product );
	}

	return $this->filter_numeric_value( min( array_filter( $limits ) ), 'limit', $product, $cart_item );
}