Doc > Prices & quantity calculations

In Documentation, Uncategorized by loopus

Prices & quantity calculations

Both prices calculations, quantity calculations and variables calculation use the same awesome system :

The custom calculation system uses JavaScript language.
It supports any Javascript syntax and functions, like the Math object ones.

In addition to the Javascript language, shortcodes are added which are specific to this plugin.
The [price] shortcode is the result of the calculation, so a calculation looks like this :

[price] = 110.00

The other shortcodes are used to recover the value, price or quantity of any item or step of the form and use it in the calculation.
You don’t need to write them manually : simply click the “Add a value” button above the calculation field to visually select the wanted element and attribute. The plugin will automatically generate the corresponding shortcode in the calculation field :

[price] = [item-1_value]

The main operators to use are :

  • + : addition
  • – : subtraction
  • * : multiplication
  • / : division

To create conditions, click the “Add a condition” button to access to the condition panel :

Simply use the “Add a condition” button and the conditions dropdowns to create the wanted conditions.
You can also choose if all the conditions must be filled, or if only one of them must be filled to consider the condition as true, by using the dropdown placed at top of the conditions list.

Once the “Save” button clicked on the conditions panel, the plugin automatically generates the condition code in the calculation field :

[price] = 10
          if([item-1_isChecked] && [item-2_value] < 25) {

          }

Simply fill the wanted conditional price between the two braces :

[price] = 10
          if([item-1_isChecked] && [item-2_value] < 25) {
            [price] = 20
          }

In this example, the default unit cost of the current item will be $10, but if the item 1 is selected and if the value filled in the item 2 is inferior to 25, its price will become $20.

As explained, custom calculations support any JS syntax, so you can even create conditions in conditions, and use "else" statement :

if([item-1_isChecked]) {
            if([item-2_isChecked]){
              [price] = 20
            } else {
              [price] = 10              
            }
          }

The "Add a distance" button will be available only if the "Google Maps API key" option is filled in the form settings.
It allows you to recover the number of miles/km or the travel duration between the addresses that come from the text fields of your form.
The plugin uses the "Type of information" option of the text fields of the form to detect the available address fields.
The result will be a shortcode like [distance-1-2] in the calculation code, that will return the calculated distance when this calculation will be executed.

The "Date difference" button allows you to recover the number of days between the dates selected in two date pickers of the form, and use it in your calculation.