View Categories

Calculations

The User Registration & Membership plugin’s Calculations addon allows you to perform real-time calculations based on user input in registration forms. So, automate costs, integrate payments, and deliver clarity to boost conversions using this guide for installing and using the Calculation addon in WordPress form.

Prerequisites:

  • User Registration & Membership Pro installed and activated.
  • Calculation Addon is available on User Registration & Membership Pro v4.1.0+, so make sure your plugin is updated to the latest version.

Install User Registration & Membership Pro (If Not Installed) #

To use the Calculation Addon, ensure User Registration & Membership Pro is installed and activated. If not, purchase it from wpuserregistration.com and follow our guide on activating it with a license key. The addon is available for Plus and Professional plans.

Activate the Calculation Addon #

  1. Navigate to User Registration & Membership > Addons in your WordPress dashboard.
  2. Locate the Calculation Addon and toggle to Activate.

Using the Calculation Addon in Forms #

Follow the steps below to configure the calculation addon in forms:

Step 1: Create or Edit Form #

  1. Navigate to User Registration & Membership > All Forms
  2. Click the Add New button to create or edit the existing form.

Step 2: Add Calculation Field #

You can enable the calculations on supported fields in the form builder.

  1. Drag and drop any field (e.g., Number) into your form
  2. Click on the field to open the settings
  3. On the left, you’ll see the Field Options tab, so scroll and click on the Calculation Settings
  4. Toggle to enable the Calculations
Note: You can only enable calculations on the Number field to display the results.  

Step 3: Configure Calculation Settings #

Expressions: It contains all the calculation expressions that you can set. It supports 27 operators, including parentheses “( )”.

< >: Click on this icon to select the form field you used on your current form. After you choose the field, it will display the field IDs (e.g., the field ID for Username is $FIELD_user_login)

Validate Formula: Once you use the expression on the form fields, you can click on Validate Formula to verify whether the formula is correct.

Supported Operators #

Mathematical Operators #

  • Division: /
  • Multiplication: *
  • Addition: +
  • Subtraction:

Conditional Operators #

Conditional operators let you display results based on user input. Here’s how they work:

  • if( ): Runs calculation is a condition is true
  • elseif( ): Checks a new condition if the first if( ) is false
  • else( ): Runs calculation if all previous conditions are false

Mathematical Functions #

  • abs( ): Returns the absolute value of any given number.  
  • average( ): Returns the mean or average between a set of numbers.  
  • ceil( ): Rounds a number up to the nearest integer.  
  • exp( ): Returns e raised to the power of the given number. 
  • floor( ): Rounds a number down to the nearest integer.  
  • ln( ): Returns the natural logarithm of any number.  
  • log( ): Return the base -10 logarithm of different numbers:
  • max( ): Returns the highest value among the input arguments.
  • min( ): Returns the lowest value among the provided arguments.
  • num( ): Converts a given value to a number. 
  • pi( ): Returns the value of π. 
  • pow( ): Returns the result of raising a number to the power of another number.
  • rand( ): Returns a random number, usually between 0 and 1, or within a specified range.
  • round( ): Rounds a number to the nearest integer or to a specified number of decimal places.
  • sqrt( ): Returns the square root of a number. 
String and Text Functions #
  • trim( ): Removes whitespace from the beginning and end of a string 
  • truncate( ): Returns the first length characters of the string. 
  • concat( ): Combines two or more strings into one string.

Valid and Invalid Expressions: #

When you add an expression with correct operator signs and fields, the ‘Formula is valid‘ message is shown below the expression field. 

Otherwise. the ‘Formula is invalid’ message is shown below.

Avoid Using the Following Operators #

  • The ^ sign is replaced with pow( ). If you were previously using the ^ operator for returning the power of a number, you’ll now have to do so with the pow( ) function.
  • Operators not listed on the Expressions are not supported.

Example of Using Calculations in User Registration Form #

In this example, we are creating a user registration form for an event where users can register and buy more than one ticket. Using the number field, we will calculate the total amount the user has to pay.

First, let’s add the necessary form fields.

Here, the Quantity of ticket and Total Price are the number fields where we have changed the label. Now, on the Total Price field, we will perform the calculation using the expressions.

First of all, it should know which ticket type the user has selected, and then multiply it by quantity of the ticket.

Once the formula is valid, you can save the changes or update the form.

Frontend View: #

Similarly, you can use other expressions and perform the calculations.

Powered by BetterDocs

Scroll to top