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.
Метод класса: QuantityLimits{}
Хуки из метода
Возвращает
int
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_product_quantity_limit( $product );
- $product(WC_Product) (обязательный)
- Product instance.
Код QuantityLimits::get_product_quantity_limit() QuantityLimits::get product quantity limit WC 9.9.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 ); } $limit = max( min( array_filter( $limits ) ), 1 ); /** * 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 */ $filtered_limit = apply_filters( 'woocommerce_store_api_product_quantity_limit', $limit, $product ); // Only return the filtered limit if it's numeric, otherwise return the original limit. return is_numeric( $filtered_limit ) ? (int) $filtered_limit : $limit; }