Created
January 30, 2017 19:20
-
-
Save drabbytux/bb1d936ca6828965887f7e159f50b55a to your computer and use it in GitHub Desktop.
Hide variants that are sold out theme.js portion
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
/* Remove variants that are sold out in the dropdown */ | |
jQuery(document).ready(function(){ | |
if(typeof arr_titles_to_remove != 'undefined' ){ | |
var $addToCartForm = $('form[action="/cart/add"]'); | |
var i_title; | |
for (i_title = 0; i_title < arr_titles_to_remove.length; ++i_title) { | |
jQuery('.single-option-selector option').filter(function() { return jQuery(this).text() === arr_titles_to_remove[i_title] }).remove(); | |
} | |
jQuery('.single-option-selector').trigger('change'); | |
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() { | |
console.log('test 2'); | |
var i_title; | |
for (i_title = 0; i_title < arr_titles_to_remove.length; ++i_title) { | |
jQuery('.single-option-selector option').filter(function() { return jQuery(this).text() === arr_titles_to_remove[i_title] }).remove(); | |
} | |
jQuery('.single-option-selector').trigger('change'); | |
observer.disconnect(); | |
}); | |
observer.observe($addToCartForm[0], config); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will this not work in a sectioned theme?