Opencart 4 · 5 min read · Updated

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.

Opencart 4 postcode delivery checker

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).

OpenCart 4 iPhone product page with a Check delivery to your area box under the add to cart button, showing a green message: Good news: we deliver to 11215 in 1-2 business days
The box sits under the add to cart button.

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.
Postcode checker box with a red message: Sorry, we don't deliver to 90210 yet
No area matched 90210, so the “not delivered” message is shown.

Install the extension

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

Settings

Postcode Delivery Checker settings in OpenCart 4 admin with three delivery areas: 10001-10099 and 112*, SW1* and EC1A 1BB, and 0*, 1*, 2*, each with its own message
Delivery areas are checked from top to bottom.

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:

EntryMatches
10001Only 10001
10001-10099Every 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 1BBOnly 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:

TypedResult
10001, 10099Row 1: 1-2 business days (range)
11215Row 1: 1-2 business days (prefix 112*)
10100Row 3: 3-5 business days (outside the range, matches 1*)
1005Row 3: a four-digit postcode never matches a five-digit range, so it fell through to 1*
sw1a 1aa, SW1A1AARow 2: London, shown back as “SW1A 1AA” and “SW1A1AA”
ec1a-1bbRow 2: the exact entry EC1A 1BB
EC1A2BB, 90210Not 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.

Postcode delivery checker on a phone-sized OpenCart 4 product page with 10001 checked
On a 390 px wide phone screen.

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.
Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *