-
-
Save msmithstubbs/9544398 to your computer and use it in GitHub Desktop.
Example of Back In Stock form with MailChimp checkbox
This file contains hidden or 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
| <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