WooCommerce: Hide Shipping Method If Shipping Class Is In The Cart

Our goal is to check if a Product with a specific Shipping Class is in the Cart, and consequently disabling a shipping rate such as Free Shipping if this is true.

This is super useful when there are multiple items in the cart and you don’t want to give free shipping for certain orders for example.

WooCommerce: Disable Free Shipping if a specific Shipping Class is in the Cart
WooCommerce: Disable Free Shipping if a specific Shipping Class is in the Cart

PHP Snippet: Disable Free Shipping Rate if WooCommerce Cart Contains Product with Specific Shipping Class

/**
 * @snippet       Disable Free Shipping if Cart has Shipping Class
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */
 
add_filter( 'woocommerce_package_rates', 'bbloomer_hide_free_shipping_for_shipping_class', 9999, 2 );
  
function bbloomer_hide_free_shipping_for_shipping_class( $rates, $package ) {
   $shipping_class_target = 15; // shipping class ID (see screenshot below)
   $in_cart = false;
   foreach ( WC()->cart->get_cart_contents() as $key => $values ) {
      if ( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) {
         $in_cart = true;
         break;
      } 
   }
   if ( $in_cart ) {
      unset( $rates['free_shipping:8'] ); // shipping method ID (see screenshot below)
   }
   return $rates;
}

Shipping Rates Not Hiding After Implementing PHP?

You probably need to clear the customer sessions:

Clear Customer Sessions – WooCommerce System Status Tools

WooCommerce: How to Find Shipping Class ID

WooCommerce 2.6+: Find Shipping Class ID
WooCommerce: Find Shipping Class ID

WooCommerce: How to Find Shipping Method ID

Find Shipping Method Name in WooCommerce 2.6+
Find Shipping Method Name in WooCommerce

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
  • WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart
    This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. Here’s how we show a simple message on the […]
  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

