[vc_cta h2=”The Below Code Works for the Following Plugins:”]
- WooCommerce UPS Shipping plugin
- ELEX WooCommerce DHL Express / Paket Shipping plugin
- WooCommerce FedEx Shipping plugin
- ELEX WooCommerce USPS Shipping plugin
- WooCommerce Canada Post Shipping plugin
- ELEX WooCommerce Stamps.com USPS Shipping plugin
- ELEX WooCommerce Australia Post Shipping plugin
- WooCommerce Multi-Carrier Shipping plugin
- WooCommerce Table Rate Shipping Pro plugin
- ELEX EasyPost (UPS, USPS & FedEx) Shipping plugin
- ELEXtensions.com Shipping Plugins
[/vc_cta]
The below code snippet can be used to hide shipping methods based on whether shipping classes are present in cart or not.
Add the following code to your functions.php or anywhere relevant.
If you are looking for a plugin do this job, visit ELEX Hide Shipping Methods Plugin. Using this plugin, You can easily hide shipping methods based on various conditions.
– If shipping ID “42” is present in cart, then the snippet will hide “Free Shipping”.
– If shipping ID “42” is not present in cart, then the snippet will hide these services :
‘wf_shipping_ups:03’, – UPS Ground
‘wf_shipping_ups:02’, – UPS 2nd Day Air
‘wf_shipping_ups:01’ – Ups Next Day Air
-If shipping ID “43” is not present in cart, then the snippet will hide “Free Shipping”.
What do i mean by shipping ID “42” and “43”?
Don’t worry. To make it simple, developers use Shipping IDs to map shipping classes in code.
How do I map it?
You can to Products –> Shipping Classes and you will find the corresponding Shipping ID for a shipping class as shown in the two screenshots below :
What about shipping methods? I cannot understand the code that is to be used in the code snippet.
No Problem. You can easily find the service by the following method :
– Go to the cart page and fetch the rates for an order as shown below :
In the screenshot below, you can see “UPS Next day Air Early AM”. Take the mouse pointer just above the service name, do a right click and then click on inspect.
A small wintom of the page. You can find the service code from here.
Use this code if you want to hide this shipping method for a particular shipping ID/Class.
Hi Author,
can we hide Hide Shipping methods in case of multiple shipping packages.
Regards
Don
Hi Besty,
can you please resolve my problem.
Regards
Don