How do you get the tax total in woocommerce in the functions.php page in wordpress. Using :

global $woocommerce;

$discount = $woocommerce->cart->tax_total;

Is not returning any value.

Essentially I want the Tax to calculate for the user, but then have it reduced as the customer will pay the taxes on COD. Full Code below
Full Code:

add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 );
function action_cart_calculate_totals( $cart_object ) {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( !WC()->cart->is_empty() ):
        $cart_object->cart_contents_total *= .10 ;

    endif;
}


//Code for removing tax from total collected
function prefix_add_discount_line( $cart ) {

  global $woocommerce;

  $discount = $woocommerce->cart->tax_total;

  $woocommerce->cart->add_fee( __( 'Tax Paid On COD', 'your-text-domain' ) , - $discount );

}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line' );

Read more here: How to Get Tax Total WooCommerce Programatically


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: