Round Discounts to 1 decimal
Round discount amounts to one decimal place.
// Round discount to 1 decimal by using woocommerce round discount function and it may be round half down (1.5 into 1)
add_filter('advanced_woo_discount_rules_discount_prices_of_product', function ($discount_prices, $product, $quantity, $cart_item){
if (function_exists('wc_round_discount') && function_exists('wc_get_price_decimals')) {
$precision = 1;
if(isset($discount_prices['discounted_price'])){
$discount_prices['discounted_price'] = wc_round_discount($discount_prices['discounted_price'], $precision);
}
if(isset($discount_prices['discounted_price_with_tax'])){
$discount_prices['discounted_price_with_tax'] = wc_round_discount($discount_prices['discounted_price_with_tax'], $precision);
}
if(isset($discount_prices['discount_lines'])){
foreach ($discount_prices['discount_lines'] as $key => $value){
if($key !== 'non_applied'){
$line_discount = $discount_prices['discount_lines'][$key]['discounted_price'];
$discount_prices['discount_lines'][$key]['discounted_price'] = wc_round_discount($line_discount, $precision);
}
}
}
}
return $discount_prices;
}, 10, 4);