Skip to content

Instantly share code, notes, and snippets.

@odessy
Created January 7, 2019 15:48
Show Gist options
  • Save odessy/4cc6b2942a456f840450babfe7c69e1a to your computer and use it in GitHub Desktop.
Save odessy/4cc6b2942a456f840450babfe7c69e1a to your computer and use it in GitHub Desktop.
remove variation code
$( 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