1

I have a 3 shipping methods in my Woocommerce store and I want to disable the tax rate when customer choose the 3rd shipping method.

How can I do that?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Marvyn Sue
  • 75
  • 2
  • 10
  • Yes there is, I have set it to "none" already but I still get the tax on that method – Marvyn Sue Sep 03 '18 at 08:37
  • Can you give the specific related shipping method ID(s) *(for each zone if there is many)* that should be something like: `flat_rate:11` … You can find that with your bowser tools, inspecting the generated html code for the shipping methods radio buttons. – LoicTheAztec Sep 03 '18 at 08:43
  • shipping_method_0_flat_rate2 shipping_method_0_shipping_by_rules5 shipping_method_0_flat_rate3 -> this is the id of the method where I need to disable the tax Thanks – Marvyn Sue Sep 03 '18 at 08:50
  • 1
    The `shipping_method_0_shipping_by_rules5` is a custom shipping method made by a plugin or by dome customizations… So you should add in your question the related information. Actually your question is a bit too vague. Now your **shipping methods IDs** should be normally `flat_rate:2`, `shipping_by_rules:5` and `flat_rate:3` if you look to the generated html code for input radio (buttons) in the tag attribute **"value"**… Please confirm. – LoicTheAztec Sep 03 '18 at 08:57
  • should i get the input ID or the value? – Marvyn Sue Sep 03 '18 at 09:05
  • the value is this one flat_rate:2 shipping_by_rules:5 flat_rate:3 -> this method where tax should be disabled – Marvyn Sue Sep 03 '18 at 09:05
  • The input value – LoicTheAztec Sep 03 '18 at 09:07
  • the value is this one flat_rate:2 shipping_by_rules:5 flat_rate:3 -> this method where tax should be disabled – Marvyn Sue Sep 03 '18 at 09:14

1 Answers1

2

As settings doesn't seem to be working to remove taxes from specific shipping methods, try the following code that will set zero taxes to your specific defined shipping methods:

add_filter('woocommerce_package_rates', 'null_specific_shipping_method_taxes', 12, 2);
function null_specific_shipping_method_taxes( $rates, $package ){
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return $rates;

    // HERE define your targeted shipping methods IDs (in this array)
    $shipping_methods_ids = array( 'flat_rate:2', 'flat_rate:12', 'flat_rate:3', 'shipping_by_rules:5' );

    // Loop through shipping rates
    foreach ( $rates as $rate_key => $rate ){
        $has_taxes = false;

        // Only for your defined Shipping method IDs
        if( in_array( $rate->id, $shipping_methods_ids ) ){
            $taxes = [];
            // Loop through the shipping taxes array (as they can be many)
            foreach ($rates[$rate_key]->taxes as $key => $tax){
                if( $rates[$rate_key]->taxes[$key] > 0 ){
                    // Set each tax cost to zero
                    $taxes[$key] = 0;
                    $has_taxes   = true;
                }
            }
            // Set the new taxes array
            if( $has_taxes )
                $rates[$rate_key]->taxes = $taxes;
        }
    }
    return $rates;
}

This code goes on function.php file of your active child theme (or theme). Tested and works (if settings are made in a correct way, regarding related shipping methods and taxes in Woocommerce)

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thank you for the effort, but I still get the tax rate on this method flat_rate:3. I already done what you have said – Marvyn Sue Sep 03 '18 at 09:40
  • @MarvynSue I think that your Tax settings or your shipping settings are wrong as I have tested this and it works just perfectly. It could be also a bug due to some other customizations or some plugin that are making trouble. Your question is very poor and vague, without any details… So nobody will be able to help you. – LoicTheAztec Sep 03 '18 at 09:47
  • Ill add a screenshot on my tax settings. [link]https://screenshots.firefox.com/FRV6qTBrWyqcOKR5/synergymediaprojects.co.uk[link] [link]https://screenshots.firefox.com/6wiNrYlGRgbeH1dJ/synergymediaprojects.co.uk[link] – Marvyn Sue Sep 03 '18 at 10:01
  • No, please **you edit your question** adding some text explanations, text details and screenshots through the stackOverFlow add screenshot tool bar feature. You also add all related shipping plugins information and details that you are using. Now **on your side**, make a backup first and try to disable other customizations and plugins to see if there is no something that is interfering… Try to change settings (and read the carefully all related documentation). – LoicTheAztec Sep 03 '18 at 10:09