Automattic\WooCommerce\StoreApi\Utilities

QuantityLimits::filter_numeric_valueprotectedWC 1.0

Get a numeric value while running it through a filter hook.

Method of the class: QuantityLimits{}

Returns

Int|float.

Usage

// protected - for code of main (parent) or child class
$result = $this->filter_numeric_value( $value, $value_type, $product, $cart_item );
$value(int|float) (required)
Value to filter.
$value_type(string) (required)
Type of value. Used for filter suffix.
$product(WC_Product) (required)
Product instance.
$cart_item(array|null)
Optional cart item associated with the product.
Default: null

QuantityLimits::filter_numeric_value() code WC 10.9.1

protected function filter_numeric_value( $value, string $value_type, \WC_Product $product, $cart_item = null ) {
	/**
	 * Filters a quantity for a cart item in Store API. This allows extensions to control the qty of items.
	 *
	 * The suffix of the hook will vary depending on the value being filtered.
	 * For example, minimum, maximum, multiple_of, editable.
	 *
	 * @since 6.8.0
	 *
	 * @param mixed $value The value being filtered.
	 * @param \WC_Product $product The product object.
	 * @param array|null $cart_item The cart item if the product exists in the cart, or null.
	 * @return mixed
	 */
	$filtered_value = apply_filters( 'woocommerce_store_api_product_quantity_' . $value_type, $value, $product, $cart_item );

	return wc_stock_amount( NumberUtil::normalize( $filtered_value, $value ) );
}