Loading...

Your privacy choices

Google Analytics 4 measures site visits and Google Ads measures advertising clicks and checkout completions, only for the purposes you accept. Neither is required to buy. Necessary checkout services remain available.

Your privacy choices

Google Analytics 4 measures site visits and Google Ads measures advertising clicks and checkout completions, only for the purposes you accept. Neither is required to buy. Necessary checkout services remain available.

These optional Google services may set audience or advertising cookies after your acceptance. Analytics and advertising are separate choices. Acceptance and refusal are remembered in this browser for a fixed 180 days, without extending the period when read. You can withdraw or change your choices at any time using Privacy choices in the footer. Withdrawal removes optional first-party Google cookies and reloads the page if Google has already loaded (using session storage in this tab if persistent storage refuses the withdrawal; a blank page opens only if both stores cannot safely record the withdrawal and a stale approval remains). Checkout, external demos, videos, support and newsletter services have their own privacy information.

Complete Documentation

Documentation

Everything you need to know about WP Cost Estimation

Prices & Quantity Calculations

Section 13•5 min read

Set up price formulas, quantity rules and conditional calculations.

Price and Quantity Calculations with WP Cost Estimation & Payment Forms Builder

Learn how to create dynamic pricing and quantity calculations in your forms using the powerful calculation engine.

Calculation Engine Overview

The plugin provides a robust system for calculating prices, quantities, and other variables:

The custom calculation engine utilizes the JavaScript language, supporting any JavaScript syntax and functions, including those from the Math object.

JavaScript Support

Use the full power of JavaScript to create complex calculations, including variables, functions, loops, and conditional statements.

Special Shortcodes

Use special shortcodes to access form element values, prices, and quantities in your calculations.

Shortcodes and Syntax

Beyond standard JavaScript, the plugin incorporates special shortcodes. For example, the [price] shortcode represents the calculation result, formatted as:

[price] = 110.00

Additional shortcodes can retrieve the value, price, or quantity of any form element. These don't have to be written manually; simply use the "Add a value" button to visually select an element, and the plugin will insert the corresponding shortcode:

[price] = [item-1_value]

Arithmetic Operators

Key arithmetic operators include:

Addition

+

Subtraction

-

Multiplication

*

Division

/

Conditional Calculations

For conditions, the "Add a condition" button provides access to the conditions panel:

Conditions Panel
Conditions Panel

Create conditions using the "Add a condition" button and the condition dropdowns. A dropdown at the top of the list specifies if all conditions must be met or just one for the condition to apply.

After saving in the conditions panel, the plugin automatically generates the condition syntax:

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

}

In this scenario, the default price is $10, adjusted to $20 if certain conditions are met.

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

Advanced Conditional Logic

Leveraging full JavaScript syntax, nested conditions and "else" statements are also possible:

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

Special Calculation Features

Distance Calculations

The "Add a distance" feature, enabled when the "Google Maps API key" is configured, calculates distance or travel time between addresses from form fields, returning a shortcode like [distance-1-2].

Date Difference Calculations

The "Date difference" button calculates the days between dates from two datepickers in the form.

Distance Calculations

Learn how to calculate distances and travel times between addresses in your forms.

The "Add a distance" button will be available only if the "Google Maps API key" option is filled in the form settings.

How Distance Calculation Works
  • It allows you to calculate the number of miles/km or the travel duration between addresses from text fields in your form.
  • The plugin uses the "Type of information" option of the text fields to detect available address fields.
  • Select the address fields you want to calculate distance between using the "Add a distance" button.
  • The result will be a shortcode like [distance-1-2] in the calculation code.
  • This shortcode will return the calculated distance when the calculation is executed.
Example Usage
[price] = 10 + ([distance-1-2] * 2.5)

This calculation adds a base price of $10 plus $2.50 per distance unit (mile/km) between the two addresses.

Calculation Examples

Basic Price Calculation
[price] = [item-1_value] * 10

This sets the price to 10 times the value of item-1.

Quantity Based on Multiple Items
[quantity] = [item-1_value] + [item-2_value]

This sets the quantity to the sum of the values of item-1 and item-2.

Conditional Pricing with Multiple Options
[price] = 100
if([item-1_value] == "option1") {
  [price] = 150
} else if([item-1_value] == "option2") {
  [price] = 200
} else if([item-1_value] == "option3") {
  [price] = 250
}

This sets different prices based on which option is selected in item-1.

Using Math Functions
[price] = Math.round([item-1_value] * 1.5)

This multiplies the value of item-1 by 1.5 and rounds the result to the nearest integer.

Pro Tip: For complex calculations, break down your logic into smaller, manageable parts. This makes it easier to debug and maintain your calculations. You can also use JavaScript variables to store intermediate results.

Keep moving

Useful next steps from documentation