Created
January 7, 2019 15:48
-
-
Save odessy/4cc6b2942a456f840450babfe7c69e1a to your computer and use it in GitHub Desktop.
remove variation code
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
| $( document ).ready(function() { | |
| if( typeof product_variants_removed != undefined ) { // was there items to be removed? | |
| var $addToCartForm = $('form[action="/cart/add"]'); | |
| if (window.MutationObserver && $addToCartForm.length) { | |
| if (typeof observer === 'object' && typeof observer.disconnect === 'function') { | |
| observer.disconnect(); | |
| } | |
| var config = { childList: true, subtree: true }; | |
| var observer = new MutationObserver(function() { | |
| product_variants_removed.forEach(function(item){ | |
| $('.single-option-selector option').filter(function() { return $(this).val() === item; }).remove(); | |
| }); | |
| observer.disconnect(); | |
| }); | |
| observer.observe($addToCartForm[0], config); | |
| $('.single-option-selector').trigger('change'); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment