Automattic\WooCommerce\Internal\Admin\Orders
ItemQuantityLimits::validate_new_item_quantity
Validate the quantity requested for a product being added to an order.
Метод класса: ItemQuantityLimits{}
Хуки из метода
Возвращает
void. Ничего (null).
Использование
$ItemQuantityLimits = new ItemQuantityLimits(); $ItemQuantityLimits->validate_new_item_quantity( $qty, $product ): void;
- $qty(float) (обязательный)
- Requested quantity.
- $product(WC_Product) (обязательный)
- Product being added.
Список изменений
| С версии 11.2.0 | Введена. |
Код ItemQuantityLimits::validate_new_item_quantity() ItemQuantityLimits::validate new item quantity WC 11.2.2
public function validate_new_item_quantity( float $qty, WC_Product $product ): void {
/**
* This filter is documented in includes/admin/meta-boxes/views/html-order-item.php
*
* @since 5.8.0
*/
$min = apply_filters( 'woocommerce_quantity_input_min_admin', '0', $product, 'add' );
// A callback can return anything; fall back to the default on non-numeric values.
$min = is_numeric( $min ) ? (float) $min : 0.0;
if ( $qty < $min ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- below_min_exception() strips and decodes the message for a JS alert.
throw $this->below_min_exception( $product->get_name(), $min );
}
}