subscribeToCartStateUpdate()
The subscribeToCartStateUpdate
function adds your callback function to the list of functions that will be called each time after the State object is changed. The callback should be passed as the only parameter.
subscribeToCartStateUpdate( myCallback );
<script type="module">
import { subscribeToCartStateUpdate } from '{{ "liquid-ajax-cart-v1.11.2.js" | asset_url }}'
subscribeToCartStateUpdate(( state, isCartUpdated ) => {
console.log('State is updated: ', state);
console.log('Cart state is updated: ', isCartUpdated);
});
</script>
Your callback will be called with the State object and the isCartUpdated
boolean parameter.
If the isCartUpdated
is true
, it means that Liquid Ajax Cart has just received new cart JSON-data from Shopify from the last Shopify Cart Ajax API request and the new cart state is available in the cart
property.
If the isCartUpdated
is false
, it means that only status
State property is changed.