diff --git a/session_dialog.php b/session_dialog.php index 8e74fcf..df5a5fd 100644 --- a/session_dialog.php +++ b/session_dialog.php @@ -31,17 +31,20 @@ function modal_styles() function show_modal() { - ?> - - + $URL = get_rest_url(null, "postcode-modal/v1/submit"); + $nonce = wp_create_nonce("wp_rest"); + + echo << const postcodeModal = document.querySelector("#postcode_modal"); const modalForm = document.querySelector("#postcode_modal_form"); @@ -74,17 +77,13 @@ function send_postcode_data() const payload = Object.fromEntries(formData.entries()); try { - const resp = await fetch('', { + const resp = await fetch('{$URL}', { method: 'POST', credentials: 'same-origin', + headers: { 'Content-Type': 'application/json', - 'X-WP-Nonce': '' + 'X-WP-Nonce': '{$nonce}' }, body: JSON.stringify(payload) }); @@ -108,13 +107,11 @@ function send_postcode_data() userErrorMessage = "Adres is niet gevonden."; } else if (errorCode === "HUISNUMMER_AMBIGUOUS") { - // Deze komt ALLEEN nog hier als PHP géén 'platte' match kon vinden. - // Dat betekent dat de gebruiker verplicht een toevoeging moet geven (bijv. alleen 15A bestaat). const suggestions = data.suggestions || []; - if (suggestions.length > 0) { - userErrorMessage = `Meerdere opties: ${suggestions.join(", ")}. Voeg een toevoeging toe.`; + if (suggestions.length > 0) { + userErrorMessage = `Meerdere opties: \${suggestions.join(", ")}. Voeg een toevoeging toe.`; } else { - userErrorMessage = "Huisnummertoevoeging is verplicht."; + userErrorMessage = "Huisnummertoevoeging is verplicht."; } } else if (errorCode === "CURL_ERROR" || errorCode === "JSON_ERROR") { @@ -131,7 +128,6 @@ function send_postcode_data() } } catch (err) { - console.error("Fetch Failed:", err); sndBtn.disabled = false; sndBtnLdr.style.opacity = "0"; sndBtnTxt.style.opacity = "1"; @@ -139,12 +135,12 @@ function send_postcode_data() } }); - + echo <<<'HTML'

Vul je postcode en huisnummer in.

Onze prijzen zijn afhankelijk van de regio. Vul daarom de postcode en het huisnummer in om de exacte prijzen te bekijken.

@@ -186,7 +182,7 @@ function render_dialog_html()
- - - + HTML; } + + + + function load_assets_reset_postcode_on_checkout() { if (is_checkout() && !is_wc_endpoint_url()) {