From d4be70eb78971cb16342a497b70156cda4b3cf45 Mon Sep 17 00:00:00 2001 From: Remo Zaros Date: Tue, 19 May 2026 16:56:03 +0200 Subject: [PATCH] Change postcode_in_range() to work with admin page --- session_dialog.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/session_dialog.php b/session_dialog.php index fd265e3..c3bb69a 100644 --- a/session_dialog.php +++ b/session_dialog.php @@ -116,7 +116,7 @@ function render_dialog_html() name="postcode" title="Voer een geldige Nederlandse postcode in (bijv. 1234AB of 1234 AB)." pattern="[1-9][0-9]{3} ?(?!sa|sd|ss)[a-zA-Z]{2}" - placeholder="1010 AA" + placeholder="5010 AA" size="10" required autocomplete="off" @@ -272,6 +272,15 @@ function getStraatnaam($postcode, $huisnummer) function postcode_in_range($postcode) { + $vals = get_option("local_postcodes_values", ""); + $rows = preg_split("/\R/", $vals, -1, PREG_SPLIT_NO_EMPTY); + $pc_arr = []; + + foreach ($rows as $row) { + $row = trim($row); + $postcode_range = explode("|", $row); + $pc_arr[] = [(int) $postcode_range[0], (int) $postcode_range[1]]; + } $cleanPostcode = strtoupper(preg_replace("/\s+/", "", $postcode)); if (!preg_match('/^\d{4}[A-Z]{2}$/', $cleanPostcode)) { @@ -280,10 +289,12 @@ function postcode_in_range($postcode) $numberPart = (int) substr($cleanPostcode, 0, 4); - return ($numberPart >= 4800 && $numberPart <= 4899) || - ($numberPart >= 5000 && $numberPart <= 5199) || - ($numberPart >= 5260 && $numberPart <= 5268) || - ($numberPart >= 5688 && $numberPart <= 5689); + foreach ($pc_arr as $pc_to_check) { + if ($numberPart >= $pc_to_check[0] && $numberPart <= $pc_to_check[1]) { + return true; + } + } + return false; } function modify_checkout_with_js()