onChange( )


Deprecated. This function will continue to work, but a newer version is available at wix-ecom-frontend.onCartChange().

Migration Instructions

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:

  1. Add the new import statement:

    Copy
  2. 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.

  3. 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:

  • Use 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.
  • The 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.
  • When editing a site as a contributor, onChange() will only work when viewing the live site.
Method Declaration
Copy
Method Parameters
handlerfunctionRequired

handler(cart: CartObj): void The name of the function to run when a cart changes.

Was this helpful?
Yes
No