Template Engine
How to subscribe to the Add To Cart event in Template Engine
Add to Cart button in Template Engine will show up after the user selected a product on the page. You might want to subscribe to the Add to Cart button event to figure out which product
the user wanted to add the cart/basket. This event will provide all necessary information about the product so that you can trigger your own cart/drawer with it.
Subscribe to the Add To Cart event#
You need to listen the postMessage event on window object first, then you can receive
the unique id of selected product/variant after confirming the message is valid.
Here is the sample code block with explanation:
How to trigger Shopify Cart Drawer with the Add to Cart event#
Integrations for Shopify themes might slightly change by the theme itself. Some themes might have different API's for the add to cart events. You can check the following implementation as a most common example to trigger updated cart drawer after Add to Cart event is invoked: