title: Woocommerce update cart total tax - woocommerce_after_calculate_totals
body: <p>Within my shop I had to adjust the calculation of the total cart value which was successfull. For this task I used <code>add_action( 'woocommerce_after_calculate_totals', 'custom_woocommerce_after_calculate_totals', 30 );</code>.</p>
  <p>After my calculations I get for example a price of 167,74€ which includes 27,951... VAT (20%).<br>
  Now I have the problem that VAT calculation is wrong after a few digits.<br>
  The correct result should be 27,956... =&gt; rounded up to 27,96. Which results in a cent difference.</p>
  <p>Because of the wrong value I tried to do my own calculation by &quot;reverse engineering&quot; the tax rate and calculating the tax_total on my own.</p>
  <p><strong>My calculation:</strong></p>
  <pre><code>add_action( 'woocommerce_after_calculate_totals', 'custom_woocommerce_after_calculate_totals', 30 );
  
  function custom_woocommerce_after_calculate_totals( $cart ) {
  
      $subtotal = 0.0;
      /* Get cart items */
      $items = $cart-&gt;cart_contents;
  
      $do_one_time = 0;
      foreach ($items as $key =&gt; $item) {
      
          // Reverse engineer the tax rate because Woocommerce lacks a get rate method on the cart
          if($item['line_total'] &amp;&amp; $item['line_tax']){
              if($do_one_time &lt; 1){
                  $the_cost = $item['line_total'];
                  $the_tax = $item['line_tax'];
                  $tax_rate = round(ceil(($the_tax / $the_cost)*1000)/1000,2);
                  $do_one_time++;
              }
          }
          /* Calculate cart total value */
          if($item[&quot;line_subtotal&quot;]){
              /* manually add up the cart item subtotal value and round it by 2 digits */
              $number = round($item[&quot;line_subtotal&quot;], 2);
              $subtotal += $number;
          }
  
      }
      /* If shipping is set add it to subtotal value otherwise keep the already calculated subtotal*/
      if($cart-&gt;shipping_total){
          $subtotal_with_shipping = $cart-&gt;shipping_total + $subtotal;
          $subtotal_tax = $subtotal_with_shipping * $tax_rate;
          $total_cost = round($subtotal_with_shipping + $subtotal_tax, 2);
      }else{
          $subtotal_tax = $subtotal * $tax_rate;
          $total_cost = round($subtotal + $subtotal_tax, 2);
      }
  
  
      /* Compare cart total value with pre-calculated total value by woocommerce */
      /* If a difference within the values is present we update the total value with our own total value =&gt; $total_cost */
  
      if($subtotal !== $cart-&gt;subtotal_ex_tax){
          $cart-&gt;total = $total_cost;
      }    
      /* part which is not working */
      $cart-&gt;tax_total = $subtotal_tax;
      
      /* Also tried the following which changes the data within the cart but not on the frontend -&gt; I saw the changes within var_dump($cart)*/
      $cart-&gt;set_total_tax($subtotal_tax);
      
  
  }
  </code></pre>
  <p>Within my <code>$subtotal_tax</code> I have the correct value of 27,96€ but I can´t find a way to update the value.</p>
  <p>For the total value I set the <code>$cart-&gt;total = $total_cost;</code> which worked fine.
  I tried the same for the total tax with <code>$cart-&gt;tax_total = $subtotal_tax;</code> but I won´t change the value.</p>
  <p>Is there some way to update the tax_total wihthin the <code>woocommerce_after_calculate_totals</code> action?</p>
  <p>Output (Wrong): <br>
  Total: 167,74€ which includes VAT of 27,95€ (20%).</p>
  <p>Output (Needed):<br>
  Total: 167,74€ which includes VAT of 27,96€ (20%).</p>