How to access exposed JavaScript functions and values

Learn how to use JavaScript functions available in your theme

warning icon
We do not provide support for code customizations
If you are not comfortable making code changes, we highly recommend hiring an expert developer. View Shopify experts

Summary


If you are integrating your Shopify theme with a third-party app you may want to access some of the globally available functions. Since our themes utilize Alpine.js this is done a bit differently than normal.

How to


The first step is to access the app object. This object contains all the exposed functions and is stored in the _x_dataStack array of the html element. Here is how to access it:

var app = document.querySelectorAll('html')[0]._x_dataStack[0];

From here you can call any of the functions available in the Paper toolkit. For example if you want to call cart.updateCart() you could do the following.

app.updateCart(true);
Did this answer your question?
😞
😐
😁