Skip to content
Advertisement

Hide shipping methods based on products categories in Woocommerce

With Woocommerce, I would like to hide all shipping methods except “Local pickup” when a defined products category is in cart…

The code below does that for other product types, except variable products:

JavaScript

What can I do to make it work for variable products too? Any help is appreciated.

Advertisement

Answer

I have revisited your code and here is correct way to make it work for variable products too:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

You should need to refresh the shipping caches:
1) First this code is already saved on your function.php file.
2) In Shipping settings, enter in a Shipping Zone and disable a Shipping Method and “save”. Then re-enable that Shipping Method and “save”. You are done.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement