Forked from cargix1/zapiet-delivery-validator-custom.liquid
Created
March 22, 2022 16:32
-
-
Save procarrera/c5b4fd33b042a818aed09d3ddfcf2417 to your computer and use it in GitHub Desktop.
Custom delivery validator widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment