WooCommerce: Hide Shipping Rate If Variation ID Is In The Cart
Are you facing a situation where some of your WooCommerce product variations require different shipping options? Perhaps a bulky variation needs a special freight rate, while others can utilize standard shipping. The default settings might display all shipping methods for every variation, leading to confusion for your customers.
This blog post offers a solution! We’ll walk you through hiding shipping rates based on the variation ID in the cart. With clear explanations and an easy-to-follow code snippet, you’ll learn how to customize your store’s shipping experience for a more streamlined checkout process.
How to Find Variation IDs – WooCommerce
PHP Snippet: Disable Shipping Rate if Variation ID is in the Cart – WooCommerce
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: Remaining $$$ to Get Free Shipping Notification @ 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. So, here’s how we show a simple message on […]
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: Weight-Based Shipping Methods With WooCommerce you get 3 default shipping methods: Flat Rate, Free Shipping, Local Pickup. For each one you can define a cost, however there is no way to set up some “weight” restrictions. So, what if you want to display a rate for orders below 10 kg, and another shipping rate for orders above that […]
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 […]
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
18 thoughts on “WooCommerce: Hide Shipping Rate If Variation ID Is In The Cart”
Bradley Maravalli
What do I do if I want to also track the variation product quantity?
Hello Bradley, 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!
Juho, 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
Hi Rodolfo,
Thanks for sharing this this is exactly what I am looking for! Do you know whether this is still compatible with the latest version of Woocommerce to date?
Apologize for asking but my knowledge of coding is very basic and I don’t want to mess around with my webshop!
Thanks a million,
Greg
Greg, thanks for your comment! I strongly recommend to test this function (and all functions) on a clone version of your website – never on a live website. Let me know if it works ๐
Thanks for your feedback! Unfortunately it doesn’t work for me ๐
The shipping option is disabled for the Variation IDs I selected but when placed in the cart it is not possible to finalize the order as the “proceed to checkout” button is no longer available.
Have I missed something? Thanks!
Hey Greg, this snippet does not disable the proceed to checkout button so there must be some third party conflict. Sorry but I can’t help here via the blog comments. Thanks for your understanding ๐
Hi,
Thanks for this tutorial.
I am a developer, I am using BACS method for payment.
Can I show bank account based on the variable product?
Suppose I have the single product and my variable products are “A”, “B” and “C”.
So when user select “A” then he can only see my bank account “AC1”,
So when user select “B” then he can only see my bank account “AC2”,
So when user select “c” then he can only see my bank account “AC3”.
Please please help me.
Thanks in advance.
Hey MSD, thanks for your comment! Yes, you’ll first need to duplicate the BACS payment gateway (via PHP), and after that you can apply your rules. Unfortunately this is custom and I cannot help here in the blog comments. Thanks for your understanding!
I was wondering if you could assist with a variation of this.
I need to remove the “Calculate Shipping” button for either of the 2 conditions:
1. “Calculate Shipping” has already been clicked and used to calculate shipping
2. Free Shipping is applied through cart total or coupon
For me the “Calculate Shipping” link still appears after it’s been clicked. It also appears if free shipping has been achieved by the cart total reaching a threshold or a coupon code. It’s a little confusing to see it after there is already shipping values.
Im looking for a way to make a product have free shipping if a certain variation is selected. I sell an item in small. medium, large. Medium and Large should use fedex but small is free. But if someone adds a small and a large to the order, the small should remain free and the large should calculate shipping as normal… Any advise is welcome ๐
Hey thanks for your feedback! You should be able to do that by adding shipping class to your specific variations. You can check Woo documentation here. Hope this helps!
I am using the WooCommerce’s “Local Pickup Plus” Plugin. How would I eliminate certain Pickup Locations when certain Product Variations are in the cart? I want customers that purchase a specific variation to only be allowed to select from specific location. I believe this post is in the neighborhood of what I am looking for.
George thanks for your inquiry. This is unfortunately pretty custom and depends on the plugin code I think. The system would be pretty similar but the specific code would depend on the plugin. Sorry but I can’t help here ๐
How would I do this but just for a specific product ID, not a variation? Say for 2 or 3 different product Id’s if they are in the cart only allow local pickup or local delivery, so:
if product id: 100, or 101 is in cart:
disable flate rate, only allow local pickup or local delivery, can this be done?
James, thanks for your question. You can simply check for a specific product ID by using is_single(ID) where ID is the ID of the product. Hope this helps!
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!
What do I do if I want to also track the variation product quantity?
Hello Bradley, 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!
How to make this snippet work with WooCommerce Product Add-ons?
Juho, 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
Hi Rodolfo,
Thanks for sharing this this is exactly what I am looking for! Do you know whether this is still compatible with the latest version of Woocommerce to date?
Apologize for asking but my knowledge of coding is very basic and I don’t want to mess around with my webshop!
Thanks a million,
Greg
Greg, thanks for your comment! I strongly recommend to test this function (and all functions) on a clone version of your website – never on a live website. Let me know if it works ๐
Thanks for your feedback! Unfortunately it doesn’t work for me ๐
The shipping option is disabled for the Variation IDs I selected but when placed in the cart it is not possible to finalize the order as the “proceed to checkout” button is no longer available.
Have I missed something? Thanks!
Hey Greg, this snippet does not disable the proceed to checkout button so there must be some third party conflict. Sorry but I can’t help here via the blog comments. Thanks for your understanding ๐
Hi,
Thanks for this tutorial.
I am a developer, I am using BACS method for payment.
Can I show bank account based on the variable product?
Suppose I have the single product and my variable products are “A”, “B” and “C”.
So when user select “A” then he can only see my bank account “AC1”,
So when user select “B” then he can only see my bank account “AC2”,
So when user select “c” then he can only see my bank account “AC3”.
Please please help me.
Thanks in advance.
Hey MSD, thanks for your comment! Yes, you’ll first need to duplicate the BACS payment gateway (via PHP), and after that you can apply your rules. Unfortunately this is custom and I cannot help here in the blog comments. Thanks for your understanding!
Hey Rodolfo,
Loving your blog, thanks for this.
I was wondering if you could assist with a variation of this.
I need to remove the “Calculate Shipping” button for either of the 2 conditions:
1. “Calculate Shipping” has already been clicked and used to calculate shipping
2. Free Shipping is applied through cart total or coupon
For me the “Calculate Shipping” link still appears after it’s been clicked. It also appears if free shipping has been achieved by the cart total reaching a threshold or a coupon code. It’s a little confusing to see it after there is already shipping values.
Thanks!
Rob
Hey Rob, thanks for your comment! Are you suggesting here to remove the button via Ajax (on the same page, instantly, without refreshing the page)?
Im looking for a way to make a product have free shipping if a certain variation is selected. I sell an item in small. medium, large. Medium and Large should use fedex but small is free. But if someone adds a small and a large to the order, the small should remain free and the large should calculate shipping as normal… Any advise is welcome ๐
Hey thanks for your feedback! You should be able to do that by adding shipping class to your specific variations. You can check Woo documentation here. Hope this helps!
I am using the WooCommerce’s “Local Pickup Plus” Plugin. How would I eliminate certain Pickup Locations when certain Product Variations are in the cart? I want customers that purchase a specific variation to only be allowed to select from specific location. I believe this post is in the neighborhood of what I am looking for.
George thanks for your inquiry. This is unfortunately pretty custom and depends on the plugin code I think. The system would be pretty similar but the specific code would depend on the plugin. Sorry but I can’t help here ๐
How would I do this but just for a specific product ID, not a variation? Say for 2 or 3 different product Id’s if they are in the cart only allow local pickup or local delivery, so:
if product id: 100, or 101 is in cart:
disable flate rate, only allow local pickup or local delivery, can this be done?
James, thanks for your question. You can simply check for a specific product ID by using is_single(ID) where ID is the ID of the product. Hope this helps!