🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!
Guides & Tutorials October 13, 2026

Gravity Forms If Statement in Calculations: Tiered Prices, Dates and Minimum Charges

GravityExtra
Gravity Forms If Statement in Calculations: Tiered Prices, Dates and Minimum Charges

Gravity Forms calculations are great for simple totals: hours times rate, quantity times price. The moment a client asks for a 10% discount above ten hours, a minimum charge, a price per night between two dates or a fee per ticked checkbox, the formula box runs out of road. You type an if statement, click Validate Formula and Gravity Forms tells you it is invalid, or the field quietly shows 0.

This guide shows why that happens, the usual workarounds, and how the Gravity Forms Logic & Math Pro Premium Add-on lets you write if(), comparisons, min, max, rounding, date differences, age and checkbox counts straight into the formula box, with live results and a server-side recalculation on every submission.

Why Standard Gravity Forms Formulas Hit a Wall

A Gravity Forms formula understands numbers, field merge tags, the four operators + – * / and brackets. That covers a surprising number of forms, but real pricing rarely stays that simple. Agencies quoting projects, venues taking bookings and service businesses building estimate forms all need decisions inside the maths.

Without a decision function you end up with workarounds: several hidden calculation fields, each shown or hidden by conditional logic, and a total that adds up whichever one is visible. It works for one rule. With three or four rules the form becomes a maze that nobody wants to edit six months later.

Formulas that standard Gravity Forms cannot write
Tiered or discounted prices. “10% off when more than 10 hours are booked” needs an if statement.
Minimum and maximum charges. “Bill at least 2 hours and never more than 40” needs min() and max().
Dates. Nights between check-in and check-out, or a guest’s age from a date of birth.
Checkbox maths. Adding the values of ticked extras, or counting how many were ticked.

Your Options Today

1. Hidden fields and conditional logic

Build one calculation field per scenario and show the right one with conditional logic. No extra cost, but every new rule doubles the number of fields to maintain, and it still cannot handle dates or counts.

2. Custom code with gform_calculation_result

Gravity Forms offers a filter for changing calculation results with PHP and a matching JavaScript filter for the browser. A developer can write any logic, but has to keep the PHP and JavaScript versions identical, or the live total and the stored total will disagree. Each formula change means another code change.

3. Other calculation add-ons

Other Gravity Forms add-ons add functions and conditionals to formulas. They are capable options, usually sold as one of several separate add-ons, each bought, set up and updated on its own.

Comparison: Ways to Add Logic to Calculations

Logic & Math Pro add-on Hidden fields workaround Custom code Other add-ons
if() and comparisons Yes, in the formula box Via extra fields Yes, in PHP and JS Yes
Date maths days_between, age, weekday, today No If you write it See vendor docs
Checkbox sum and count Yes No If you write it See vendor docs
Live and server results match Same formula both sides Yes Only if both are kept in sync Yes
Editor helper Insert function, reference, validation No No See vendor docs
Cost From $39/year (1 site) $0 Developer time Varies per add-on

Other vendors’ prices are from their public pricing pages at the time of writing and may change.

What Logic & Math Pro Does

Logic & Math Pro works inside the formula box you already know: a Number field with Enable Calculation, or a Calculated product field. Formulas that only use + – * / keep working exactly as before.

  • if(condition, a, b). Return one value when a condition is true and another when it is false, for tiered prices, discounts and minimum charges.
  • Comparisons and logic. =, !=, >, <, >=, <= anywhere in a formula, plus and(), or() and not().
  • Maths functions. min(), max(), sum(), round(x, decimals), floor(), ceil(), abs(), pow(), sqrt() and mod().
  • Date functions. days_between(), age(), weekday() and today() for every Date field input type and date format.
  • Choice sums and counts. A Checkboxes or Multi Select field adds up the selected values, and count() returns how many are ticked.
  • Form editor helper. Insert function and Insert date or choice field menus above the formula box, a function reference and Validate Formula.
  • Safe by design. A built-in parser that only knows the listed functions; nothing in a formula is ever run as code, and division by zero gives 0.

Results update live as visitors fill in the form. When the form is submitted, Gravity Forms recalculates every calculation field on the server and the add-on evaluates the same formula there, so a value changed in the browser is never stored. The script only loads on forms that use the functions.

How to Set It Up, Step by Step

You need WordPress 6.5 or higher, PHP 7.4 or higher, Gravity Forms 2.9.4 or higher, a Number field with Enable Calculation or a Calculated product field, and an active GravityExtra license.

Step 1: Install the add-on and choose function groups

Upload and activate the add-on, then go to Forms → Settings → Logic & Math and activate your license key. Reload the page to see the Formula functions section with three switches, all on by default: Math & logic functions, Date functions and Choice count & sum.

Each form also has a Use formula functions on this form switch under Settings → Logic & Math. When it is off, that form works exactly like standard Gravity Forms and the add-on loads nothing on it.

Step 2: Write your formula with the helper

Edit a form, add a Number field and tick Enable Calculation, or use a Product field with the Calculation field type. Above the formula box you get Insert function and Insert date or choice field drop-downs, so you do not have to remember the syntax. Function reference opens a one-line description of every function.

