Tax rounding issue when having multiple tax classes in woocommerce

Solution:

First you have to search how the tax are calculated in Woocommerce… If you go in WooCommerce WC_Cart class code, you will see that WC_Tax class is responsible for this…

In the source code WC_Tax the methods that make calculations are (with the corresponding available filter hooks to alter that calculations):

  • calc_tax() with available filter hook woocommerce_calc_tax.
  • calc_shipping_tax() with available filter hook woocommerce_calc_shipping_tax.
  • round() with available filter hook woocommerce_tax_round.
  • calc_inclusive_tax() with available filter hook woocommerce_price_inc_tax_amount.
  • calc_exclusive_tax() with available filter hook woocommerce_price_ex_tax_amount.
  • and may be some others…

Here is an example to change the round() behavior to return rounding to .5 cents:

add_filter( 'woocommerce_tax_round', 'euro_5cent_rounding' );
function euro_5cent_rounding( $in ) {
    return round( $in / 5, 2 ) * 5;
}

Code goes in function.php file of your active child theme or active theme (or also in any plugin file).

As your problem is very specific and difficult to reproduce, you will have to find which hook is going to make the trick to solve your issue…