GET FREE VERSION GET THE PRO VERSION

Math calculations with CALC

Learn how to perform math calculations for your text variables and display the results inside labels.

In this article

Overview

Following article describes features available only with PRO plugin version.

With the CALC text variable you can perform simple math activities. Such as addition, subtraction, multiplication and division of two arguments.

The result of the calculation can be rounded to integer values or you can set the degree of rounding yourself.

And even more exciting - you can use other text variables as arguments for your CALC expression. For example, use the {PRICE} text variable and do math on it.

Some example of use:

- Multiply {PRICE} and {QTY} text variables to show the value of all remaining products in stock.

Label text with CALC expression

- Any custom calculations with product custom fields. For example, you have a field special_offer_price that specifies some special price for some specific user groups. So you want to show to the user his benefit from buying at this new price. You create a label with display conditions to be visible only to certain users. And then subtract {META:special_offer_price} from {PRICE} to show a discount amount.

How to use the CALC function

CALC is a text variable. So you can use it and display the result as and other text variables.

Here are the steps to get started:

1. Go to Adv. Woo Labels -> All Labels page and choose the needed label to edit. Or just create a new one.

2. Find Label text option and insert CALC text with the needed expression inside it. For example, we want to multiply {PRICE} and {QTY} to show the total cost of all remaining products in stock. In this case CALC variable should looks like that:

{CALC:{PRICE}*{QTY}}

Also you can add some text into the label for example: Buy all for {CALC:{PRICE}*{QTY}}

Label text with CALC expression

Label text with CALC expression

3. Additionally you can add some label display conditions. For example, to make sure that product is in stock and price for it is set properly you can use following rules:

Label display conditions

Label display conditions

4. Finally just save all changes and check your shop for that label with shiny new text.

Label to display total cost of in stock items

Label to display total cost of in stock items

Limitations

There are some limitations that you need to keep in mind when using the CALC function.

- Only +, -, * and / operator are available for math calculations.

- Only simple expressions with two arguments are allowed.

- Try to avoid any non-numeric values within arguments.

- By default results will be presented with a float value ( if applied ). To round the value use | character and specify number of decimal places. Example - {CALC: 10/3 | 0 } will return 3 instead of 3.33

Format calculations

Additionally you can use a special {FORMAT} text variable to make results from CALC more attractive.

{FORMAT} format a number with grouped thousands by adding separators for such groups. Value that you want to be formatted must be integer or might be able to convert to integer. Otherwise FORMAT will return the same value as was specified as its argument.

Some examples of use:

{FORMAT:100000} - will return 100,000

{FORMAT:{CALC:3000*40}} - will return 120,000