Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Created March 14, 2014 09:03
Show Gist options
  • Select an option

  • Save msmithstubbs/9544398 to your computer and use it in GitHub Desktop.

Select an option

Save msmithstubbs/9544398 to your computer and use it in GitHub Desktop.
Example of Back In Stock form with MailChimp checkbox
<label>Email me when available</label>
<input type="email" id="notify_email" />
<input type="checkbox" id="notify_opt_in" value="Yes" /> Opt-in in for
email newsletter
<button id="notify_button">Email when available</button>
<script>
var notificationCallback = 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);
}
$('#notify_button').click(function(e) {
e.preventDefault();
var email = $('#notify_email').val(),
productId = {{product.id}},
variantId = {{product.variants.first.id}}; // rendered by Liquid
var options = {
accepts_marketing: $('#notify_opt_in').is(':checked')
};
BISPopover.create(email, variantId, productId, options).then(notificationCallback);
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment