Automattic\WooCommerce\StoreApi\Utilities

QuantityLimits::get_product_quantity_limit()protectedWC 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.

{} Это метод класса: QuantityLimits{}

Возвращает

int.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_product_quantity_limit( $product );
$product(\WC_Product) (обязательный)
Product instance.

Код QuantityLimits::get_product_quantity_limit() WC 6.8.0

protected function get_product_quantity_limit( \WC_Product $product ) {
	$limits = [ 9999 ];

	if ( $product->is_sold_individually() ) {
		$limits[] = 1;
	} elseif ( ! $product->backorders_allowed() ) {
		$limits[] = $this->get_remaining_stock( $product );
	}

	/**
	 * Filters the quantity limit for a product being added to the cart via the Store API.
	 *
	 * Filters the variation option name for custom option slugs.
	 *
	 * @param integer $quantity_limit Quantity limit which defaults to 9999 unless sold individually.
	 * @param \WC_Product $product Product instance.
	 * @return integer
	 */
	return apply_filters( 'woocommerce_store_api_product_quantity_limit', max( min( array_filter( $limits ) ), 1 ), $product );
}