We have installed & tweaked the following widget that checks to see if postcodes are in our delivery areas, if not it auto redirects them to a page to register their interest.
<div id="deliverychecker-container" data-widget-id="166f5152dc8d7b"></div>
<script>
(function() {
const i = setInterval(function() {
const d = document.getElementById("deliverychecker-results");
if (!d) {
return;
}
const t = d.firstChild.firstChild.innerText.slice(0, 5);
if (t == "Sorry") {
clearInterval(i);
setTimeout(function() {
window.location = "/register-your-interest-261/";
}, 3000)
};
}, 1000);
var a = document.createElement("script");
a.type = "text/javascript";
a.async = !0;
a.src = "https://cdn.deliverychecker.co/api/v1/js/166f5152dc8d7b.js";
var b = document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a, b);
console.log(a);
console.log(b);
}());
</script>
The API calls an external db that has the postcodes in (a subset of PAF)
I now need to do the same thing on the WooCommerce chekout page to prevent people adding a different postcode that is out of area, but I can’t work out how to do so.
Note that we are using WooCommerce classic checkout (shortcode).
Any pointers please, I am stuck as to where to start.