fix error messages, made redirects when postcode is unknown

This commit is contained in:
Remo Zaros
2026-05-11 09:19:50 +02:00
parent 782fee8ac4
commit 30b43a9396
2 changed files with 70 additions and 9 deletions

View File

@@ -12,6 +12,9 @@ function if_needed_place_postcode_form($uri)
add_action("wp_enqueue_scripts", "modal_styles");
add_action("wp_footer", "send_postcode_data");
if (!has_postcode()) {
if (!is_admin()) {
WC()->cart->empty_cart();
}
add_action("wp_footer", "show_modal");
}
}
@@ -65,7 +68,20 @@ function send_postcode_data()
console.log("Data returnd", data);
if (data.status === "error"){
const err = data.message;
let errmsg
switch (err) {
case "Huisnummer not found":
errmsg = "Adres niet gevonden.";
break;
case "Multiple addresses match this huisnummer; add huisletter and/or huisnummertoevoeging":
errmsg = "Huisnummertovoeging mist.";
break;
default:
errmsg = "Gegevens niet correct.";
}
document.querySelector("#error_message_modal_postcode").innerHTML = errmsg;
}
if (data.status === "success"){
@@ -108,7 +124,7 @@ function render_dialog_html()
<button id="postcode_modal_submit" type="submit">verzend</button>
</div>
<form>
<div class="error_message" id="error_message"></div>
<div class="error_message_modal_postcode" id="error_message_modal_postcode"></div>
</dialog>
<?php
}