Automattic\WooCommerce\StoreApi\Utilities
QuantityLimits::filter_numeric_value
Get a numeric value while running it through a filter hook.
Метод класса: QuantityLimits{}
Хуки из метода
Возвращает
int|float.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->filter_numeric_value( $value, $value_type, $product, $cart_item );
- $value(int|float) (обязательный)
- Value to filter.
- $value_type(строка) (обязательный)
- Type of value. Used for filter suffix.
- $product(WC_Product) (обязательный)
- Product instance.
- $cart_item(массив|null)
- Optional cart item associated with the product.
По умолчанию:null
Код QuantityLimits::filter_numeric_value() QuantityLimits::filter numeric value WC 10.5.0
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 ) );
}