Click Validate Formula. A formula with an unknown function, the wrong number of values or an unclosed bracket is reported as invalid before a visitor ever sees it. Then pick the rounding and save.

Form editor calculation options with the Insert function and Insert date or choice field drop-downs
The helper above the formula box: insert functions and date or choice fields in one click.

Step 3: Build a tiered price with if()

For 10% off when more than 10 hours are booked, write if({Hours:1} > 10, {Hours:1} * {Rate:2} * 0.9, {Hours:1} * {Rate:2}). For a minimum charge of 2 hours and a maximum of 40, wrap the hours in min(max({Hours:1}, 2), 40). Comparisons return 1 when true and 0 when false, so you can also multiply by them directly.

Project quote form showing a discounted subtotal and a calculated package price
A project quote form with a discounted subtotal and a calculated package price, updating live.

Step 4: Calculate with dates

Insert two Date fields and use days_between({Check-in:1}, {Check-out:2}) to get the number of nights. To keep a room total from ever going negative, write if(days_between({Check-in:1}, {Check-out:2}) > 0, days_between({Check-in:1}, {Check-out:2}) * 120, 0). Use age({Date of birth:3}) for age checks and weekday() for weekend surcharges, where 6 and 7 are Saturday and Sunday.

An empty or incomplete date counts as 0, so the total stays at 0 until both dates are filled in. today() uses the timezone set in Settings → General.

Room booking form calculating nights, guest age, weekday and room total from Date fields
Nights, guest age, weekday and room total calculated from Date fields.

What’s new in version 1.2: rules based on who fills in the form

Some fields only make sense for some people: a member discount code for logged-in members, internal notes for your editors, a “create an account” box for visitors who are not logged in. Version 1.2 of the Gravity Forms Logic & Math Pro Premium Add-on adds visitor rules for exactly that: logged in status, user role and user meta.

Show a field to logged-in Gold members and to editors

  1. Open the form, go to Form Settings → Logic & Math and add a rule set, for example “Gold members and staff”.
  2. Click Add visitor condition and choose Visitor: logged in status → is logged in.
  3. Add an OR group with Visitor: user meta membership_level → is → Gold, and Visitor: user role → is → Editor.
  4. In the conditional logic of the “Member discount code” field, pick Rule set: Gold members and staff.
Rule set Gold members and staff: logged in status is logged in, AND any of user meta membership_level is Gold or user role is Editor
Visitor conditions mixed in AND / OR groups inside a rule set.

You do not have to use a rule set: the same three sources, listed as “Visitor: …”, also appear at the end of the field list in Gravity Forms’ own conditional logic for fields, pages, the submit button, notifications, confirmations and feeds. User role rules work with every role on your site, custom roles included. User meta rules compare with is, is not, contains, is empty or is not empty.

Form showing the Member discount code field to a logged-in Gold member
The same form for a logged-in Gold member: the discount code field is shown.

Only the meta keys you allow

User meta rules work only with the keys you list under Forms → Settings → Logic & Math → User meta keys for visitor rules, one per line, such as membership_level. The list is empty by default, and keys for passwords, tokens, sessions and capabilities are never accepted.

Checked on the server

Visitor rules are worked out on the server. The page only receives true or false for each rule, never a role list or a meta value, and every rule is checked again when the form is sent, so a field hidden from a role is not validated or saved whatever the browser posts. After submission, notifications, confirmations and feeds use the person who submitted the entry, so resending a notification later gives the same result. Pages with a form that uses visitor rules are marked “do not cache”; forms without visitor rules work and cache exactly as before.

All comparisons, the meta key allow-list and the caching notes are in the documentation.

Pro Tips for Production Forms

  • Give checkbox choices numeric values. Turn on show values and give each choice a number, then add the whole field, such as {Extras:7}, to the formula to sum the ticked extras.
  • Use count() for per-item fees. count({Extras:7}) * 15 charges 15 for every ticked option, whatever the choice values are.
  • Set your timezone to a city. Age and day counts use Settings → General. A city avoids off-by-one results around daylight saving changes.
  • Keep formulas readable. Split very long logic over two Number fields, for example a subtotal and a final price. Formulas can be up to 2,000 characters.
  • Remember hidden fields count as 0. A field hidden by conditional logic contributes 0, just as in standard formulas, which is handy for optional extras.
Our recommendation

Replace your hidden-field workarounds one form at a time. Start with the formula that has the most conditional fields, rewrite it as a single if() formula, validate it and test a few combinations on the front end before you delete the old fields.

Write the Formulas Your Clients Ask For

if(), min, max, rounding, date maths and checkbox counts in the Gravity Forms formula box, live in the browser and recalculated on the server. Plans start at $39/year for one site, $69 for five sites and $149 for ten.

or read the Logic & Math Pro setup guide

Frequently Asked Questions

Do my existing formulas change?

No. Formulas that only use + – * / and brackets are left to Gravity Forms exactly as before.

Can a visitor change the calculated value?

No. Gravity Forms recalculates every calculation field on the server when the form is submitted, and the add-on evaluates the same formula there.

Which fields can use the functions?

Number fields with Enable Calculation and Calculated product fields. Text and Hidden fields cannot use them yet.

Does it change conditional logic?

No. It adds functions to formulas only. Conditional logic for fields, notifications and feeds works as before.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr