The other day, We had discussion with a client of ours about rounding off issue in cart totals. It was coming as .01, .02 after tax and shipping charges calculation. Though we rounded of the taxes at line level with WooCommerce Settings, it was not appearing properly.
We had many options to round off.
- Make every element like Tax, Item Price and shipping charges even and set it up.
- Change the piece of code which is calculating the total.
- Or just customize it to display the amount rounded at cart level.
To make it simple, we chose the 3rd option. We understand, if the below code is added to functions.php, when theme updates it will go off. Rather we have a child theme to make the changes. The below piece of code worked like a charm. try this and let us know your opinion.
add_filter( ‘woocommerce_calculated_total’, ‘custom_calculated_total’ );
function custom_calculated_total( $total ) {
$total = round( $total, 1 );
return ceil($total);
}
This code returns the nearest rounded amount in your cart.
#WooCommerce #Wordpress #CartTotals, #functions.php
Recent Comments