Listen to product added to cart event

Hi,
Is there a way to listen to an event related to a product being added to the cart when the user clicks the “Add to cart” button on the standard Product Page?
What I would like to do is to add a second product to the cart automatically every time the user adds a certain product.
The way I thought about it was to listen to a “added to cart event” and when that triggers, to add the product I want to the cart.
Any ideas on how to achieve that? The only events available so far on the CartIcon element are only related to mouse movements and the viewport.
Regards,
Fabio

Take a look at the addToCart( ) function
https://www.wix.com/corvid/reference/$w.CartIcon.html#addToCart

The addToCart() function returns a Promise that is resolved when the specified product is added to the shopping cart.

Use the optional quantity parameter to add more than one product unit to the shopping cart at one time. If quantity is omitted, one product unit will be added.

Hi Yevhenieea,
Thanks for commenting. But that’s not actually what I am looking for.
This would work in case I would be adding a product using the API. But instead I want to listen to all “add to cart” events, including those triggered by the user clicking on the “Add to cart” button from the standard Product Page.
Do you get it?
I have updated my question above to reflect that.

If the “addToCart” returns a promise, I am sure I can also hook up my function to the standard action of adding an item to the cart but by using the “Add to cart” button on the standard page. Really, nobody ever tried doing that?

I just found out that the wix-store-backend has some additional functionality that is not available on the CartIcon frontend object. I am now investigating if I can achieve my objective using the backend API together with web modules . I will give it a try in the next few days and will update this post accordingly.

Still, it would be much easier if we had this feature available on the frontend.

Fábio Molinar here is a ,link for the event when cart created but for that you have to to write this code in the back-end of your website here is the link of that function description.

Hi @umairboss26 ,
That’s what I will try in the next few days. Found about this web module thing yesterday.
Still, it would be much better and easier to have such functionality available on the frontend.

@fabiomolinar I know this is an old thread, but the results were never updated and I need the exact same thing.

Hi Neff, no, I had no luck with this one. I don’t know if anything changed here. I would bet it didn’t. What I did though to circumvent this was to create my own buttons (and also my own product page) which I had more control over. With my own buttons I was able to custom build the entire behavior of the “buy button”.

I’m coming to the realization I’ll have to build completely custom product pages and supporting code due to missing “cartUpdated” events.

Barry, does onCartChanged() not work for what you need?

What I ended up doing is using the standard product-page page, but I hide the entire product page element. Than, on top of it, I created an entire custom page. This way I can keep using all of the features from the standard product-page (like the seamless integration with Facebook shop), but using my own buttons and custom code.

@fabiomolinar good idea. I hadnt considered this.