Postcode Delivery Checker for OpenCart 4: “Do You Deliver to My Area?” Answered on the Product Page (Free Extension)
A free OpenCart 4 extension that adds a postcode checker under the add to cart button, with delivery areas as exact postcodes, numeric ranges and prefixes.

If you only deliver to some areas, shoppers find out at the worst moment: in checkout, after they have filled in their address. Local grocers, furniture stores, florists and anyone with their own vans get the same question by phone and chat every day: “Do you deliver to 11215?” An OpenCart 4 postcode delivery checker answers before checkout.
The free Postcode Delivery Checker answers it on the product page. The shopper types a postcode, clicks Check and gets your message for that area, such as “Good news: we deliver to 11215 in 1-2 business days.” You set the delivery areas as postcode lists, numeric ranges and prefixes. This OpenCart 4 postcode delivery checker was built and tested on OpenCart 4.1.0.4 with the Webocreation Theme.
Download: postcodecheck.ocmod.zip (tested on OpenCart 4.1.0.4).

What the OpenCart 4 postcode delivery checker does
- Adds a “Check delivery to your area” box under the add to cart button on product pages.
- Checks the postcode against your delivery areas from top to bottom and shows the message of the first area that matches.
- Shows your “not delivered” message when no area matches.
- Understands exact postcodes (10001), numeric ranges (10001-10099) and prefixes (112* or SW1*). Spaces, dashes and letter case are ignored, so “sw1a 1aa”, “SW1A1AA” and “SW1A-1AA” are the same postcode.
- Remembers the last postcode in the shopper’s browser and checks it again on every product page they open.
- Hides itself on products that don’t ship, such as downloads and gift cards.

Install the extension
- Download postcodecheck.ocmod.zip. Don’t unzip it.
- Go to Extensions > Installer, click Upload and choose the zip.
- Click the green Install button next to “Postcode Delivery Checker”.
- Go to Extensions > Extensions, choose Modules, find Postcode Delivery Checker and click Install.
- Click Edit, replace the sample delivery areas with your own, switch Status on and click Save.
Settings

Delivery areas
Each row has a list of postcodes and the message shown for them. Use {postcode} in the message to repeat what the shopper typed. Separate postcodes with commas or new lines:
| Entry | Matches |
|---|---|
10001 | Only 10001 |
10001-10099 | Every number from 10001 to 10099 with the same number of digits |
112* | Every postcode that starts with 112 |
SW1* | UK postcodes in the SW1 district, such as SW1A 1AA |
EC1A 1BB | Only EC1A 1BB, written with or without the space |
The first match wins, so put your small, fast areas above the wide ones. In the example above, a Brooklyn postcode such as 11215 matches 112* in the first row and gets “1-2 business days”, even though the third row’s 1* would also match it.
Product page box
- Box title: the heading of the box.
- Not delivered message: shown when no area matches. It can use
{postcode}too. - Only on shipped products: hides the box when the product’s Requires Shipping setting is No. In the demo store the MacBook is set up that way, and the box didn’t appear on it.
- Remember the postcode: keeps the last checked postcode in the browser’s local storage and checks it again automatically. Nothing is stored on the server or in a cookie.
Saving refuses a row that has postcodes but no message, or the other way round, and you can’t switch the checker on without at least one delivery area. Fully empty rows are dropped.
What we tested
With the three areas from the screenshot saved, we sent these postcodes to the checker:
| Typed | Result |
|---|---|
| 10001, 10099 | Row 1: 1-2 business days (range) |
| 11215 | Row 1: 1-2 business days (prefix 112*) |
| 10100 | Row 3: 3-5 business days (outside the range, matches 1*) |
| 1005 | Row 3: a four-digit postcode never matches a five-digit range, so it fell through to 1* |
| sw1a 1aa, SW1A1AA | Row 2: London, shown back as “SW1A 1AA” and “SW1A1AA” |
| ec1a-1bb | Row 2: the exact entry EC1A 1BB |
| EC1A2BB, 90210 | Not delivered |
| (empty), x | “Enter your postcode.” |
On another product page the box filled in SW1A 1AA by itself and showed the London message, and Add to Cart worked as usual next to it.

How it works
The extension adds one event, catalog/view/product/product/after, which appends the box and a small script to the product page. The script moves the box right under the add to cart form and sends the postcode to the extension’s check route, which answers with JSON. The message is shown with textContent, so nothing the shopper types can inject HTML.
The check route cleans the input first. Request data in OpenCart arrives HTML-encoded, so it is decoded, then everything except letters, digits, spaces and dashes is removed and the result is cut to 12 characters. This is the matching code:
private function match(string $postcode, array $rules): ?array {
$code = $this->normalize($postcode);
foreach ($rules as $rule) {
$entries = preg_split('/[\s,;]*[,;\r\n]+[\s,;]*/', html_entity_decode((string)($rule['postcodes'] ?? ''), ENT_QUOTES, 'UTF-8'));
foreach ($entries as $entry) {
$entry = trim($entry);
if ($entry === '') {
continue;
}
if (preg_match('/^(\d+)\s*-\s*(\d+)$/', $entry, $range)) {
// Compare as numbers, but only postcodes of the same length: 1005 is not inside 10001-10099.
if (ctype_digit($code) && strlen($code) == strlen($range[1]) && (int)$code >= (int)$range[1] && (int)$code <= (int)$range[2]) {
return $rule;
}
continue;
}
$entry = $this->normalize($entry);
if (str_ends_with($entry, '*')) {
if (str_starts_with($code, rtrim($entry, '*'))) {
return $rule;
}
} elseif ($code === $entry) {
return $rule;
}
}
}
return null;
}
Ranges compare numbers only when the postcode has the same number of digits as the start of the range. Comparing as numbers drops leading zeros, so without that check a range such as 01000-01999 would also match a four-digit 1500. Prefixes and exact entries are compared after removing spaces and dashes on both sides.
Limitations
- The checker gives an answer. It doesn’t change shipping rates or stop checkout for an address you don’t serve. Shipping rates still come from your shipping extensions and geo zones, as set up in tax and geo zone setup for OpenCart 4.
- There is no country field. If you deliver to two countries whose postcodes look alike, use prefixes that can’t overlap.
- Messages are stored once, not per language.
- Postcodes with more than 12 characters are cut off. No country uses longer ones.
Related posts
- Estimated Delivery Date for OpenCart 4
- Delivery Time Slot Picker for OpenCart 4
- Store Locator for OpenCart 4
- Free Shipping Progress Bar for OpenCart 4







