Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Created December 3, 2014 10:07
Show Gist options
  • Save msmithstubbs/0999e82fb9ee2ce83325 to your computer and use it in GitHub Desktop.
Save msmithstubbs/0999e82fb9ee2ce83325 to your computer and use it in GitHub Desktop.
Back In Stock Product page form with mailing list checkbox
<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