Variables and Field Values

Written By Floris de Vries

Last updated 2 days ago

Variables represent values that can be used inside pricing formulas. These values come from form fields, product data, system helpers, and any computed properties you define.


Form field variables

Every field created in Step 1 becomes available as a variable in the formula.The variable name is based on the fieldโ€™s Key (unique ID).

How field types behave

  • Number Input โ€“ the numeric value entered by the customer.

  • Dropdown / Radio / Swatch โ€“ the numeric value of the selected option.

  • Checkbox โ€“ the configured numeric value when checked, or 0 when unchecked.

  • Text Field / Textarea โ€“ if the customer typed any text and you set a numeric value on the field, that float is used; otherwise 0.

  • File Upload โ€“ the configured numeric value, multiplied by the number of uploaded files.

  • Date Picker โ€“ the selected date string. Generally referenced from conditional logic rather than added directly to a price.

  • Rich Text / Divider / Calculation display โ€“ not available as variables (display-only).

All values update dynamically as the customer interacts with the calculator.


Extra variables for specific field types

  • {key}_chars โ€“ the number of characters in a Text Field, Textarea or Font Picker text. Useful for charging per character or per word.

  • {key}_color โ€“ the numeric value linked to the selected color of a Font Picker (when the optional color choice is enabled).

  • {key}_optidx โ€“ the zero-based index of the selected option for Dropdown, Radio Buttons, Swatch, Font Picker and Color Picker. Available only inside Conditional pricing rules, not inside the regular formula.


Product & variant variables

Product price

The Product price variable always represents the price of the currently selected variant.

  • If the product has multiple variants, this value updates automatically when the customer selects a different variant.

  • If the product has only one variant, the product price is simply the base product price.

In practice, Product price always equals the active variant price.

Numeric metafields

Numeric product and variant metafields are also exposed as variables when they exist on your products. The variable name follows the pattern:

  • product_metafield__{namespace}__{key}

  • variant_metafield__{namespace}__{key}

Use the Form fields picker in the formula builder to insert them with the right name. Only metafields with a numeric type (integer or decimal) are listed.


Computed properties (custom variables)

You can define your own intermediate variables in the Computed properties section of the formula step. They are referenced internally as _cv_{slug} but are also listed by their human label in the formula picker.

Use them to break complex pricing into smaller pieces โ€“ e.g. a Surface area variable that holds width * height and is then re-used everywhere. See Computed properties (custom variables) for details.


System helpers

The following math helpers are available inside formulas (not inside conditional rules):

  • Minimum โ€“ Math.min(a, b) picks the smaller value.

  • Maximum โ€“ Math.max(a, b) picks the larger value.

  • Round up โ€“ Math.ceil(x) rounds up to the next whole number.

  • Round down โ€“ Math.floor(x) rounds down to the previous whole number.

  • Round to nearest โ€“ Math.round(x) rounds to the closest whole number.

Inside Conditional pricing rules you can additionally use the constants TRUE and FALSE to compare against boolean-style fields.


Variable rules

  • Variable names are case-sensitive

  • Variables must exist in the calculator

  • All values used in formulas must resolve to a number

  • Invalid variables will cause the formula to fail


๐Ÿ’ก Tip:Use clear, descriptive field keys. This makes formulas easier to read, debug, and maintain.