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.