Velo Tutorial: Cross-Selling a Product in Your Store with Velo by Wix

Note: This tutorial and its steps are based on a Wix Editor site. You can adapt the steps for a Wix Studio site by using the equivalent Wix Studio features.

Overview

In this tutorial, you'll learn how to use Velo to implement cross-selling in your store. Cross-selling means suggesting a product to your customers when they get to the checkout page. Cross-selling can increase cart value, overall revenue, and conversion rates while improving the shopping experience.

You can see a similar implementation of the functionality described in this tutorial on this site, but with a different code solution. In both this tutorial and the example site, the site promotes Jasmine soap only if customers have one of the other products in their cart, but not Jasmine.

How to Build This Promotion

In the first part of this tutorial, we are going to set up the Cart Page using standard Editor elements. Then we'll use Velo and code to customize the Cart.

Part I - Setting up the Cart Page

Step 1: Start Working with Velo

  • Enable Velo Dev Mode in the Wix Editor to let you work with code. Click Dev Mode in your site's top bar and turn on Enable Developer Mode in the dropdown.

    You will see the Code sidebar on the left-hand side of your screen, and the Properties & Events panel in the bottom-right corner of the Editor.

  • To get to the Cart page in your store, click the Page Code button in the Code sidebar on the left-hand side of the Editor, then Cart page.

Step 2: Adding Elements

Now we're going to add an element to hold the details of the product you want to promote: name, price, image, and description.

  1. Click Add on the left side of the Editor, then Box, and then select Container Boxes.

  2. Add a text element to the Container for the product name, another for the price, and one more for the description.

  3. Add an image (choose one from your gallery).

  4. Add a button and change its text to Add to cart.

    Note: Make sure you see the Attach to Box message before dropping all your elements into the container box.

  5. Customize the elements in the Editor to match your store's design.

Part II - Customizing the Cart Page with Code

Now that you've set up your Cart page you can add the code to cross-sell your product.

Step 3: Element IDs in the Properties Panel

You need to start working with your site's elements in code. One of the first things to do is to give your elements meaningful IDs. That will make it easier to work with them in code. You change an element's ID in the Properties & Events Panel.

When you select an element, its properties are displayed in the Properties & Events Panel.

If you can't see the Properties & Events Panel, click Tools in your site's top bar and check the box next to Properties & Events Panel in the dropdown.

Select each element that you added to the container and change their IDs as described below:

  • Container box: crossSellBox
  • First text element: productName
  • Second text element: productPrice
  • Third text element: productDescription
  • The image: productImage
  • The button: addToCart

Step 4: Product SKU

  1. Navigate to the product section of your store dashboard.
  2. Choose the product you plan to promote.
  3. Note the product's SKU (stock keeping unit). This number is very useful for keeping track of inventory. You will need to assign SKUs to your products. Learn more about Adding and Customizing Product Options.

Step 5: Cart Page Code Editor

  1. Go back to the Cart page in the Editor.
  2. In the Editor, paste the following code into the code editor for the Cart Page.

Note: If you already have code in the Cart Page, take care to avoid clashes between the code you've written and the code provided below. Pay particular attention to the onReady function.

Copy

Understanding the Code

Line 1: Import the module you need to work with Wix Data.
Line 2: Import your backend code.

Line 4: This is where you will insert your product's SKU. If you'd like to promote a different product, replace only the number inside the double quotes with a different SKU.
For example, if your product's SKU is 213, replace line 4 with:
const CROSS_SELL_PRODUCT_SKU = "213";

Lines 6-13: When the page loads, call the other functions in the code to: check for your promoted product in the cart (lines 20-25); find the product in your products databse (lines 27-32); display the product information in the cross-sell box (lines 34-44).
Lines 14-15: If the buyer visiting your store has already added your promoted product to their cart, don't show the cross-sell box.

Lines 20-25: Check the currently displayed cart for the product you've decided to promote.

Lines 27-32: Find the promoted product in your products database and get its information.

Lines 34-44: Display the product name, price, image, and description in the elements inside the cross-sell box.

Step 6: Backend Code

  1. Click the Code Files button in the Code sidebar, then hover over Backend, click the plus icon, and select Add Web Module.
  2. Name this module cart.web.js.
  3. Delete the provided sample code and paste the following code into the Web Module.
Copy

Understanding the Code

Line 1: Import the Permissions enum and webMethod from wix-web-module.
Line 2: Import the module you need to work with Wix Stores.
Line 4-5: Export the getCurrentCart() function for use on the front-end (line 2 of the cart page code). Learn more here.

Step 7: Save and Publish your Site.

  • In the top right corner of the Editor, save and preview to check your progress.
  • To see the live version of the site, click Publish.
Did this help?