const zakekeButtonSelector = ".zakeke-button" window.addEventListener("load", function(event) { const els = document.body.querySelectorAll(zakekeButtonSelector); els.forEach(handleZakeke) }); function handleZakeke(el) { const originalHref = el.getAttribute("href") const box = el.closest('[data-pf-type="ProductBox"]') const pfvariants = $(box).find('[data-pf-type="ProductVariant"]') const selects = pfvariants.find("select") const inputs = pfvariants.find("input") const pfKey = Array.from(box.classList).find(item => item.includes("pf-")) const productId = box.getAttribute("data-product-id") function handleChange () { const currentVariant = __pageflyProducts[productId].pfCurrentVariant[pfKey] // custom code below el.setAttribute("href", originalHref + "&id=" + currentVariant.id) } if (__pageflyProducts && __pageflyProducts[productId]) { selects.change(handleChange) inputs.change(handleChange) } handleChange() }