Hide Shipping Method When Cart Contains Shipping Class

A popular request over the last several months, some items simply do not qualify for one of your shipping methods. For example, you could not send large scale pieces of furniture via regular services such as UPS, so you may opt to remove this choice when a customer purchases small items in addition to a furniture item. The best way to go about this is to assign your large pieces of furniture a special shipping class that denotes it is too large for regular shipping.

The code snippet below removes the ‘Free Shipping’ method from the list of available choices if the cart contains any items belonging to the ‘Bulky Items’ shipping class.

You may have seen that the shipping method ID in the above example is a little different. It contains the instance ID ‘7’, which tells the code exactly which option to remove. This is good if you have multiple Free Shipping methods available and only wish to remove one. If you would like to remove all options from any Free Shipping method, try the example below:

  • Was this article helpful ?
  • yes   no