How can I display dynamic EAN codes on product pages?

Hi everybody. I have been searching for how to display SKU code and EAN code on the product pages. I found a way to make those 2 codes display on the product page BUT EAN code is not changing when you select a different variant

SKU code changes with no issues.

Does anybody know how to make it change as SKU does?

This is the code (product.liquid):

{% assign current_variant = product.selected_or_first_available_variant %}
SKU: {{ current_variant.sku }} |
EAN: {{ current_variant.barcode }}

It will be through custom js in your theme. SKU is changing because there is already a code in the theme to do that, to change EAN on variant change, you have to update in your theme/custom js
Thanks!

1 Like

how can I do that?

You can check the code in your custom/theme/global JS for SKU and do the same for EAN
Also, Please share store and product url (Password as well if store is password protected) so that I can look more into this
Thanks!

1 Like

Thanks. https://bravepaws.co.uk/products/deneme-can

Please try this

In theme.js
After the line: this.currentVariant = variant;

Put this code

if(variant.sku){

document.querySelector('.variant-sku').innerHTML = variant.sku;
}
if(variant.barcode){

document.querySelector('.variant-barcode').innerHTML = variant.barcode;
}

Thanks!

1 Like

Really thank you so much.