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

How to display variant SKU on product page (horizon theme)

How to display variant SKU on product page (horizon theme)

SDBdigital
Shopify Partner
92 0 18

How do I display the variant SKU below the product price?

Using Horizon theme.

https://lunamar.co.za

 

Replies 5 (5)

Guleria
Shopify Partner
4299 825 1189

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


 

- Elevate Your Store with Expert Shopify Services. Email: guleriathakur43@gmail.com - Need a quick fix or a tailored customization? I’ve got you covered.
- Looking to enhance your pages? Try GEMPAGES- a powerful drag & drop page builder.
- Let’s make your store stand out. Get in touch today!
- My Apps: Productify Groups – Smart product grouping made easy.

AiTrillion
Shopify Partner
4265 250 754

Hi @SDBdigital ,

 

You can add a snippet in the customization section.

 
{{ product.first_available_variant.sku }}
 
Sachin D | Shopify Growth Expert @ AiTrillion

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- 10+ Years of eCommerce experience.
- 1400+ Stores Designed on Shopify.
- All in One Marketing App on Shopify AiTrillion Marketing Automation
.
- 13+ Shopify Apps launched on app store.
SDBdigital
Shopify Partner
92 0 18

Hi

 

I inserted the code using a custom liquid block - the sku displays - but does not update/change when selecting a different variant.

 

AiTrillion
Shopify Partner
4265 250 754

@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>

Sachin D | Shopify Growth Expert @ AiTrillion

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- 10+ Years of eCommerce experience.
- 1400+ Stores Designed on Shopify.
- All in One Marketing App on Shopify AiTrillion Marketing Automation
.
- 13+ Shopify Apps launched on app store.
SDBdigital
Shopify Partner
92 0 18

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)