Update selected variant

Highlighted
New Member
2 0 0

Hi all,

I am currently using Shopify Buy Button code, and just embedding it in to my site. On page load, I have written some JavaScript to update the product that is selected in the SELECT dropdown.

 

$(".shopify-buy__option-select__select", $('iframe')[0].contentWindow.document).val('PRODUCT_VARIANT').trigger('change');

 

Now I would like to trigger the change event that causes Shopify's code to update the selected variant and load the image for that variant (i.e. I want it to behave as if a user came in an clicked this PRODUCT_VARIANT option in the dropdown.

 

Right now, the select dropdown shows the new PRODUCT_VARIANT, but the image doesn't change, and Add to Cart adds a different product.

 

Any help would be appreciated.

0 Likes
Highlighted
Astronaut
1085 177 213

Send your website URL please

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Recommended by 25+ customers on Facebook. Click here to read their reviews.
◦ Contact me at: diego.boarutto.fortes@gmail.com
0 Likes
Highlighted
New Member
2 0 0

Thank you.

http://stevelotus.com/shopify_test.php

You will notice when you load the page, the dropdown is selecting the new variant ("Lithograph Framed") but the image shown is not for that variant, and if you do Add to Cart, you get a different variant added, "Canvas Giclee Small".

0 Likes