Formula functions reference

Introduction

Pricing formulas are similar to Excel formulas: they can contain functions to make your product’s pricing even more powerful. Function parameters can be simple data (such as a number or text), or can contain dynamic code and variables like [field.{id}] or [price.{id}] to reference dynamic data.

All functions

Available in all versions of the plugin

FunctionDescriptionExample
min(a; [b; c; ...])Returns the smallest of the given numbers.min(100; [field.61ad341])
max(a; [b; c; ...])Returns the largest of the given numbers.max(100; [field.61ad341])
len(string; ignoreSpaces)Returns the length of a string. Optionally ignores spaces by setting ifnoreSpaces to true or false.len(a quick brown fox;true)

Available in the Extended version

FunctionDescriptionExample
if(condition; value1; value2)Returns value1 if the condition argument is true, otherwise it returns value2. You can make nested IF statements.if([field.61ad341] > 50; 10; 20)
or(logical1; [logical2; ...])Used in IF() functions. Returns true if any one of the arguments is true.or([field.61ad341]=50;[field.799e141]=100)
and(logical1; [logical2; ...])Used in IF() functions. Returns true if all the arguments are true, returns false otherwise.and([field.61ad341]=50;[field.799e141]=100)
datediff(date1; date2)Returns the difference (in days) between two dates.datediff([field.61ad341];[field.799e141])
today()Returns today’s date. Can be used in the datediff function for further calculation.today()
checked(field ID)Returns how many items are selected in a multi-select field (such as checkboxes, image swatches, …).checked(61ad341)
files(field ID)Returns the count of uploaded files for that field.files(61ad341)
round(number; decimals)Round (up or down) the value to the nearest number. You can optionally specify the number of decimals to round to.round(4.8) => 5
round(9.07) => 9
round(0.33337; 4) => 0.3334
ceil(number)Round up to the nearest number.ceil(4.8) => 5
floorRound down to the nearest number.floor(4.8) => 4
abs(number)Returns the absolute value of a number.abs(-5) => 5
pow(base; exponent)function returns the base to the exponent power, as in baseexponent.pow(4;2) => 4² => 16
sqrt(number)Returns the square root of a number.sqrt(144) => 12
sin(number)Returns the sine of a number.sin(5)
cos(number)Returns the cosine of the specified angle. The number parameter specifies radians.cos(5)
tan(number)Returns the tangent of a number.tan(5)
sumQty(field ID)Sums all quantities entered by a user in a field that has several “quantity” inputs. Currently that is only applicable for the “images + quantities” field type.sumQty(61ad341)

Nesting functions

Nesting functions inside other functions is possible too. For example, you could create a more complex IF-ELSE structure like this:

if( condition; true; if(condition2; true2; false2))

Just like with Excel functions, you can use the and() and or() function inside the if function. Let’s say you want to do something when X = 1 or X = 2, then you would write your function like this:

if( or(x=1; x=2); then; else )

Troubleshooting formulas

Are you using functions but your formulas produce incorrect results? Check this article to troubleshoot your formulas.

Dynamic data and variables

If you haven’t already, we recommend checking our article on how to get started with formula-based pricing. It also contains which dynamic codes (shortcodes) you can use inside formulas and how to work with your custom created variables.

Was this article helpful?

Related Articles