<?php
remove_filter('woocommerce_stock_amount', 'intval');
add_filter('woocommerce_stock_amount', 'floatval');
function gog_min_decimal_qty($val, $product) {
$decimal_qty = get_post_meta($product->id, '_decimal_qty', true);
if ($decimal_qty) {
$val = 0.01;
}
return $val;
}
add_filter('woocommerce_quantity_input_min', 'gog_min_decimal_qty', 20, 2);
function gog_allow_decimal_qty($val, $product) {
$decimal_qty = get_post_meta($product->id, '_decimal_qty', true);
if ($decimal_qty) {
$val = 0.01;
}
return $val;
}
add_filter('woocommerce_quantity_input_step', 'gog_allow_decimal_qty', 20, 2);
function gog_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;
}
add_filter('woocommerce_order_amount_item_total', 'gog_unit_price_fix', 10, 5);
Dále je potřeba upravit jQuery skript u tlačítek pro změnu množství produktu.