Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tobymarsden/96dc6d98b0d877c085a1b139709056ca to your computer and use it in GitHub Desktop.
Save tobymarsden/96dc6d98b0d877c085a1b139709056ca to your computer and use it in GitHub Desktop.
Hypervisual find in-stock variant in embed
window.HYPERVISUAL_CALLBACKS = window.HYPERVISUAL_CALLBACKS || {}
window.HYPERVISUAL_CALLBACKS.afterProductEmbed = function() {
var foundInStock = false
var variant
var data = JSON.parse(this.dataset.productJson)
for(var i = 0; i < data.variants.length; i++) {
variant = data.variants[i]
if(variant.available && !foundInStock) {
var option1 = this.querySelector('.hypervisual__embed_product-option-select[data-option-handle=option1')
if(option1) {
option1.value = variant.option1
option1.dispatchEvent(new Event("change"))
}
var option2 = this.querySelector('.hypervisual__embed_product-option-select[data-option-handle=option2')
if(option2) {
option2.value = variant.option2
option2.dispatchEvent(new Event("change"))
}
var option3 = this.querySelector('.hypervisual__embed_product-option-select[data-option-handle=option3')
if(option3) {
option3.value = variant.option3
option3.dispatchEvent(new Event("change"))
}
foundInStock = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment