We have a page that dynamically updates one of the variation selections on page load, through jquery, based on what the url of the previous page was. However, when adding to cart, the variation is showing the initial selection rather than the one updated through jquery.
This is the code which updates the select element on page load.
I have actually applied this already in the 3 Recipe tier which was what I was testing on, and the Add to cart still ignored the change. To be safe I applied it to both but did not see any difference in results.
I guess it’s time for you to share your store url (preview link, if unpublished/under password). Generally @Anonymous gave you the right advice, but it’s hard to be spot on without seeing the problem.
Theme code should update hidden select/data, which is then used as source of variant id when adding to cart. Theme code listens for the “change” event, so simply updating value of your drop-down without triggering “change” would not trigger event listeners and would not change the variant selected.
The user will have 1, 2 or 3 recipe options selected on the left sidebar. If 2 or 3 are selected, when the user clicks into one of the products (ignore the first one, but any of the other products like “Vodka (Infused)” will be using the correct template), 2 or 3 recipe will be automatically selected.
Once you pick the recipes you want and add to cart, the item appears in your cart but only with 1 Recipe added, and only charging for that.
We also added trigger (‘change’) to the first condition.
In the example above, your code will fire 500ms later. If you ask how we checked, we just inserted a part of the code in the Chrome console. We launched and tried to add an option, and the option was applied on the shopping cart page.
After that, it became clear that your code is simply triggered earlier than necessary.