Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aatronco/94eb3283050a0f5b097e5473d800663c to your computer and use it in GitHub Desktop.
Save aatronco/94eb3283050a0f5b097e5473d800663c to your computer and use it in GitHub Desktop.
<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