Add postcode reset to checkout.
This commit is contained in:
@@ -26,7 +26,8 @@ class PrijsPerPostcode
|
||||
public function init()
|
||||
{
|
||||
$uri = $_SERVER["REQUEST_URI"];
|
||||
if_needed_place_postcode_form($uri);
|
||||
add_filter("woocommerce_sale_flash", "__return_null");
|
||||
init_postcode_handlers($uri);
|
||||
|
||||
//add_action("template_redirect", [$this, "redirect_if_missing_tag"]);
|
||||
add_action(
|
||||
@@ -56,67 +57,6 @@ class PrijsPerPostcode
|
||||
$this,
|
||||
"controleer_postcode_op_woocommerce_paginas",
|
||||
]);
|
||||
add_action("wp_footer", [$this, "set_checkout_fields_with_javascript"]);
|
||||
}
|
||||
|
||||
public function set_checkout_fields_with_javascript()
|
||||
{
|
||||
if (
|
||||
!is_checkout() ||
|
||||
(is_wc_endpoint_url() && !is_wc_endpoint_url("order-received"))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$woonplaats = $_SESSION["woonplaats"];
|
||||
$postcode = $formatted_postcode = preg_replace(
|
||||
"/(\d+)([A-Z]+)/",
|
||||
'$1 $2',
|
||||
strtoupper($_SESSION["postcode"]),
|
||||
);
|
||||
$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';
|
||||
|
||||
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: ''
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
$('#shipping-postcode, #shipping-city, #shipping-address_1')
|
||||
.prop('readonly', true)
|
||||
.css('background', '#f9f9f9');
|
||||
}, 500);
|
||||
|
||||
jQuery(document.body).trigger('update_checkout');
|
||||
} else {
|
||||
console.error('WooCommerce Blocks API is niet beschikbaar');
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function add_local_price_field($loop, $variation_data, $variation)
|
||||
|
||||
Reference in New Issue
Block a user