Display product barcode

Highlighted
New Member
1 0 0

Hi guys. Please assist in advising how to go about displaying the barcode of each product on the front end. 

 

I have gotten the SKU to display

0 Likes
Highlighted
Shopify Partner
1445 195 525

How did you do the sku? I assume it's through the products variant. It's the same with the barcode.

 

{% for variant in product.variants %}
{{ variant.sku }}
{{ variant.barcode }}
{% endfor %}
If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Highlighted
Shopify Partner
3 0 1

just to add as it took me a good time to work out and I like to share things in case others have the same question. This is what you need to use in your structured data to display your gtin13 barcode.

 

this should be placed under

"@type": "Product",

 

{% if selected_variant.barcode != blank %}
"gtin13": {{ selected_variant.barcode | json }},
{% endif %}

 

test your product page with the structured data testing tool and look under product for your gtin13 details.

https://search.google.com/structured-data/testing-tool/u/0/

Highlighted
New Member
1 0 0

Hi, ive added this code into my template. but the sku and barcode are both on the same line. how can i make it so that they are on 2 seperate lines. sorry im new to all this coding. any help would be appreciated. 

 

thank you

0 Likes
Highlighted
Shopify Partner
3 0 1

you can wrap each element in a <div> tag

here is an example.

 

<div class="product-vendor" itemprop="gtin13">

the number would go here

 

</div>

<div  itemprop="sku">

what ever this is 

 

</div>

0 Likes
Highlighted
Tourist
8 0 5

If I choose a different color/size, the first barcode always shows. How can we get this to update with selected variants?

0 Likes
Highlighted
Tourist
8 0 5

Nevermind, I found a solution and will post it here to answer that exact question asked by another user.

0 Likes