SKU: {%- assign current_variant = product.selected_or_first_available_variant -%}
<span id='pf-variant-sku'>{{ current_variant.sku }}</span>
<script>
const elId = 'pf-variant-sku';
window.addEventListener("load", function(event) {
const el = document.getElementById(elId);
const box = el.closest('[data-pf-type="ProductBox"]')
const pfvariant = box.querySelector('[data-pf-type="ProductVariant"]')
const selects = $(pfvariant).find("select")
const inputs = $(pfvariant).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.innerHTML = currentVariant.sku;
}
if (__pageflyProducts && __pageflyProducts[productId]) {
selects.change(handleChange)
inputs.change(handleChange)
}
console.log("Tất cả các tài nguyên đã được tải nạp hoàn tất!");
});
</script>