Automattic\WooCommerce\StoreApi\Utilities
QuantityLimits::get_product_quantity_limit()
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{}
Hooks from the method
Return
Int
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_product_quantity_limit( $product );
- $product(\WC_Product) (required)
- Product instance.
QuantityLimits::get_product_quantity_limit() QuantityLimits::get product quantity limit code WC 9.2.3
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. * * @since 6.8.0 * * @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 ); }