We would like to offer our customers and imprinting option on certain products.
We will be putting a checkbox on the product page and if it is checked, we want to add the imprinting product to the cart using the ajax api. This needs to happen on the add cart button click.
Below is my code. The issue is that it sometimes works and sometimes not. Whenever I test it, sometimes only the original product makes it to the cart, sometimes only the imprinting product makes it to the cart, and sometimes they both get there.
When I watch my requests in the network tab in chrome dev tool, I always see 2 cart/add requests being sent, and they always come back with a status of 200. Yet not always does the cart get updated with both products.
Here's my code. I added the onclick handler on the button and created the function in a script tag.