Directs the browser to navigate to the site visitor's Cart Page.
The navigateToCartPage()
function returns a Promise that resolves when the browser successfully navigates to the Cart Page.
function navigateToCartPage(): Promise<void>;
import wixEcomFrontend from "wix-ecom-frontend";
import wixEcomBackend from "wix-ecom-backend";
$w("#myNavigateToCartPageButton").onClick(() => {
// 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,
},
],
};
// The wixEcomBackend.currentCart module is universal.
// You can call its methods in frontend and backend code.
wixEcomBackend.currentCart
.addToCurrentCart(options)
.then(() => {
console.log("item added to cart");
// navigate to cart page after adding item
wixEcomFrontend.navigateToCartPage();
})
.catch((error) => {
console.error(error);
// Handle the error
});
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.