header-logo
Learn how to use Wix to build your site and business.
Design and manage your site using intuitive Wix features.
Manage subscriptions, plans and invoices.
Run your business and connect with members.
Learn to purchase, connect or transfer a domain to your site.
Get tools to grow your business and web presence.
Boost your visibility with SEO and marketing tools.
Get advanced features to help you work more efficiently.
Find solutions, learn about known issues or contact us.
placeholder-preview-image
Improve your skills with our courses and tutorials.
Get tips for web design, marketing and more.
Learn to increase organic site traffic from search engines.
Build a custom site using our full-stack platform.
Get matched with a specialist to help you reach your goals.
placeholder-preview-image

Wix Functions: Using Variables

6 min
In this article
  • Adding a variable to your function
  • Example of using variables in a function
  • FAQs
Create variables to act as placeholders for information you use repeatedly in your function. Instead of adding or calculating the same details over and over, you set up a variable once and can reuse it as many times as you need. If you ever want to update the variable, you only need to do so in one place and it updates throughout your function.
For example, if you have an online store you can create a variable to keep track of the total items in a customer's cart or the heaviest item for shipping purposes. This way, your site stays accurate and efficient, making things easier for both you and your customers.
A screenshot of creating variables in the function builder.

Adding a variable to your function

Add a variable in the function builder by adding a new step. Make sure you add a variable before the point in the flow where you want to use it. For example, if you want to use a variable in a condition, you must create the variable before adding the condition step.

To add a variable to a function:

  1. Go to Functions in your site's dashboard.
  2. Edit an existing function or select a template to create a new one.
  3. Click the Add Step icon  in the function builder.
  4. Click Variable.
  5. Add your variable info:
    1. Variable name: Add an easily identifiable name.
    2. Data type: Select the appropriate data type (text, number, boolean, date-time).
    3. Value: Enter the variable's value. You can also click Customize to create a more complex calculation using properties, functions and values.
An example of creating a minimum order variable
  1. (Optional) Click + Add Variable to add another variable.
  2. Click Apply.
  3. Continue building your function by adding your variable to conditions and/or the function output.
    Tip: To find your variables, click Select a property in a condition step, or Customize in the function output. Available variables are listed at the top.
A screenshot of the variable drop-down inside the property picker.

Example of using variables in a function

Let's take a look at how a Wix Stores user includes variables in a function.
Stella runs an online store and wants to offer free delivery for orders over $100. She can achieve this by creating a minimum order subtotal function
In the function builder, instead of entering the exact minimum order amount ($100) throughout the expression, Stella can create a 'minimum order subtotal' variable. If she needs to update the minimum order amount in the future, she can simply adjust the variable instead of changing it everywhere in the function. This simplifies her workflow and reduces the function's overall complexity.
Example of a function without a variable:
An example of building a function without a variable.
Example of a function with a variable:
An example of setting a minimum order subtotal variable in the function builder

FAQs

Click a question below to learn more about using variables.