Using fields in formulas

Posted by:

To add a field to a formula you can click on the “Add field” button

Depending on which kind of formula you add a field different pieces of information will be used.

For example, if you have a text field which has a fixed price of 10 (as defined in the price type setting)

If you add this field in a “Price” formula, its “Price” representation will be used, in this case the 10. But if you add it in a formula to define the text of another field, then its textual representation will be used, which is going to be whatever text the user typed in it.

Using context functions

Some of the fields have additional functions, for example, the dropdown has functions to return the text of the selected items or their price. You can find the list of available functions by adding a field and then adding a dot in front of them

A context menu will pop up that will give you a list of available functions for that field, in the example above i can see a list of available functions for the dropdown.

Clicking on them or hitting enter will add the function to the formula.

0

Getting values from URL

Posted by:

Note: In order to follow this tutorial you will need the Essentials add on

You might want to get values from the URL for example you might have a URL like this:

HTTP://www.example.com?myparameter=hello

And you might want to fill a field using the value of myparameter (in this case it would be “hello”)

To do so follow these steps:

1.- Select the field that you want to fill with this value and open the formula editor

2.- Click on “Add function”

3.- Select the function “GetParameter”

4.- Configure the function, this function just needs the name of the parameter that you want to use, in my previous example (HTTP://www.example.com?myparameter=hello) my parameter is called “myparameter” so I will use that

That’s it! Now the field that I selected will be automatically filled using the parameter from my URL.

0

Using conditions

Posted by:

Sometimes you will want to add conditions to your formulas, for example you might want to use different calculations depending on what options in your form are selected.

if(Condition)
  operation
else
  operation

Example:

The condition above will check the value of the dropdown, if the “Option 1” is selected the formula value will be 1, otherwise it will be 2.

The else section is optional, if you want you can create many conditions like this:

In the example above the formula value will be 1 if option 2 is selected, 2 if option 2 is selected or 3 if option 3 is selected.

You can also do arithmetical operations inside the conditions for more complex calculations:

Or even add conditions inside other conditions:

Creating multiple comparisons

You can also create multiple comparisons using && (for and) and || (for or). In an “And” comparison all the comparisons need to be true in order for the condition to be executed in an “Or” comparison at least one comparison needs to be true.

for example, if you want to compare if a number is greater than 10 AND lesser than 20 you can use this comparison:

alternatively, if you want to compare if a number is either 10 or 20 you could do so using the “Or” comparison

0

Using formulas to calculate a price

Posted by:

The plugin comes with several preconfigured ways to calculate prices but if you want to create your own calculation you can use the price type “Formula”

Selecting that option will open the formula builder

In here you can put your formula, most of the times your formula will just be an arithmetical operation but you can do a lot more things like adding conditions (explained in another tutorial).

You can click on the add field button to add one field to your formula

The add function button will let you add useful operations like rounding a number

Every time you do a modification to the formula the plugin will automatically validate it and will let you know if there is any error with it

0