Automattic\WooCommerce\StoreApi\Utilities
QuantityLimits::adjust_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|float.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->adjust_product_quantity_limit( $purchase_limit, $product, $cart_item );
- $purchase_limit(int|float) (обязательный)
- The purchase limit from the product. Usually maps to
get_max_purchase_quantity. - $product(WC_Product) (обязательный)
- Product instance.
- $cart_item(массив|null)
- Optional cart item associated with the product.
По умолчанию:null
Код QuantityLimits::adjust_product_quantity_limit() QuantityLimits::adjust product quantity limit WC 11.2.2
protected function adjust_product_quantity_limit( $purchase_limit, \WC_Product $product, $cart_item = null ) {
$limits = [ $purchase_limit > 0 ? $purchase_limit : 9999 ];
// If managing stock and backorders are not allowed, get the remaining stock considering active carts.
if ( $product->managing_stock() && ! $product->backorders_allowed() ) {
$limits[] = $this->get_remaining_stock( $product );
}
return $this->filter_numeric_value( min( array_filter( $limits ) ), 'limit', $product, $cart_item );
}