Show SKU numbers on product pages - Dawn 2.0

Topic summary

Users are seeking methods to display SKU numbers (and variant SKUs) on product pages in Shopify’s Dawn 2.0 theme. The original poster found existing documentation but it only applied to vintage themes, not Dawn 2.0.

Working Solution (Posts #5-6):

  • Add custom Liquid code block to display SKU/barcode fields
  • Modify global.js file by locating the onVariantChange() function and adding updateSku() and getSku() functions
  • This enables SKUs to update dynamically when customers select different product variants without page refresh

Extensions & Variations:

  • Solution successfully adapted to also display barcodes (post #6)
  • Can be extended to show inventory quantities using variant.inventory_quantity (posts #7-8)
  • Works with any variant attributes from Shopify’s Liquid API

Recent Issue (Posts #24-25):

  • In Dawn 2.0.15+, the onVariantChange() line no longer exists in global.js
  • Code comments indicate this was intentionally refactored (line 757)
  • Multiple users report the solution no longer works on current Dawn versions
  • Status: Unresolved - community seeking updated workaround for latest Dawn theme versions

Minor Issues Resolved:

  • Zero inventory displaying as blank (post #10-11)
  • SKU disappearing for non-first variants (post #21)
  • Products with only SKU or only barcode not displaying correctly (post #22)
Summarized with AI on November 3. AI used: claude-sonnet-4-5-20250929.

Can anyone help on a easy way to display the SKU details for products and variants on default product page in Dawn 2.0 please??

I found this but it stated not 2.0

https://help.shopify.com/en/manual/online-store/themes/themes-by-shopify/vintage-themes/customizing-vintage-themes/show-sku

Hey,

If you edit the theme code and go to Sections → main-product.liquid you will see code relating to product properties e.g.

{{ product.description }}

and

{{ product.title }}

Simply add the product / variant attributes that you want to display in there.

May this help you. Click Here

thanks, i was aware of this page, however not the specifics of the code for the DAWN 2.0 theme to get the product SKU to update with the variants? any advise appreciated

Select your theme

The next steps for this customization vary depending on your theme. Click the button for your theme and follow the instructions.

If you haven’t figured out yet, with the skus changing when clicking different options, check out this post below from @Alan15 It worked for me and many others too!!

For the Dawn theme, add this code to the main-product.liquid file , directly to the code after the title, or add it to a custom block as described above:

<div class="hideAll">
    <p><span>SKU: </span><span class="sku"></span></p>       
</div>

{% capture 'variant_sku' %}       
    {% for variant in product.variants %}
        {{variant.id}}:{{ variant.sku| json }}
        {% unless forloop.last %},{% endunless %}           
   {% endfor %}
{% endcapture %}  
        
<script>
  const currentVariantSku = {{ product.selected_or_first_available_variant.id }};
  const variantSku = { {{ variant_sku }} };        
  const getSku = (id) => {
  let selector = document.querySelector('.sku');
  let hide = document.querySelector('.hideAll')
    if (variantSku[id]) {
     hide.style.display = 'block'
     selector.innerHTML = variantSku[id];
    }
    else 
     hide.style.display = 'none'
  }
  getSku(currentVariantSku);

</script>

You then need to update the global.js file in the Assets folder. Find the code beginning with onVariantChange() , it should be around line 740. Update it to look like this:

 onVariantChange() {
    this.updateOptions();
    this.updateMasterId();
    this.toggleAddButton(true, '', false);
    this.updatePickupAvailability();
    this.removeErrorMessage();

    if (!this.currentVariant) {
      this.toggleAddButton(true, '', true);
      this.setUnavailable();
    } else {
      this.updateMedia();
      this.updateURL();
      this.updateVariantInput();
      this.renderProductInfo();
      this.updateShareUrl();
      this.updateSku();
    }
  }
  
 updateSku() {
	  getSku(this.currentVariant.id);
  }

  updateOptions() {
    this.options = Array.from(this.querySelectorAll('select'), (select) => select.value);
  }   

I’ve added

this.updateSku();

and

updateSku() {
getSku(this.currentVariant.id);
}

to the existing code.

This should update the SKU variant value without a page refresh.

If you only need the first 4 numbers of the SKU, change the javascript code above to be:

selector.innerHTML = variantSku[id].substring(0,4);
7 Likes

Well this needs bumping. Spent weeks trying to figure out how to add variant SKUs and Barcodes to product pages and this solves it.

Added more detail below, to also include barcodes, basically still follows Alan15’s post from https://community.shopify.com/c/shopify-design/sku-id-on-dawn/m-p/1472513#M387714

  1. Add the below to a Custom Liquid block in theme editor (I put mine within the Product Information block).

    

SKU:  Barcode: 

       

{% capture 'variant_barcode' %}       
    {% for variant in product.variants %}
        {{variant.id}}:{{ variant.barcode| json }}
        {% unless forloop.last %},{% endunless %}           
   {% endfor %}
{% endcapture %}

{% capture 'variant_sku' %}       
    {% for variant in product.variants %}
        {{variant.id}}:{{ variant.sku| json }}
        {% unless forloop.last %},{% endunless %}           
   {% endfor %}
{% endcapture %}

        

  1. In global.js (found in code editor for theme, under Assets), find the “onVariantChange() {” line, and update it to the following. Basically adds this.updateSku and the updateSku function, and again for barcode.
onVariantChange() {
    this.updateOptions();
    this.updateMasterId();
    this.toggleAddButton(true, '', false);
    this.updatePickupAvailability();
    this.removeErrorMessage();

    if (!this.currentVariant) {
      this.toggleAddButton(true, '', true);
      this.setUnavailable();
    } else {
      this.updateMedia();
      this.updateURL();
      this.updateVariantInput();
      this.renderProductInfo();
      this.updateShareUrl();
      this.updateSku();
      this.updateBarcode();
    }
  }
  
 updateSku() {
	  getSku(this.currentVariant.id);
  }
  
  updateBarcode() {
	  getBarcode(this.currentVariant.id);
  }

  updateOptions() {
    this.options = Array.from(this.querySelectorAll('select'), (select) => select.value);
  }

And that should be it. Barcodes and SKUs now updating on variant selection in product pages on OS 2.0, thanks to Alan15 and Madiasdomain :slightly_smiling_face:

3 Likes

Thats perfect, any idea how to do the same thing to show a variants inventory stock quantity?

Yup; you can do it with any of the variant attributes shown in https://shopify.dev/api/liquid/objects/variant

So just duplicate everything for eg. barcode, and change the word barcode to inventory_quantity.

for the noobs:


    

SKU:  Barcode: 

       

{% capture 'variant_barcode' %}       
    {% for variant in product.variants %}
        {{variant.id}}:{{ variant.barcode| json }}
        {% unless forloop.last %},{% endunless %}           
   {% endfor %}
{% endcapture %}

{% capture 'variant_sku' %}       
    {% for variant in product.variants %}
        {{variant.id}}:{{ variant.sku| json }}
        {% unless forloop.last %},{% endunless %}           
   {% endfor %}
{% endcapture %}

{% capture 'variant_inventory_quantity' %}       
    {% for variant in product.variants %}
        {{variant.id}}:{{ variant.inventory_quantity| json }}
        {% unless forloop.last %},{% endunless %}           
   {% endfor %}
{% endcapture %}

        

onVariantChange() {
    this.updateOptions();
    this.updateMasterId();
    this.toggleAddButton(true, '', false);
    this.updatePickupAvailability();
    this.removeErrorMessage();

    if (!this.currentVariant) {
      this.toggleAddButton(true, '', true);
      this.setUnavailable();
    } else {
      this.updateMedia();
      this.updateURL();
      this.updateVariantInput();
      this.renderProductInfo();
      this.updateShareUrl();
      this.updateSku();
      this.updateBarcode();
      this.updateInventoryQuantity();
    }
  }
  
 updateSku() {
	  getSku(this.currentVariant.id);
  }
  
  updateBarcode() {
	  getBarcode(this.currentVariant.id);
  }

  updateInventoryQuantity() {
	  getInventoryQuantity(this.currentVariant.id);
  }

  updateOptions() {
    this.options = Array.from(this.querySelectorAll('select'), (select) => select.value);
  }
3 Likes

Thats great! Thank you

We have implemented it and works great, apart from if an item is down to 0 then it goes blank. Any other figure, even minus figures show up perfectly (and we want it to so thats great), but if something is 0 then its not appearing. Any ideas? I want it to show 0 if possible.

You’d have to play around with it but it might have something to do with the following:

if (variantInventoryQuantity[id]) {
     hide.style.display = 'block'
     selector.innerHTML = variantInventoryQuantity[id];
    }
    else 
     hide.style.display = 'none'
  }

This hides the inventory text if the inventory quantity is blank/null/doesnt exits/maybe 0? In which case…

if (variantInventoryQuantity[id]) {
     hide.style.display = 'block'
     selector.innerHTML = variantInventoryQuantity[id];
    }
    else 
      hide.style.display = 'block'
     selector.innerHTML = '0';
  }

Not sure if that code’s quite right either, or if that’s the actual issue, but may work?

1 Like

This works BRILLIANTLY!!!

I am also adding a “Contact us for more info” email button to the product page (via a custom block), and I’d like the variant.sku to update in the Subject line of the button.

So, to reiterate, I have your code in a custom block, and in ANOTHER custom block I have the following lines

[
**{{ 'products.product.enquire' | t }}**

](mailto:sales@xxx.com?subject=Shop enquiry - {{ product.title }} - {{variant.sku }}>
<button type=)

And I’d really like it if the same global.js and script could update the email subject SKU with the correct SKU for the one chosen… Any ideas? Because the original code uses , I don’t see how I can use that in the Subject line.

Thanks for the solution. Simple and working so well. Thanks.

Brilliant work. Clear step by step instruction. Hats off. Thank you.

This works only for vintage theme not applicable for 2.0 themes like Dawn

Not true - works brilliantly in Dawn 2.0.

1 Like

I solved my issue, and using the code from this thread as a basis it now updates sku displayed on the page, in the email link, and it updates the product weight shown on the page.

Took a bit of figuring out with the email link, but got there in the end.

Dawn is a lovely theme to customise!

I can confirm that this solution works perfectly in Dawn 2.0

Thanks Mate! works like a charm. :heart_eyes:

:blush: :+1: