Change postcode_in_range() to work with admin page
This commit is contained in:
@@ -116,7 +116,7 @@ function render_dialog_html()
|
|||||||
name="postcode"
|
name="postcode"
|
||||||
title="Voer een geldige Nederlandse postcode in (bijv. 1234AB of 1234 AB)."
|
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}"
|
pattern="[1-9][0-9]{3} ?(?!sa|sd|ss)[a-zA-Z]{2}"
|
||||||
placeholder="1010 AA"
|
placeholder="5010 AA"
|
||||||
size="10"
|
size="10"
|
||||||
required
|
required
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
@@ -272,6 +272,15 @@ function getStraatnaam($postcode, $huisnummer)
|
|||||||
|
|
||||||
function postcode_in_range($postcode)
|
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));
|
$cleanPostcode = strtoupper(preg_replace("/\s+/", "", $postcode));
|
||||||
|
|
||||||
if (!preg_match('/^\d{4}[A-Z]{2}$/', $cleanPostcode)) {
|
if (!preg_match('/^\d{4}[A-Z]{2}$/', $cleanPostcode)) {
|
||||||
@@ -280,10 +289,12 @@ function postcode_in_range($postcode)
|
|||||||
|
|
||||||
$numberPart = (int) substr($cleanPostcode, 0, 4);
|
$numberPart = (int) substr($cleanPostcode, 0, 4);
|
||||||
|
|
||||||
return ($numberPart >= 4800 && $numberPart <= 4899) ||
|
foreach ($pc_arr as $pc_to_check) {
|
||||||
($numberPart >= 5000 && $numberPart <= 5199) ||
|
if ($numberPart >= $pc_to_check[0] && $numberPart <= $pc_to_check[1]) {
|
||||||
($numberPart >= 5260 && $numberPart <= 5268) ||
|
return true;
|
||||||
($numberPart >= 5688 && $numberPart <= 5689);
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function modify_checkout_with_js()
|
function modify_checkout_with_js()
|
||||||
|
|||||||
Reference in New Issue
Block a user