Created
September 8, 2021 18:56
-
-
Save aatronco/94eb3283050a0f5b097e5473d800663c to your computer and use it in GitHub Desktop.
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
<script> | |
$(document).ready(function() { | |
// Get the variant_id from the parameter | |
const queryString = window.location.search; | |
const urlParams = new URLSearchParams(queryString); | |
if (urlParams.has('variant_id')) { | |
const variant_id = urlParams.get('variant_id') | |
console.log('-------> '+variant_id) | |
var update_function = function(data) { | |
// Find the variant | |
active_variant = data.variants.find(item => item.id == variant_id) | |
// Choose each option of the variant | |
jQuery.each(active_variant.options, function(i, item) { | |
$('select[name=' + "'" + item.name + "'" + '] option').filter(function() { | |
return $(this).html() == item.value; | |
}).prop("selected", true) | |
}); | |
// Force a ntive change event | |
selects = document.getElementsByClassName("prod-options"); | |
jQuery.each(selects, function(i, select) { | |
select.dispatchEvent(new Event("change")); | |
}) | |
}; | |
// Get Current Product info and apply callback | |
Jumpseller.getCurrentProductInfo({ | |
callback: update_function | |
}) | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment