Exclude shipping methods - Product and Country

As an example, let's say you have products that require "cold" shipping.  So, you offer both standard shipping and cold shipping, and you've set up different rates in the Fixed/ByWeight shipping provider.  If the cart contains any items that require cold shipping, then that's the only shipping method the customer can see.  Similarly, if the cart does not contain any items that require cold shipping, then Standard is the only shipping method the customer can see. 

Set up the two methods in Fixed/ByWeight:  Standard Shipping and Cold Shipping.  We'lI assume you've already accounted for the additional charge for Cold, so SD won't need to calculate the surcharge. 

SD will handle whether to show the Standard or Cold.  Addiitonally, let's set up some country restrictions that we can't cold ship to, and we'll put up an error message if the cart needs Cold, yet the country does not support it.  (Using the ErrorExit rule)

I recommend that you set up an unpublished category for the cold products. (Products can be in more than one category.)  For example, call the category "Cold Shipping".  Then we can detect if the cart contains items requiring cold shipping:  Items.Any(Product.HasCategory("Cold Shipping"))

We'll set up a variable for it:

Boolean

NeedsColdShipping

Items.Any(Product.HasCategory("Cold Shipping"))


The Option rule's Name Expression field can suppress a method when the expression evaluates to blank ("").  We use the ternary if-then-else operator ( ? : )  to evaluate whether the method for the cart should be Cold or Standard.  Only one method with show, never both.

(NOT [NeedsColdShipping] and [$Name].Contains("Cold")) OR ([NeedsColdShipping] and NOT [$Name].Contains("Cold")) ? "" : [$Name]

Finally, since we have two methods configured in Fixed/ByWeight, then normally it will return those two methods.  Yet since we have a Restriction set up on Country, it would only return one method if the country does not support cold shipping.  Shipping Director has a special variable that can be examined after another shipping rate provider is called - [$ShippingOptionsCount],  Thus if we check that variable, and it is equal to 1, then we know the country is restricted.  Thus if only 1 method is returned and also the cart requires Cold, we can use the ErrorExit rule to show the message.

ErrorExit

NoColdShippingForCountry

[NeedsColdShipping] and [$ShippingOptionsCount] = 1

"Sorry, your cart contains items requiring cold shipping, bu we cant do cold shipping for your country"

(Note that $ShippingOptionsCount is the actual count of returned other rate provider methods, not the count after any Name Expression exclusion.)

You can download the above configuration that you can then import into Shipping Director.

Comments
Leave your comment
:
yeemail97@gmail.com
Created on: 11/12/2021 10:14 AM
This is awesome but I cannot understand why if I press "Test" the output is right, but in the actual site in the cart there are always the 2 shippings method showing. Someone can help me?
support@nopTools.com
Created on: 11/13/2021 11:15 AM
Make sure that Shipping Director is the only Active shipping provider plugin.  (Check for a warning on the Shipping Director configuration page)
sample@email.tst
Created on: 6/26/2023 5:31 PM
1
sample@email.tst
Created on: 6/26/2023 5:31 PM
1