# Why is my "add to cart" button not working?

**URL:** <https://forum.wixstudio.com/t/why-is-my-add-to-cart-button-not-working/63708>\
**Category:** Ask the community\
**Tags:** code\
**Created:** [October 18, 2024, 5:43pm UTC](https://forum.wixstudio.com/t/why-is-my-add-to-cart-button-not-working/63708 "2024-10-18T17:43:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasanda\_VALIN](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@Vasanda\_VALIN](https://forum.wixstudio.com/u/Vasanda_VALIN)\
**Post date:** [October 18, 2024, 5:43pm UTC](https://forum.wixstudio.com/t/why-is-my-add-to-cart-button-not-working/63708/1 "2024-10-18T17:43:06Z")

</div>

Hello everyone, could someone help me with my VELO code, please? I have a dynamic page linked to products, and I would like to add an “add to cart” button. Despite reaching out to Wix support, my code still isn’t working, and I’m getting an error message. Please help me!

my code :

```javascript
import { myAddToCurrentCartFunction } from "backend/befsovaz.web"; // Importe ta fonction backend
import wixLocation from 'wix-location'; 

$w.onReady(function () {
  let dynamicDataset = $w("#dynamicDataset"); 

  dynamicDataset.onReady(() => {
    const currentProductId = dynamicDataset.getCurrentItem()._id; 
    const appId = "215238eb-22a5-4c36-9e7b-e7c08025e04e"; 
    const variantId = dynamicDataset.getCurrentItem().variantId; 

    const options = {
      lineItems: [
        {
          catalogReference: {
            appId: appId,
            catalogItemId: currentProductId, 
            options: {
              variantId: variantId || null, 
            },
          },
          quantity: 1,
        },
      ],
    };

    $w("#button9").onClick(() => {
      myAddToCurrentCartFunction(options)
        .then((updatedCart) => {
          console.log("Produit ajouté au panier !", updatedCart);
          wixLocation.to("/cart-page");
        })
        .catch((error) => {
          console.error("Erreur lors de l'ajout au panier :", error);
        });
    });
  });
});

```
