Automattic\WooCommerce\StoreApi\Utilities
QuantityLimits::get_cart_item_quantity_limits()
Get quantity limits (min, max, step/multiple) for a product or cart item.
Method of the class: QuantityLimits{}
No Hooks.
Return
Array
.
Usage
$QuantityLimits = new QuantityLimits(); $QuantityLimits->get_cart_item_quantity_limits( $cart_item );
- $cart_item(array) (required)
- A cart item array.
QuantityLimits::get_cart_item_quantity_limits() QuantityLimits::get cart item quantity limits code WC 9.3.3
public function get_cart_item_quantity_limits( $cart_item ) { $product = $cart_item['data'] ?? false; if ( ! $product instanceof \WC_Product ) { return [ 'minimum' => 1, 'maximum' => 9999, '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, ]; }