JavaScript API

liquidAjaxCart.init

A boolean read-only property of the liquidAjaxCart object, which becomes true once Liquid Ajax Cart is initialized.

Use case

Use this property along with the liquid-ajax-cart:init event when you want to run your JavaScript once Liquid Ajax Cart is initialized.

assets/script.js
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);
}