0

Very simple use case, using only flat rate shipping, with version 2 of Drupal Commerce Shipping and Drupal Commerce Flat Rate. I have two shipping options customers can choose between if they are in one country (the UK) and two if they're in any other country. Let's call them:

  • UK standard
  • UK special
  • International standard
  • International special

I've looked for ways to switch shipping rates on and off using rules, but all I can find is rules that apply a particular shipping rate, not rules which enable or disable options that the customer can then choose between.

This related question gives a faint outline of how to apply rates, but not how to enable or disable options, and likewise this related question, where there are 12 options but all are chosen for the customer (and the answers simply say "use rules"). Under the Calculation Rules tab under admin/commerce/config/shipping/services/flat-rate, I can't see anything in the "actions" list that looks like it enables or disables a particular rate. Plenty that appear to apply a rate, but not giving the customer a choice or limiting the choice.

This is clearly common and possible, as it's referred to for example in this issue, but I can't find anything on how to do it.

I've tried adding a rule like this through "Configure component" for a particular shipping rate, but it had no effect, the international rate still appears as an option even if the country is "United Kingdom". Here's the rule:

enter image description here

Here's another I tried using "Calculation rules" which, also had no effect:

enter image description here

Everything I can find around enabling or disabling shipping by country is about disabling countries completely.

I couldn't find anything in the Commerce Shipping documentation, and there is no Flat Rate documentation.

2

The two crucial pieces of information:

  • The "Configure component" link alongside each shipping rate under admin/commerce/config/shipping (Store > Configuration > Shipping) is the place to set validation criteria for a shipping rate to appear as an option.
  • In these rules, countries need to be inputted as two-letter country codes not the full names.

In detail:

  • Set up the shipping rates and go to admin/commerce/config/shipping (Store > Configuration > Shipping)
  • For each one:
    • Follow the "Configure Component" link
    • "Add condition"
    • Commerce Order > Order Address Component Comparison
    • Address value = Shipping Address, Address Component = Country, and tick the Negate box at the very bottom if this is one for "everywhere but" (e.g. international rates)
    • Input the 2-letter country code under Value. You can see what this is by using Inspect Element on a country selector dropdown:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.