Text on product page gets removed when switching variant (example: color or size)

Text on product page gets removed when switching variant (example: color or size)

TrendBlend
Trailblazer
338 0 34

https://codeshare.io/pAAolE this is my current code which results in this:

Schermafbeelding 2024-02-28 123036.png

 

But when I switch color (Grijs -> Zwart) for example all text is removed can anyone help me so that that doesn't happen? Thanks in advance

Replies 8 (8)

TrendBlend
Trailblazer
338 0 34

The text that gets deleted is this part

7C2A5488-F63E-402A-B4EF-521B819903A8.jpeg

so the text from the code but how can I make it that it doesn’t remove the text when changing variant? The text is not removed when refreshing

JohnE10
Shopify Partner
118 14 21

Hi,

 

I could be wrong, but I think a better way to add the text is by adding a custom liquid block to your product page template. It's easy to add one, it can be styled and made to look the way you want it, it can even be made dynamic in case you want to show different messages for different products, and It's sure to appear with all variants on the page.

 

Hope that helps.

If my reply was helpful, Like and Accept. Or Buy Me a Beverage
App Development/Custom Modifications, Visit My Gig and let me how I can help
For help with your store speed optimization, Check Out My Other Gig
Feel free to email with any questions: ProjectCoder10@gmail.com
TrendBlend
Trailblazer
338 0 34

Hello @JohnE10 do you also know if this can be achieved by some code in the main-product-page? Ive tried to add an eventlistener for when the variant changes but it did not work.

TrendBlend
Trailblazer
338 0 34

I mean main-product.liquid

JohnE10
Shopify Partner
118 14 21

I'm sure it could depending on the theme/code.

If my reply was helpful, Like and Accept. Or Buy Me a Beverage
App Development/Custom Modifications, Visit My Gig and let me how I can help
For help with your store speed optimization, Check Out My Other Gig
Feel free to email with any questions: ProjectCoder10@gmail.com
TrendBlend
Trailblazer
338 0 34

Yeah I got it by updating the product page when the url switches

TrendBlend
Trailblazer
338 0 34

Thanks for thinking with me tough

JohnE10
Shopify Partner
118 14 21

You bet. Good to hear you got it working.

If my reply was helpful, Like and Accept. Or Buy Me a Beverage
App Development/Custom Modifications, Visit My Gig and let me how I can help
For help with your store speed optimization, Check Out My Other Gig
Feel free to email with any questions: ProjectCoder10@gmail.com