An object which exposes the methods and properties of the Liquid Ajax Cart library.
The liquidAjaxCart object is defined as a property of the window object to be accessible from everywhere.
A few of them are available as soon as the library code is loaded:
The rest of them are available only after the initialization:
get() — makes a Shopify Cart API GET /cart.js Ajax request;add() — makes a POST /cart/add.js request;change() — makes a POST /cart/change.js request;update() — makes a POST /cart/update.js request;clear() — makes a POST /cart/clear.js request;cart — current cart state (JSON);processing — true if there is a request in progress now (boolean).Since most of the liquidAjaxCart methods and properties are available only after the initialization,
use the liquid-ajax-cart:init event
along with the liquidAjaxCart.init property
when your code depends on Liquid Ajax Cart and should be executed as soon as the library is fully available:
function runWhenInit() {
console.log("The current cart state is: ", window.liquidAjaxCart.cart);
}
if (window.liquidAjaxCart?.init) {
// if Liquid Ajax Cart is already initialized
runWhenInit();
} else {
// wait for Liquid Ajax Cart to be initialized
document.addEventListener("liquid-ajax-cart:init", runWhenInit);
}