Excluding Dutch Islands from shipping

  • Posts: 2
  • Thank you received: 0
  • Hikashop Business
5 hours ago #373028

-- HikaShop version -- : 6.5.2
-- Joomla version -- : 5.4.7.
-- Browser(s) name and version -- : Ecosia

Hi,

I am trying to exclude the Dutch Islands from shipping. I only want to ship to The Netherlands for now, but want to make sure that people from the Dutch Islands can't order (due to too high shipping fees).

Their postcodes numbers are:

1791–1797
8880–8889
8890–8891
8899
9160–9164
9166

I think I should use the "Postcode RegEx" field for this? But I can't get it to work.
I filled in this code:

#^(?!88(8[1-9]|9[0-6]|99)|916[1-3]|9166)\d{4}$

And this code:

#^(?!179[1-7]|888[1-4]|8899|916[1-4]|9166)\d{4} ?[A-Z]{2}$

but both don't work. When I do this, every single address does not work anymore.

Let me be clear: I don't really understand what I am doing in this regard, I have asked a GPT to generate the codes to fill in. But both don't work so I am stuck now.

Can you help me to exclude these postcodes from my shipping methods?

Thanks in advance!

Please Log in or Create an account to join the conversation.

  • Posts: 86027
  • Thank you received: 14170
  • MODERATOR
1 hour 23 minutes ago #373029

Hi,

The "Postcode RegEx" field is passed as-is to PHP's preg_match, so it has to be a complete pattern, delimiters included. Both of your patterns open with a # but never close it, so PHP rejects the pattern as invalid and the shipping method is then hidden for every address, which is the "every single address does not work anymore" you're seeing.

The other thing to know is how the field is evaluated: the method is kept only when the postcode matches the pattern. So it is an "allow" test, which means your negative-lookahead idea (allow everything except the islands) is exactly the right approach, it just needs the closing delimiter.

Based on the postcodes you listed (1791-1797, 8880-8889, 8890-8891), this works:

#^(?!179[1-7]|888\d|889[01])\d{4}#

It matches any 4-digit postcode that does not start with one of those island ranges, and it does not care about the trailing letters (like 1234 AB), so it works whether or not the letters are stored in the address. Put it on your Netherlands shipping method and the island postcodes will no longer be offered that method.

If you also want to exclude the Ameland / Schiermonnikoog codes you had in your test (9161-9166), add them the same way:
#^(?!179[1-7]|888\d|889[01]|916[1-6])\d{4}#

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum