Back to Documentation
Pricing & Formulas

Custom Formula System

Create complex pricing calculations with JavaScript-based formulas. Reference fields, use conditionals, and build dynamic pricing for any scenario.

20 min read
Updated December 2024
$125.50CALC{value} * {quantity}+ ({field.size.value} === 'large'? 25 : 10)+ {product_price} * 0.1Result: $125.50

Overview

The Custom Formula System allows you to create sophisticated pricing calculations using JavaScript-like syntax. You can reference field values, product prices, quantities, and use conditional logic to build dynamic pricing for any business scenario.

Important Note

Custom formulas are only available in the Entrepreneur and Business plans. Upgrade to unlock this powerful feature.

Predefined Variables

The formula system provides several built-in variables you can use in your calculations:

{value}

The current calculated price (starts with product base price)

{quantity}

The product quantity from the cart

{product_price}

The original WooCommerce product base price

{field.ID.value}

Reference any field's value by its unique ID

Referencing Fields

You can reference any field in your form using the syntax: {field.ELEMENT_ID.value}

Finding the Field ID

  1. Open your form in the form builder
  2. Click on the field you want to reference
  3. Look for the Element ID in the field settings
  4. Copy the ID (e.g., "field_123" or "size_option")
// Example: Referencing a size field
{field.size_option.value}
// Example: Referencing a quantity field
{field.custom_qty.value}
// Example: Referencing a width field
{field.width.value}

Mathematical Operators

Use standard JavaScript operators for calculations:

+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulo
**
Exponent

Example Formulas

Simple Addition

{product_price} + 25

Adds $25 to the base product price

Quantity Discount

{product_price} * {quantity} * 0.9

Apply 10% discount for bulk orders

Area Calculation

{field.width.value} * {field.height.value} * 5

Calculate price based on area ($5 per sq unit)

Conditional Logic

Use ternary operators to apply different calculations based on conditions:

// Syntax: condition ? value_if_true : value_if_false
({quantity} > 10 ? 20 : 30)
// If quantity is more than 10, charge $20, otherwise $30

Conditional Examples

📦 Size-Based Pricing

{product_price} + ({field.size.value} === 'large' ? 25 : 10)

Add $25 for large, $10 for other sizes

🎨 Color Premium

{product_price} + ({field.color.value} === 'custom' ? 50 : 0)

Add $50 for custom colors

🚚 Shipping Tiers

{product_price} + ({quantity} > 100 ? 0 : {quantity} > 50 ? 15 : 25)

Free shipping >100, $15 for 50-100, $25 for <50

Real-World Examples

1. Custom T-Shirt Printing

Scenario: Base price $20, add $5 per color, $10 for large sizes, 10% discount for 10+ items

{product_price} + ({field.colors.value} * 5) + ({field.size.value} === 'large' ? 10 : 0) * ({quantity} >= 10 ? 0.9 : 1)

2. Custom Framing

Scenario: Calculate by area (width × height) at $2/sq inch, add $50 for premium frame

({field.width.value} * {field.height.value} * 2) + ({field.frame_type.value} === 'premium' ? 50 : 0)

3. Cake Ordering System

Scenario: Base $30, add $5 per tier, $20 for custom design, 15% rush fee if needed within 48hrs

(30 + ({field.tiers.value} * 5) + ({field.custom_design.value} === 'yes' ? 20 : 0)) * ({field.rush_order.value} === 'yes' ? 1.15 : 1)

4. Cleaning Service

Scenario: $50 base + $25 per bedroom, $15 per bathroom, add $30 for deep clean

50 + ({field.bedrooms.value} * 25) + ({field.bathrooms.value} * 15) + ({field.deep_clean.value} === 'yes' ? 30 : 0)

Advanced Techniques

Nested Conditionals

You can nest ternary operators for complex logic:

{product_price} + ({field.material.value} === 'gold' ? 100 : {field.material.value} === 'silver' ? 50 : {field.material.value} === 'bronze' ? 25 : 0)

Mathematical Functions

Use JavaScript Math functions for advanced calculations:

Math.round({field.price.value})
Round to nearest integer
Math.ceil({field.price.value})
Round up
Math.floor({field.price.value})
Round down
Math.max({field.a.value}, {field.b.value})
Return the larger value
Math.min({field.a.value}, {field.b.value})
Return the smaller value

Tips & Best Practices

✅ Do's

  • ✓ Test formulas thoroughly before going live
  • ✓ Use descriptive field IDs for easy reference
  • ✓ Add comments in complex formulas
  • ✓ Round prices for clean display
  • ✓ Consider edge cases (zero, negative values)

❌ Don'ts

  • ✗ Don't use undefined field IDs
  • ✗ Don't forget to handle division by zero
  • ✗ Don't make formulas too complex
  • ✗ Don't forget parentheses for order of operations
  • ✗ Don't skip testing with real data

Troubleshooting

Formula Not Working?

  • Check that all field IDs exist and are spelled correctly
  • Ensure field values are numbers when doing math operations
  • Look for syntax errors (missing parentheses, quotes)
  • Test with simple formulas first, then build complexity
  • Check browser console for JavaScript errors

Price Shows NaN or Infinity?

  • A field value might be empty or not a valid number
  • You might be dividing by zero
  • Check that referenced fields have default values
  • Use parseInt() or parseFloat() to convert strings to numbers

Need Help with Complex Formulas?

Our support team can help you create custom pricing formulas for your specific use case.Contact us with your requirements.

Master Custom Formulas

Watch our video tutorial series on creating advanced pricing formulas

Watch Tutorial Videos