# AddToCart button not working with code

**URL:** <https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 12, 2019, 6:52pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910 "2019-03-12T18:52:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hernands16](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hernands16/32/7919_2.png) [@hernands16](https://forum.wixstudio.com/u/hernands16)\
**Post date:** [March 12, 2019, 6:52pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/1 "2019-03-12T18:52:39Z")

</div>

I am trying to add a product to cart with a click event on a button. I keep getting this error

![](https://us1.discourse-cdn.com/wix/original/3X/f/3/f3bc3c12772fe2e352b15bcc3d14668fefd16a91.png)

![](https://us1.discourse-cdn.com/wix/original/3X/f/d/fd0e600b63ca2bdff9acf2d5f76859901df29817.png)  
I made productId a constant and copied the id from my products collection.  
I also have no options for the product at the moment.  
Can anyone help me?

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [March 13, 2019, 2:59am UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/2 "2019-03-13T02:59:49Z")

</div>

Steven, I have some code utilizing addToCart and thought I’d change a legitimate ID to a bogus one. It returned the very same error message. In order to rule this out as the culprit, you might re-check the ID that you are assigning to the constant. The alpha characters in the Wix Store product IDs are all lower case. I changed one letter from lower to upper case and received the error.

---

<div class="post-metadata">

**Author:** ![hernands16](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hernands16/32/7919_2.png) [@hernands16](https://forum.wixstudio.com/u/hernands16)\
**Post date:** [April 2, 2019, 10:01pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/3 "2019-04-02T22:01:05Z")

</div>

This issue doesn’t exist the id is copied straight from the products collection and all the characters are lowercase. I still need help.

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [April 2, 2019, 11:29pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/4 "2019-04-02T23:29:14Z")

</div>

@hernands16 Where in the code page is productId assigned. Post a screenshot of that, and perhaps something will be apparent to one of us.

---

<div class="post-metadata">

**Author:** ![hernands16](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hernands16/32/7919_2.png) [@hernands16](https://forum.wixstudio.com/u/hernands16)\
**Post date:** [April 16, 2019, 4:09pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/5 "2019-04-16T16:09:41Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/9/c/9cd6855683f4614f25a7788de11acb8ff25002b6.png)

![](https://us1.discourse-cdn.com/wix/original/3X/a/2/a200bf57132eb1556ceee1755edcee60b439b77b.png)

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [April 16, 2019, 6:05pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/6 "2019-04-16T18:05:49Z")

</div>

Steven, looking at your code, there appears to be no reason why it should not add the item to the cart. However, something did catch my eye, though I may be reaching here. When I add an Add to Cart button, the one from the Store section of the elements list and not a button from the Buttons section, that button does not have a click event that you can add and its default name is “addToCartButton1”. In fact, it’s not a button element at all, but an iFrame. I’m wondering what would happen if you added a regular button. And then in a click event added from its property sheet, copy and paste your addToCart code from above into that function. Do you get the same error?

---

<div class="post-metadata">

**Author:** ![hernands16](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hernands16/32/7919_2.png) [@hernands16](https://forum.wixstudio.com/u/hernands16)\
**Post date:** [April 16, 2019, 7:35pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/7 "2019-04-16T19:35:03Z")

</div>

Yea that is what I had it doesn’t work. I feel like the program is having trouble fetching the product because it doesn’t know where to fetch the id from. I don’t know that is just my guess.

---

<div class="post-metadata">

**Author:** ![hernands16](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hernands16/32/7919_2.png) [@hernands16](https://forum.wixstudio.com/u/hernands16)\
**Post date:** [April 16, 2019, 7:39pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/8 "2019-04-16T19:39:13Z")

</div>

I’ve been stuck on this for over a month haha.

---

<div class="post-metadata">

**Author:** ![av-promotional](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/av-promotional/32/2796_2.png) [@av-promotional](https://forum.wixstudio.com/u/av-promotional)\
**Post date:** [July 19, 2019, 1:39pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/9 "2019-07-19T13:39:06Z")

</div>

So many questions about it in many threads, and there is no answer to anyone about anything so basic.

Perhaps WIX deliberately objects to adding a product independently in the code.  
Maybe someone can help how to add a product to the shopping basket with only the product ID.

**let** id= $w(‘#dynamicDataset’).getCurrentItem().muzarsal;  
console.log(id);  
$w(‘#myShoppingCartIcon’).addToCart(id)  
.then( () =\> {  
console.log(“Product added”);  
} )  
. **catch** ( (error) =\> {  
console.log(error);  
} );

This code is marked with an error. Write to me as follows:

‘addToCart’ does not exist on ‘#myShoppingCartIcon’

---

<div class="post-metadata">

**Author:** ![av-promotional](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/av-promotional/32/2796_2.png) [@av-promotional](https://forum.wixstudio.com/u/av-promotional)\
**Post date:** [July 23, 2019, 10:31pm UTC](https://forum.wixstudio.com/t/addtocart-button-not-working-with-code/15910/10 "2019-07-23T22:31:13Z")

</div>

אופס. פשוט היה חסר לי את האלמנט של הסל. [#myShoppingCartIcon](https://www.wix.com/corvid/forum/search/~num~myShoppingCartIcon)
