# addToCart function is not wokring 

**URL:** <https://forum.wixstudio.com/t/addtocart-function-is-not-wokring/31953>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [June 23, 2020, 12:10pm UTC](https://forum.wixstudio.com/t/addtocart-function-is-not-wokring/31953 "2020-06-23T12:10:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alifraz456](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/alifraz456/32/9954_2.png) [@alifraz456](https://forum.wixstudio.com/u/alifraz456)\
**Post date:** [June 23, 2020, 12:10pm UTC](https://forum.wixstudio.com/t/addtocart-function-is-not-wokring/31953/1 "2020-06-23T12:10:56Z")

</div>

**const** currentProduct = $w( ‘#dynamicDataset’ ).getCurrentItem().\_id;  
console.log(currentProduct);  
// Add the current product to the cart with the user’s chosen background color, text color, custom text, and custom background image.  
$w( ‘#shoppingCartIcon1’ ).addToCart(currentProduct.\_id, {  
“choices” : {  
//“Background Color”: $w(‘#colorText’).text,

```
    }, 

```

“customTextFields” : [{  
“title” : “Custom Text” ,  
//“value”: $w(‘#textInput’).value  
},  
{  
“title” : “Background Image” ,  
“value” : $w( ‘#print’ ).src  
}  
]  
});

---

<div class="post-metadata">

**Author:** ![mrtobor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mrtobor/32/669_2.png) [@mrtobor](https://forum.wixstudio.com/u/mrtobor)\
**Post date:** [June 23, 2020, 2:41pm UTC](https://forum.wixstudio.com/t/addtocart-function-is-not-wokring/31953/2 "2020-06-23T14:41:32Z")

</div>

Hi,

In the code you provided it seems you’re missing an **onClick()** function on a button that will trigger the product to be added to the **#shoppingCartIcon** element.

You can take a look at my example below:

```javascript
$w.onReady(() => {
    $w("#button1").onClick(() => { 
        $w("#shoppingCartIcon1").addToCart("product._id")
            .then((results) => {
                console.log(results);
                console.log("Product added");
            })
            .catch((error) => {
                console.log(error);
            });
    })
})

```

Hope this helps you out. Let us know if it’s still not working for you!

Best regards,  
Miguel | Corvid Team
