Created
December 3, 2014 10:07
-
-
Save msmithstubbs/0999e82fb9ee2ce83325 to your computer and use it in GitHub Desktop.
Back In Stock Product page form with mailing list checkbox
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
<div> | |
<label for="bis-email">Email me when available</label> | |
<input type="email" id="bis-email"> | |
<label> | |
<input type="checkbox" id="bis-accepts-marketing"> | |
Add me to the store mailing list | |
</label> | |
<button id="bis-submit">Email when available</button> | |
</div> | |
<script> | |
$('#bis-submit').on('click', function(e) { | |
e.preventDefault(); | |
var email = $('#bis-email').val(), | |
variant = $('[name=id]').val(), | |
productId = BISPopover.product.id, // if you're not on a product page this will need to be specified | |
options = { | |
accepts_marketing: $('#bis-accepts-marketing').is(':checked') | |
}; | |
BISPopover.create(email, variant, productId, options).then(function(data) { | |
var msg = ''; | |
if (data.status == 'OK') { | |
msg = data.message; // just show the success message | |
} else { // it was an error | |
for (var k in data.errors) { // collect all the error messages into a string | |
msg += data.errors[k].join(); | |
} | |
} | |
alert(msg); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment