Created
November 16, 2018 22:43
-
-
Save whistlerbrad/4c72e4507284bce1647b6a40935d2a9d to your computer and use it in GitHub Desktop.
Remove specific variants
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
{% comment %} | |
Remove specific variants. | |
{% endcomment %} | |
{% if product.options.size == 1 %} | |
<script> | |
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() { | |
{% for variant in product.variants %} | |
{% if variant.title == "XL" %} | |
jQuery('.single-option-selector option').filter(function() { return jQuery(this).text() === {{ variant.title | json }}; }).remove(); | |
{% endif %} | |
{% endfor %} | |
jQuery('.single-option-selector').trigger('change'); | |
observer.disconnect(); | |
}); | |
observer.observe($addToCartForm[0], config); | |
} | |
</script> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment