change <?php to <<<HTML
This commit is contained in:
@@ -31,17 +31,20 @@ function modal_styles()
|
||||
|
||||
function show_modal()
|
||||
{
|
||||
?>
|
||||
<script id="postcode_modal">
|
||||
echo <<<'HTML'
|
||||
<script id="postcode_modal_open">
|
||||
const postcodeModal = document.querySelector("#postcode_modal");
|
||||
postcodeModal.showModal();
|
||||
</script>
|
||||
<?php
|
||||
HTML;
|
||||
}
|
||||
|
||||
function send_postcode_data()
|
||||
{
|
||||
?>
|
||||
$URL = get_rest_url(null, "postcode-modal/v1/submit");
|
||||
$nonce = wp_create_nonce("wp_rest");
|
||||
|
||||
echo <<<HTML
|
||||
<script type="module">
|
||||
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('<?php echo get_rest_url(
|
||||
null,
|
||||
"postcode-modal/v1/submit",
|
||||
); ?>', {
|
||||
const resp = await fetch('{$URL}', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-WP-Nonce': '<?php echo wp_create_nonce(
|
||||
"wp_rest",
|
||||
); ?>'
|
||||
'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()
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
HTML;
|
||||
}
|
||||
|
||||
function render_dialog_html()
|
||||
{
|
||||
?>
|
||||
echo <<<'HTML'
|
||||
<dialog id="postcode_modal" class="postcode_modal" closedby="none">
|
||||
<h2>Vul je postcode en huisnummer in.</h2>
|
||||
<p>Onze prijzen zijn afhankelijk van de regio. Vul daarom de postcode en het huisnummer in om de exacte prijzen te bekijken.</p>
|
||||
@@ -186,7 +182,7 @@ function render_dialog_html()
|
||||
</form>
|
||||
<div class="error_message_modal_postcode" id="error_message_modal_postcode" aria-live="polite"></div>
|
||||
</dialog>
|
||||
<?php
|
||||
HTML;
|
||||
}
|
||||
|
||||
function has_postcode()
|
||||
@@ -409,62 +405,63 @@ function modify_checkout_with_js()
|
||||
);
|
||||
$address =
|
||||
$_SESSION["straatnaam"] . " " . strtoupper($_SESSION["huisnummer"]);
|
||||
// Output the JavaScript
|
||||
?>
|
||||
<script type="text/javascript" id="fill_address_fields">
|
||||
jQuery(document).ready(function($) {
|
||||
fillCheckoutFields();
|
||||
$(document.body).on('updated_checkout', fillCheckoutFields);
|
||||
});
|
||||
|
||||
function fillCheckoutFields() {
|
||||
if (typeof wp !== 'undefined' && wp.data && wp.data.dispatch) {
|
||||
const store = 'wc/store/cart';
|
||||
echo <<<HTML
|
||||
<script type="text/javascript" id="fill_address_fields">
|
||||
jQuery(document).ready(function(\$) {
|
||||
fillCheckoutFields();
|
||||
\$(document.body).on('updated_checkout', fillCheckoutFields);
|
||||
});
|
||||
|
||||
wp.data.dispatch(store).setShippingAddress({
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
address_1: '<?php echo esc_js($address); ?>',
|
||||
address_2: '',
|
||||
city: '<?php echo esc_js($woonplaats); ?>',
|
||||
state: '',
|
||||
postcode: '<?php echo esc_js($postcode); ?>',
|
||||
country: 'NL',
|
||||
phone: '',
|
||||
email: ''
|
||||
});
|
||||
function fillCheckoutFields() {
|
||||
if (typeof wp !== 'undefined' && wp.data && wp.data.dispatch) {
|
||||
const store = 'wc/store/cart';
|
||||
|
||||
//make fields READONLY and ppstcode reset.
|
||||
setTimeout(() => {
|
||||
// make prefilled fiields readonly.
|
||||
$('#shipping-postcode, #shipping-city, #shipping-address_1')
|
||||
.prop('readonly', true)
|
||||
.css('background', '#f9f9f9');
|
||||
wp.data.dispatch(store).setShippingAddress({
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
address_1: '{$address}',
|
||||
address_2: '',
|
||||
city: '{$woonplaats}',
|
||||
state: '',
|
||||
postcode: '{$postcode}',
|
||||
country: 'NL',
|
||||
phone: '',
|
||||
email: ''
|
||||
});
|
||||
|
||||
// create postcode reset button
|
||||
const div = document.createElement("div");
|
||||
const script = document.createElement('script');
|
||||
div.setAttribute("class", "postcode-reset")
|
||||
div.innerHTML = `
|
||||
<a href="#" class="reset-postcode-show-comfirm" >Reset postcode.</a>
|
||||
<span class="bevestiging"> Deze handeling leegt ook de winkelwagen. Weet je het zeker?
|
||||
<a href="#" class="accept"> JA </a>/<a href="#" class="decline"> nee </a>
|
||||
</span> `;
|
||||
div.style.width = "100%";
|
||||
document.querySelector(".wc-block-components-address-form__city").after(div);
|
||||
}, 500);
|
||||
//make fields READONLY and ppstcode reset.
|
||||
setTimeout(() => {
|
||||
// make prefilled fiields readonly.
|
||||
\$('#shipping-postcode, #shipping-city, #shipping-address_1')
|
||||
.prop('readonly', true)
|
||||
.css('background', '#f9f9f9');
|
||||
|
||||
// create postcode reset button
|
||||
const div = document.createElement("div");
|
||||
div.setAttribute("class", "postcode-reset")
|
||||
div.innerHTML = `
|
||||
<a href="#" class="reset-postcode-show-comfirm" >Reset postcode.</a>
|
||||
<span class="bevestiging"> Deze handeling leegt ook de winkelwagen. Weet je het zeker?
|
||||
<a href="#" class="accept"> JA </a>/<a href="#" class="decline"> nee </a>
|
||||
</span> `;
|
||||
div.style.width = "100%";
|
||||
document.querySelector(".wc-block-components-address-form__city").after(div);
|
||||
}, 500);
|
||||
|
||||
|
||||
jQuery(document.body).trigger('update_checkout');
|
||||
} else {
|
||||
console.error('WooCommerce Blocks API is niet beschikbaar');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
jQuery(document.body).trigger('update_checkout');
|
||||
} else {
|
||||
console.error('WooCommerce Blocks API is niet beschikbaar');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function load_assets_reset_postcode_on_checkout()
|
||||
{
|
||||
if (is_checkout() && !is_wc_endpoint_url()) {
|
||||
|
||||
Reference in New Issue
Block a user