Woocommerce

How To Fix The Rounding Issue In WooCommerce Because Of Included Tax

In this ARTICLE, We learn how to fix the rounding issue in WooCommerce because of the included tax.

Here is the WooCommerce Included Tax issue.

Follow the below step to resolve the WooCommerce Included Tax issue.

Step-1: Use “woocommerce_before_calculate_totals” add action and set tax condition.

add_action( 'woocommerce_before_calculate_totals','conditional_payment_mothod_custom_fee', 10, 1 );
function conditional_payment_mothod_custom_fee( $cart_obj ) {
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $tax = new WC_Tax();
        $country_code = WC()->customer->get_shipping_country(); 
        $rates = $tax->find_rates( array( 'country' => $country_code ) );
        if(empty($rates)) {
        }
    }        
}

Step-2: Use “wc_tax_enabled” add filter for remover zero tax

add_filter( 'wc_tax_enabled', 'custom_enable_tax' , 1, 2 );
function custom_enable_tax(){
return false;
}

Here is the full code.

add_action( 'woocommerce_before_calculate_totals','conditional_payment_mothod_custom_fee', 10, 1 );
function conditional_payment_mothod_custom_fee( $cart_obj ) {
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $tax = new WC_Tax();
        $country_code = WC()->customer->get_shipping_country(); 
        $rates = $tax->find_rates( array( 'country' => $country_code ) );
        if(empty($rates)) {
            add_filter( 'wc_tax_enabled',  'custom_enable_tax' , 1, 2 );
            function custom_enable_tax(){
              return false;
            } 
        }
    }        
}

Here is the result.

 

Tarun Thummar

I'm a JR. WordPress Developer at Vision Infotech.Skilled in HTML,CSS,PHP, WordPress, and jQuery.

Share
Published by
Tarun Thummar

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago