Shopify themes, liquid, logos, and UX
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hello @SDBdigital ,
Edit product template find for price existing code and just after it use this code
SKU: {{ product.selected_or_first_available_variant.sku }}
Or if the theme you are using support liquid block then use this code directly there.
Regards
Guleria
Hi @SDBdigital ,
You can add a snippet in the customization section.
{{ product.first_available_variant.sku }}
Hi
I inserted the code using a custom liquid block - the sku displays - but does not update/change when selecting a different variant.
@SDBdigital Yes, to update/change the price according to varient please copy the below code:
<script>
document.addEventListener("DOMContentLoaded", function () {
const variantSelector = document.querySelector('form[action^="/cart/add"] select[name="id"]');
const skuDisplay = document.getElementById("variant-sku");
if (variantSelector && skuDisplay) {
variantSelector.addEventListener("change", function () {
const selectedVariantId = this.value;
fetch(window.location.pathname + '.js')
.then(res => res.json())
.then(product => {
const variant = product.variants.find(v => v.id == selectedVariantId);
if (variant && variant.sku) {
skuDisplay.textContent = "SKU: " + variant.sku;
} else {
skuDisplay.textContent = "SKU: N/A";
}
});
});
}
});
</script>
Hi
I don't need the price to change.
I just want the variant SKU that is displayed below the titles to change when changing variants.
eg:
small (display SKU: xyz-small)
medium (display SKU: xyz-medium)