refreshCart( )


Updates cart UI elements, like the Cart Icon and Side Cart with the most recent cart data.

The refreshCart() function returns a Promise that resolves when the latest cart data is retrieved, and the cart UI elements are refreshed.

Note: Calling the refreshCart() function will trigger the onCartChange() event handler.

Method Declaration
Copy
function refreshCart(): Promise<void>;
Request
This method does not take any parameters
Refresh the cart
JavaScript
import { createClient } from "@wix/sdk"; import { site } from "@wix/site"; import { ecom } from "@wix/site-ecom"; const wixClient = createClient({ host: site.host(), modules: { ecom } }); document .getElementById("myAddAndRefreshCartButton") .addEventListener("click", async () => { // example values for the options object const options = { lineItems: [ { catalogReference: { // Wix Stores appId appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e", // Wix Stores productId catalogItemId: "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea", }, quantity: 1, }, ], }; try { // The wixEcomBackend.currentCart module is universal. // You can call its methods in frontend and backend code. await wixEcomBackend.currentCart.addToCurrentCart(options); console.log("item added to cart"); // refresh the cart after adding item await wixClient.ecom.refreshCart(); } catch (error) { console.error(error); // Handle the error } });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?