132 thoughts on “WooCommerce: Hide Shipping Method If Shipping Class Is In The Cart

  1. Hi.
    Another great code snippet. Thanks a lot.

  2. Do you have a PHP snippet which > “Disable Free Shipping Rate if WooCommerce Cart Contains Product with Sale Price (product on sale)”

    Even if the customer meet criteria for free shipping , if his cart contains even a single product which is on sale, to disable free shipping.

  3. As finding the shipping method ID is a little messy I wrote some code to show all the shipping zones and shipping method IDs on the WooCommerce/Settings/Shipping page in the Dashboard. This might help your readers when they use the code in this post.
    https://www.damiencarbery.com/2022/10/show-shipping-method-ids-in-woocommerce/
    Show shipping method IDs in WooCommerce – List shipping zones, shipping methods and their IDs for use in custom code.

  4. Hi, i want to hide Free Shipping when other shipping methods are available in the cart. I would appreciate your help thank you

  5. Thank you!! Spent an hour trying to find a simple plugin to run this code, $100 to unlock the by shipping class option on everything!! Finally found this and it worked perfectly. I have just enough coding knowledge to be dangerous, but seem to always be lacking the last pieces to make my own solutions, so thank you for providing your knowledge! Sending $9 your way as the code suggests ; )

  6. Thank you Rodolfo Melogli for your great work. All the best in 2022!

  7. Hello,
    how can i add a second shippiing class? I would like to exclude two shipping classes from free shipping. I copied the code a second time in the function.php and changed the shipping class id but it gives me an error πŸ™
    Thanks and regards,
    Sascha

    1. Hi Sascha thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  8. Hi Rodolfo,
    First, thank you for your greats tutos !

    Thank to your tuto, i’m alllowed to disabling a specific shipping method for “Product B” if “Product A” is in my cart.
    Everthing looks good.

    However, i need to use a multipackage plugin to split my cart because each product category has differents shipping method.

    Once i installed the multipackage plugin, i have an issue with shipping rate cache and not really effective refresh/update.
    Each action in my cart (remov a product, update quantity, and else), i want/need to purge all the shipping cache and refresh all my cart.

    I found that in Woocommerce shipping options into, we can enable “debug mode” wich “bypass shipping rate cache.”, when i enable this debug mode, everything’s working great.

    Do you know a way to bypass shippint rate cache ?
    I tried so many solution that doesn’t work… πŸ™

    Thanks for your help, i really need it.

    1. Hi Simon thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. Tested with Divi default theme and works like a charm. Thanks for sharing!

  10. Great solution! I’ve a question. How can i do this with 2 different shipping classes?
    I tried to add the same code again and a different shipping_class_target, but that did not work.

    I want to do this for 2 specific shipping classes.

    1. Hello JJ, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  11. Hello,
    this snippet worked properly, but after update to the new Woocommerce 4.6 it was stopped. Do you know, what could be an arror?
    Thank you in advance!!! Your tutorial is very helpful for me πŸ™‚
    Jiri

    1. Still works, so must be something else. Try to empty your cart and test again

  12. Hey Rodolfo,
    thanks for this snippet, I’ve tweaked it a bit to unset some shipping methods depending on a shipping class of items in the cart. I just have a quick question though :
    Is it possible to unset all shipping methods that contains the same term all at once rather than look for each value individually ?
    In fact I have prints for sale and so I’ve set some shipping methods for orders including prints and some for orders whitout. Therefore all my shipping methods for prints have a value ending with “_print” when the others have a value ending with “_classique”.

    My goal is to disable all shipping methods ending with “_classique” when a product with the “print” shipping class in the cart and vice versa.
    I’ve randomly tried this but it didn’t work :

    function businessbloomer_hide_regular_shipping_method( $rates, $package ) {
    	$shipping_class_target = 35; // shipping class ID (to find it, see screenshot in @sourcecode)
    	$in_cart = false;
    	foreach( WC()->cart->get_cart_contents() as $key => $values ) {
     		if( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) {
      		$in_cart = true;
      		break;
     		}
    	}
    	if( $in_cart ) { // shipping method with ID (to find it, see screenshot in @sourcecode)
    		unset( $rates['classique'] ); // France
    	}
    	else{
    		unset( $rates['print'] ); // France
    
    	}
    	return $rates;
    }
    

    If I put the right value of the shipping methods instead of $rates[‘print’] or $rates[‘classique’] it does work though.

    I have a lot of shipping methods / zones so this would really help rather than looking for all values individually.
    Thank you !

    1. Hi Alexis, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  13. You are the man!
    Second time your snippets provided a starting solution for me!

    1. Great!

  14. Rodolfo i don’t know if you’re italian, but i really would like to thanks couse yours snippets are teaching a lot to me REALLY THANKS πŸ™‚

    1. Ahah yes I am!

      1. ok, your function have inspired me.
        i think you can easy find my solution.
        yes, off course, i know, it’s custom work πŸ™‚ if you want to do it tell me please how i can ask it to you.
        sorry for my english, i’m sardinian, it was at least 15 years i don’t use any codes or any programmation language. i need you πŸ™‚

        1. Yes, your function has a few PHP errors. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  15. this fails when user updates their address in checkout.

    not sure if it’s related, but i’m using target class id = 0 since that works for my application (disallow free shipping if anything in cart that does not fit single class).

    thanks.

    1. ahhh please disregard.

      i was echoing commented out product info (how i found that no shipping class assigned = 0) and left it in there. maybe the added code being sent was causing the issue. at least that’s what it seems like.

      thanks for the script. works perfectly for what I need. you can delete comment if you want.

      1. Great!

  16. Is there a way to unset two different shipping rates in the same function?

    1. Hey Falco, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  17. Hi Mr Rodolfo Melogli,

    I have a question here, is it possible to set that if certain shipping class product is in the cart, it only ship to New York, United States while the other states will not allow to purchase/ship if that particular shipping class product is in the cart.

    Thank you so much.

    1. Hello Su, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  18. Hi,

    I need a fairly simple solution:
    If parcel is less than 1.6kg show flat rate option.
    If parcel is greater than 1.6kg do not show flat rate option.

    I’ve tried to modify your code but having problems!

    Can you help please ?

    Best regards

    John

    1. Hello John, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  19. IS it possible to setup shipping classes example freight and that item can only be shipped to United States?

    1. Hello Tom, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  20. Hello,

    Thank you for this article, but I think you need to update him, because it doesn’t work if you set free shipping on order over $XX.

    Example:
    If you have two classes, “shipping class exclude free” ($9,99*[qty] Ship. fee) and “none class” ($10 Ship. fee) with free shipping on order over $20, Ship. cost = $29,99 instead of $9,99 (If you have 1 product exclude to shipping and 2 others products)

    1. Stan, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  21. Rodolfo: Can you give an example of this in an array? I would like to be able to use this for multiple items but cannot get it to work.

    1. Kevin, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  22. hi I found this snippet but is not working for me I mean I have a custom plugin and I am prettly sure that I am not putting the id in a right way if you can help

    1. Hey Sam, thanks so much for your comment! Unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  23. Hi! Thank you so much for this code. It works perfectly when the class is in the cart with another class. However, if the class is the cart alone, it can’t find the shipping method. If I add it to the same shipping zone, when the class is not in the cart the $0.00 shows. My shipping class is for free shipping and I’m trying to hide the $0.00 option in the cart when free shipping items are not in the cart.

    1. Hey Kamilah, thanks for your comment! My snippet works even with only one product in the cart, so there must be something else πŸ™‚

  24. Hey Rodolfo,

    I’ve got this set up on a site but need to add multiple shipping zones to check for and then exclude free shipping. I have it working when I just have one shipping class, but is three a way to add multiple classes to check for?
    I tried the following, but it didn’t work, I’m assuming it needs to be done differently:

    $shipping_class_target = 37; // shipping class ID (to find it, see screenshot below)
    $shipping_class_target = 36; // shipping class ID (to find it, see screenshot below)
    $shipping_class_target = 44; // shipping class ID (to find it, see screenshot below)

    When I do this, it seems to offer free shipping to everyone rather than exclude it.
    Is there another way to check for all three and then if one of them is present, not show free shipping option.

    Thanks πŸ™‚

    1. Hey Sarah, thanks for your comment πŸ™‚ In the way you put it, $shipping_class_target overrides itself and only stores 44. Instead, you should turn $shipping_class_target into an array() and then slightly change the function to look into an array (with the in_array() function). Hope this helps πŸ™‚

  25. This had worked for a while, but it seems to have stopped after the latest update where they turned the shipping settings to “legacy”. I think they no longer have ID’s connected to the classes? <input name="shipping_method[0]" data-index="0" id="shipping_method_0_legacy_flat_rate"

    1. Hello Ashton! That “legacy” thing looks weird to me, never seen it before. Please see screenshot in this page to find shipping ID

  26. Unfortunately, this did not work for me. Still gives the free shipping option even when an item with the ‘free shipping’ class isn’t in the cart.

    1. Hey Danny – thanks so much for your comment! This snippet disables a rate if the Cart contains a shipping class – if it doesn’t it does nothing πŸ™‚

  27. All I want to do is choose the shipping method when creating a product. When I click the dropdown under shipping and choose USPS, I want checkout to display calculated shipping and NOT free shipping. If I choose Free Shipping, I want checkout to display free shipping NOT calculated. Why is this so difficult??? Why do shipping zones? What’s the point of choosing a shipping class if it doesn’t even matter??

    1. Hey Anthony – thanks so much for your comment! Please try ask this to WooCommerce support team πŸ™‚

  28. Hi Rodolfo & team – thanks for your enthusiasm!
    Woo 3.3.5 / Flatsome: Can this problem be solved with a snippet (rather close to the issue above):
    When buying a product from a specified shipping class, e.g. heavy items (alternative: a specified “pick up” product category) , all other shipment methods except “pick up at stock” have to be eliminated visually on the checkout page. Meaning that only the “pick up” possibility is left on the checkout page, when 1 item (or more) from the “heavy class” is chosen – even if there are items from other shipping classes.

    1. Hey Egon, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  29. You saved 40 buck on Booster and a lot of stress :)) I’m not technical but with these tutorials feeling like backender πŸ˜€ Can’t thank you enough, awesome!

    1. Eheh awesome πŸ™‚

  30. Awesome! Just saved me a load of stress!

  31. HI Rodolfo
    How would that snippet look if you want the opposite e.g Enable free shipping if cart has a specific item or shipping class?

    1. Paul, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  32. You guys are grate. I loved this tutorial. Thank you for good stuff. BTW it works on WooCommerce 3.2.6 and wordpress 4.9.1

  33. Hey,
    Thanks for all the work you have done with this snippet!
    I have multiple shipping totals to use for each product, and i’m trying to use your code to remove the shipping options I don’t want to see for multiple classes.
    Unfortunately your code was designed with only one shipping option calculator in mind, so it hides the shipping options from both!
    Is there any way to set it to run for individual shipping calculations?

    1. Hey Dan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  34. Hi Rodolfo, This snippet work perfectly for us. Thank you for all your work πŸ™‚

    Just wanted to know if you can help on the following scenario;

    – If the cart has multiple products, 1 product with the shipping class in your template already, but another product or products with other shipping classes – how do we then show those shipping classes in your CODE. We then want the free shipping to be unset since the other shipping class products has a flat rate cost and doesn’t belong to the free shipping delivery option hence the customer needs to pay for for delivery now for the products with the other shipping classes.

    With your help and this code, we know how to unset the shipping methods, but can’t figure out the above.

    Thank you!

    1. Hey Rodrigo, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  35. Works great! Avada theme v5.2.2, php 7.0.20, WordPress 4.8.3, Woocommerce 3.2.3
    Used it (modified) to exclude rush shipping method when used with a specific shipping class (a heavy item). It excludes the “Rush shipping” option whenever an item from the heavy item class is in the cart, regardless of other cart contents.

    Thank you!

  36. Does the php snippet work with a Child Theme functions.php? The file looks different, doesn’t have the”?>” at the end.
    Also what are these numbers ( 10, 2 ) for?
    I`m using a 3rd party plugin called table rate shipping. Will this code snippet work with that shipping method?
    I used this code and it did not work.

    1. Hey Chris, thanks so much for your comment! In answer to your questions:

      1. Yes, it works on a child theme
      2. The child theme functions.php file does not require the “?>” at the end
      3. The (10,2) numbers are required when using add_filter
      4. I don’t know if this snippet works with other plugins, this works for default WooCommerce

      Hope this helps a little πŸ™‚

    2. Hi, I’ve got it working with Table Rate Shipping but I had to ‘unset’ every rate…

      if( $in_cart ) {
       unset( $rates['mh_wc_table_rate_plus_85'] );
       unset( $rates['mh_wc_table_rate_plus_1' ] );
       unset( $rates['mh_wc_table_rate_plus_2' ] );
       unset( $rates['mh_wc_table_rate_plus_3' ] );

      etc

      Now I’m looking to find out whether you can only unset the rate if every item in the cart has the specified shipping class, so if it doesn’t, I don’t want to exclude the other rates, any ideas??

  37. Is this possible to modify for ‘virtual’ products?

    I have a problem of a free shipping threshold that gets triggered when there is a mix of ‘virtual’ and ‘physical’ products.

    I only want ‘physical’ products to trigger the free shipping and can’t seem to find anything on this…your article is as close as it comes.

    1. Mac, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. Hi, I have the same problem as Mac above. I don’t want free shipping to be triggered if a customer has a mixed order of physical and virtual products. Is there a solution possible?

      1. Hello Iris, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  38. Hello Rodolfo,

    I used this snipet:

    With chrome it worked perfectly, but not with firefox and internet explorer. Can you help me?

    Thanks,
    Holger

    1. Holger, thanks so much for your comment! PHP is browser-independent, so try clearing the browser cache. Only thing I can think of πŸ™‚

  39. Thanks for the code! But I’ll throw you a curve ball. I’ve split my cart into two packages using some php. Essentially, I have products that can have free shipping (among other rates), and products that cannot have free shipping. Therefore I two packages to get separate rates for.

    How do I unset free shipping for only one of the two packages, the one containing $shipping_class_target?

    1. Hey Raymond, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  40. Worked for me perfect on Woocommerce 3.1.1 version. Excellent! You saved me $99 US Dollars

  41. Hi Rodolfo,

    I just found your blog today and you got my attention, lots valuable content.

    I have a situation that’s unique but maybe you can suggest if this could work or not.

    In woocommerce we have only one zone (USA) and one class (Free), flat rate class is there too but no product is using that class.
    Unique situation is that we have Dokan vendor installed so basically vendor is able to override shipping with their own per product if they choose.

    Problem is on checkout customer still gets option of main Woo Free shipping along with vendor shipping.
    My question is how could I remove main Woo shipping option so cart displays only vendor shipping?

    My thought is I can either would have remove default Woo shipping from the cart completely (not sure how)

    Or other thought was to setup shipping class call it “Vendor” class, let vendors select it and if that class is in the cart remove our “Free” shipping as an option using your code snippet.

    What do you think?

    Thank you so much for your time.

    1. Damir, thanks for your comment! I suggest you ask this question to Dokan support πŸ™‚

  42. Very great article, however in my case, i want to unset cash on delivery if a product among the products in a cart belongs to a specific shipping class.
    Please can you guide me through.
    Cause i don’t want to make a silly mistake.
    my code

    function pekky_unset_gateway_by_shipping_class($available_gateways){
    global $woocommerce;
    $shipping_class_target = 15; // shipping class ID (to find it, see screenshot below)
    $in_cart = false;
    
    foreach ($woocommerce->cart->cart_contents as $key => $values ) {
    if( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) {//we've found the suspect we're looking for
      $in_cart = true;
      break;//pull out
     } 
    }
    if($in_cart == true){//since it's true, it belongs to the suspect shipping class
        unset( $available_gateways['cod'] );//remove cod.
    }
         
     }
        return $available_gateways;
    }
    
    add_filter('woocommerce_available_payment_gateways','pekky_unset_gateway_by_shipping_class');
     
    
    1. Is that my snippet? πŸ™‚

    2. lol, sort off, yh, but a little editted. i tried it the way i wrote the code, but it seems not to work, when a product which belongs to the shipping class in the cart, it still shows the cash on delivery option.
      Is it because cash on delivery is the only enabled payment?

    3. hey, just checked it out again, it’s working, thanks for your time and tutorial, i really love learning more about how woocommerce works in the code way

  43. Exactly what I was looking for. Thanks! It works perfectly.

  44. Hi,

    I am looking for a code to:
    Disable flat rate shipping to a specific country if the cart has a product with a specific shipping class.
    So in that case only the pick up options stays visible.
    Hope you can help me out…

    Kind regards,
    Debby

    1. Debby, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  45. Hello, not working for my Woocommerce 3.0.8 anymore.
    It was working before.
    Any advice? =)

    1. Hey Pavel, thanks for your comment! If you switch theme does that work?

  46. Hi Rodolfo,
    Thanks for your excellent WooCommerce code snippets!
    Is it possible to target multiple shipping classes with this snippet, rather than just a single shipping class, in:
    $shipping_class_target = SingleID;

    1. Joe, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  47. This worked for me thank you. But it required that I have a second shipping method in a particular zone which always shows even when free shipping is available. Is there anyway around that? If an item in the cart has my excluded from free shipping class it only shows the second method which is great but how do i make it so one or all of the items in my cart are all free shipping items only the free shipping method is displayed? In other words if free shipping is available I only want to show free shipping.

    1. Hey Nicholas, thanks for your comment πŸ™‚ I’m a little confused :O – could you provide a few screenshots as I can’t understand if this is custom to your specs or is a bug in my code? Thanks!

  48. I need to hide free shipping per product based on location when shipping cost is available on the cart/chectout page. How can i do that.

    1. Eric, thanks for your comment! Unfortunately this is custom and cannot give an answer here on the blog comments – thanks for your understanding πŸ™‚

  49. Good day! Big thanks for awesome info, very usefull and uniqe. Can you help me with code to hide specific shipping method when all products in cart with shipping class?

    1. Alex, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  50. Great code snippet.
    I have it working for one shipping zone.
    Is it possible to have it for two different shipping zones?

    I currently have ‘free_shipping:12’

    But I need to also have it apply to ‘free_shipping:11’

    Thanks so much

    1. Hey SArah, thanks for your comment! You can just add another “unset” line under the existing one – let me know πŸ™‚

  51. Placed the code in my functions.php and it breaks my entire site. What a waste of time.

    1. Hey Joe, thanks for your comment and sorry about your negative experience! I just tried the snippet and it works without breaking my website, so there must be something else that is conflicting or you haven’t pasted the right thing in your functions.php. If you activate WP_DEBUG, what error displays on the screen? Thank you!

  52. Hello Rodolfo Melogli..

    Firstly I thank you so much for what you have done so far by helping many people across the world solving their issues with woocommerce. At a point you have inspired me to get into the deeper cores of woocommerce.

    I have used the snippet to “Disable Free Shipping (for a Specific Shipping Zone) if Cart has Product with Specific Shipping Class”, and it worked pretty fine as well. But what i actually want is to disable standard shipping cost also when a product with a shipping class is added to the cart, and I want to display only the shipping class cost. (I want this to happen when only a shipping class product is being purchased individually).

    Let me explain…

    Say for example I have products = ProWSC (Product with shipping class), ProNSC (Product with No shipping class)
    My standard shipping cost is 30, and that for shipping class is 50.

    And now, if i add ProNSC to cart, it shows 30 (working fine)
    then, If i add both ProWSC and ProNSC to cart, it shows 80 (working fine)
    and now, if i add only proWSC to cart, it again is showing 80. ( I want it to display only 50 instead).

    Why actually I want to do so is, my products with shipping classes are above 1000 INR (indian Rupees) for which I offer free shipping. But they are heavy as well. That is why I want to charge them the shipping class charges.

    1. Hey Samrat, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  53. Can I post my question here? If yes then..

    Lets say two products of my products as 1)SMALL PRODUCT and 2)BIG PRODUCT.

    I don’t want to charge shipping rate for SMALL PRODUCT if user buys both SMALL PRODUCT and BIG PRODUCT at once.

    How ever I want to charge shipping rate for SMALL PRODUCT if he is not buying the BIG PRODUCT. (ofcourse there are other products also in cart along with these)

    How can i achieve this?

    1. and the shipping method is live FedEx.

    2. Hey Mounika, thanks for your comment! This is pretty custom so unfortunately I can’t give you a fix right now. By the way, have you tried assigning the shipping class to the BIG product and use my snippet, which would disable free shipping if the BIG product is in the cart?

  54. Hello, Rodolfo

    Thank you for sharing this useful information.

    This worked for me on 2.6+ version. I have disable free shipping on some shipping classes. I have a question, how can I disable “No Shipping Class” because it’s show up in the cart and checkout page like two shipping methods. Have a look here: https://puu.sh/qBBj7/4a593e93dd.jpg

    For free shipping products I setted them without any shipping class & it’s show the title of flat rate as shown in screenshot. Is there any way to hide “No Shipping Class”?

    Thanks in advance!

    Regards

    1. Hello Abd Ur, thanks for your comment!

      If that shipping option has no shipping “class”, it must be a shipping “rate”. Free shipping is a shipping “rate” for example, and so is “flat_rate”.

      Just find the name of the rate (e.g. “shipping_rate_name”) and then:

      unset( $rates['shipping_rate_name'] );
      

      Hope this helps

      1. Thanks for response! I did fix this problem found useful info from docs Woo Theme. I’m just wondering why I didn’t get notification when you replied to my message. I came here just to look for response.

        Once again thanks!

        Regards,

        1. Excellent, great to know. Re: email, I have no idea – it could be you entered the wrong email address or that it went to spam maybe? Try again πŸ™‚

          1. Email is fine. I get notification about moderation but not about comment post. This too I came here to have a look.

            Well the important thing is problem is solved.

            Thanks

  55. With the new WooCommerce version (2.6.1) the shipping class id cannot be found this way anymore. Do you have another suggestion? Many thanks

    1. Thanks for your feedback Natascha – I’ll take a look and revert πŸ™‚

      1. Please let me know as well!!

        1. Will do David – thanks for the reminder πŸ™‚

        2. Updated! Let me know πŸ™‚

          1. Excellent! Didn’t get a notification either… I just found out I had already wrote a comment here πŸ™‚

            Great work Rodolfo! Thanks for sharing!

            1. Ah, weird! Awesome πŸ™‚

    2. Updated! Let me know πŸ™‚

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *