Change postcode_in_range() to work with admin page
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user