Automattic\WooCommerce\Internal\Admin\Orders
ItemQuantityLimits::validate_new_item_quantity
Validate the quantity requested for a product being added to an order.
Method of the class: ItemQuantityLimits{}
Hooks from the method
Returns
void. Nothing (null).
Usage
$ItemQuantityLimits = new ItemQuantityLimits(); $ItemQuantityLimits->validate_new_item_quantity( $qty, $product ): void;
- $qty(float) (required)
- Requested quantity.
- $product(WC_Product) (required)
- Product being added.
Changelog
| Since 11.2.0 | Introduced. |
ItemQuantityLimits::validate_new_item_quantity() ItemQuantityLimits::validate new item quantity code WC 11.2.1
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 );
}
}