Update Variant Title When Selecting New Variant

Solved

Update Variant Title When Selecting New Variant

EnvisionWeb1
Tourist
8 1 3

In main-product.liquid I have added the following code to display the Variant title in a span tag above the variant pills:

 

<span class="size-value">
{% assign current_variant = product.selected_or_first_available_variant %}
{{ current_variant.title }}
</span>

 

EnvisionWeb1_0-1665790224919.png

 

How do I update the contents of this span tag when a different Variant pill is selected?

 

Thanks!

Accepted Solution (1)

EnvisionWeb1
Tourist
8 1 3

This is an accepted solution.

For anyone who has this issue here is the working code to be placed in the onVariantChange() function in global.js:

 

var checkedValue = document.querySelector('.product-form__input input:checked').value;
document.getElementById("size-value").innerHTML = checkedValue;

 

View solution in original post

Replies 4 (4)

PaulNewton
Shopify Partner
7721 678 1625

Varies wildly by theme and implementations.

You have to edit the themes relevant javascript variant selection functions.

Or add a listener for a the select change event to manipulate the text pulling the title info from the buttons html text.

 

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


EnvisionWeb1
Tourist
8 1 3

Thanks for the reply, I'm using Dawn 7.0 theme. Any guidance is appreciated!

Viraj2
Shopify Partner
3 0 0

You don't need to assign span for this you can access by theme javascript in global.js file you can find onVariant change function. 

EnvisionWeb1
Tourist
8 1 3

This is an accepted solution.

For anyone who has this issue here is the working code to be placed in the onVariantChange() function in global.js:

 

var checkedValue = document.querySelector('.product-form__input input:checked').value;
document.getElementById("size-value").innerHTML = checkedValue;