Skip to content

Instantly share code, notes, and snippets.

@cargix1
Last active June 27, 2022 12:54
Show Gist options
  • Save cargix1/fdecb654aaf21118ce4e08e30c6a0952 to your computer and use it in GitHub Desktop.
Save cargix1/fdecb654aaf21118ce4e08e30c6a0952 to your computer and use it in GitHub Desktop.
Custom delivery validator widget
<form onsubmit="validateZipCode(); return false;">
<input type="text" id="zipcode" placeholder="Enter zipcode here ..." />
<input type="submit" value="Go" />
</form>
<script type="text/javascript">
function validateZipCode(e) {
const zipcode = document.getElementById('zipcode').value;
if (typeof window.Zapiet === 'undefined' || typeof window.ZapietCachedSettings === 'undefined' ||
typeof window.Zapiet.DeliveryValidator === 'undefined' || window.ZapietCachedSettings.cached_config === 'undefined' ||
window.ZapietCachedSettings.cached_config.delivery_validator === 'undefined') {
console.warn('Zapiet - Custom delivery validator error. Please ensure you have Store Pickup + Delivery correctly installed. Contact [email protected] for assistance.');
return false;
}
Zapiet.DeliveryValidator.checkEligiblity(zipcode, function(response) {
// Eligible callback
Zapiet.DeliveryValidator.eligibleForDelivery(response);
}, function() {
// Not eligible callback
Zapiet.DeliveryValidator.notEligibleForDelivery();
}, function() {
// Error callback
Zapiet.DeliveryValidator.error();
});
return false;
}
</script>
@TavorSummits
Copy link

Hi, could this be adapted to accept an address instead of a zip code?
The SPD cart validator support address and Google autocomplete and doing the same for the custom validator will be a huge improvement.
What would be the cost of modifying as such?

@procarrera
Copy link

First, congratulations for this amazing article and documentation.
really hard to see App's giving such a good support like this to others Devs

Upvote for the suggestion above

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment