Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-frontend.onCartChange()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-frontend.onCartChange()
.
To migrate to the new function:
Add the new import statement:
Look for any code that uses cart.onChange()
,
and replace it with wixEcomFrontend.onCartChange()
.
The new onCartChange()
event handler does not return the changed cart. Update your code accordingly.
Test your changes to make sure your code behaves as expected.
An event handler that is triggered when items are added or removed from a cart.
The onChange()
function is a client-side event handler invoked every time the cart changes. It takes a callback function which receives the new Cart
object as a parameter.
Notes:
onChange()
in the global site code file (masterPage.js). This ensures the event is triggered when a change to the cart is made on any page. Learn more about global (site) code.onChange()
function can only be used once a page has loaded. Therefore, you must use it in code that is contained in or is called from the onReady() event handler or any element event handler.onChange()
will only work when viewing the live site.
handler(cart: CartObj): void
The name of the function to run when a cart changes.