Automattic\WooCommerce\StoreApi\Utilities

QuantityLimits::get_cart_item_quantity_limits()publicWC 1.0

Get quantity limits (min, max, step/multiple) for a product or cart item.

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

Хуков нет.

Возвращает

Массив.

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

$QuantityLimits = new QuantityLimits();
$QuantityLimits->get_cart_item_quantity_limits( $cart_item );
$cart_item(массив) (обязательный)
A cart item array.

Код QuantityLimits::get_cart_item_quantity_limits() WC 6.8.0

public function get_cart_item_quantity_limits( $cart_item ) {
	$product = $cart_item['data'] ?? false;

	if ( ! $product instanceof \WC_Product ) {
		return [
			'minimum'     => 1,
			'maximum'     => null,
			'multiple_of' => 1,
			'editable'    => true,
		];
	}

	$multiple_of = (int) $this->filter_value( 1, 'multiple_of', $cart_item );
	$minimum     = (int) $this->filter_value( 1, 'minimum', $cart_item );
	$maximum     = (int) $this->filter_value( $this->get_product_quantity_limit( $product ), 'maximum', $cart_item );
	$editable    = (bool) $this->filter_value( ! $product->is_sold_individually(), 'editable', $cart_item );

	return [
		'minimum'     => $this->limit_to_multiple( $minimum, $multiple_of, 'ceil' ),
		'maximum'     => $this->limit_to_multiple( $maximum, $multiple_of, 'floor' ),
		'multiple_of' => $multiple_of,
		'editable'    => $editable,
	];
}