Scroll To Top
jQuery(document).ready(function($) {
function handleAutofill() {
setTimeout(function() {
var addressFilled = $('#billing_address_1').val() || $('#shipping_address_1').val();
var cityFilled = $('#billing_city').val() || $('#shipping_city').val();
var postcodeFilled = $('#billing_postcode').val() || $('#shipping_postcode').val();
if (addressFilled || cityFilled || postcodeFilled) {
$('input.address-field, input.country_to_state, select.country_to_state').trigger('change');
$(document.body).trigger('update_checkout');
if (typeof wc_checkout_form !== 'undefined') {
wc_checkout_form.trigger_update_checkout();
}
console.log('Autofill detected, shipping calculation triggered');
}
}, 1000);
}
document.addEventListener('autocomplete', handleAutofill);
var observer = new MutationObserver(function(mutations) {
for (var i = 0; i < mutations.length; i++) {
if (mutations[i].type === 'attributes' || mutations[i].type === 'childList') {
handleAutofill();
break;
}
}
});
var checkoutForm = document.querySelector('form.checkout');
if (checkoutForm) {
observer.observe(checkoutForm, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['value']
});
}
handleAutofill();
$(document).on('click', function() {
handleAutofill();
});
});