doomrider89
Новичок

Добрый день, хочу сделать для определённой категории пример: Колбаса, что бы шаг был не 1 а 0.2 и цену соответсвенно не за 1кг а за 200 грамм.
Нашёл данное решение (делает шаг в 0.1):
Которое меняет шаг на 0.1 и соответственно цену, но он это делает для всех товаров...
Попытался использовать условие:
if( is_product_category( array( 291 ) ) )
(291 - id моей категории)
но почему то это не работает...
подскажите что я делаю не так?
Нашёл данное решение (делает шаг в 0.1):
Код:
// Add min value to the quantity field (default = 1)
add_filter('woocommerce_quantity_input_min', 'min_decimal');
function min_decimal($val) {
return 0.1;
}
// Add step value to the quantity field (default = 1)
add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal');
function nsk_allow_decimal($val) {
return 0.1;
}
// Removes the WooCommerce filter, that is validating the quantity to be an int
remove_filter('woocommerce_stock_amount', 'intval');
// Add a filter, that validates the quantity to be a float
add_filter('woocommerce_stock_amount', 'floatval');
// Add unit price fix when showing the unit price on processed orders
add_filter('woocommerce_order_amount_item_total', 'unit_price_fix', 10, 5);
function unit_price_fix($price, $order, $item, $inc_tax = false, $round = true) {
$qty = (!empty($item['qty']) && $item['qty'] != 0) ? $item['qty'] : 1;
if($inc_tax) {
$price = ($item['line_total'] + $item['line_tax']) / $qty;
} else {
$price = $item['line_total'] / $qty;
}
$price = $round ? round( $price, 2 ) : $price;
return $price;
}
Попытался использовать условие:
if( is_product_category( array( 291 ) ) )
(291 - id моей категории)
но почему то это не работает...
подскажите что я делаю не так?