Help Center

Calculated Callback Add-on

Calculated Callback Add-on

Learn how to perform arithmetic operations in the Dynamic Field with the help of the JetEngine Calculated Callback add-on.

Before you start, check the tutorial requirements:

  • Elementor (Free version) or Block editor (Gutenberg)

  • JetEngine plugin installed and activated with the Listing template for the CPT created. If you haven't done it yet, proceed to this tutorial

You can perform mathematical calculations using the JetEngine Dynamic Field and Calculated Callback add-on.

The initial step is downloading the callback add-on from the JetEngine plugin. Proceed to the DevTools page and press the “Download” button next to the Calculated Callback add-on.

calculated callback addon

Go to the WordPress Dashboard > Plugins > Add New directory. Push the “Upload Plugin” button.

Once done, you can upload the item manually by pressing the “Choose File” button or drag-n-drop .zip format file to the highlighted field.

After the file has been selected, the “Install Now” button becomes available, click it, and don’t forget to press the “Activate Plugin” button on the proceeding installing step.

add new plugin directory

The Calculated Callback add-on works with the Number meta fields, so ensure to add such a meta field to the CPT for which the Listing template was created and fill the value for several posts.

Proceed to the page where you want to place the Dynamic Field. For instance, we will open a Listing template. You can also use a Single or an Archive template. 

Add a Dynamic Field if you haven’t done it yet.

We choose “Meta Data” as the Source and the “Price per 1 day/night” option in the newly appeared Meta Field.

Warning

“Price per 1 day/night” option stands for the JetEngine Meta Field of the number type as we perform arithmetical operations.

dynamic price meta field in elementor

Scroll down to the Filter Field Output toggle and activate it.

In the Callback drop-down menu, select the “Calculated field” option.

Pick the desired callback in the Calculated callbacks field.

Increase Value by Percentage

When this value is chosen, set the desired percent in the Additional arguments field, and the result will be counted and displayed straight away.

increase value by percentage callback

Decrease Value by Percentage

This time, value input in the Additional arguments field will be subtracted from the meta field value.

decrease value by percentage callback

Sum Fields

In the Additional arguments field, paste the Meta Field Key of the field you want to sum with the meta field you have chosen as the Dynamic Field source.

sum fields callback

Fields Difference

Subtract the desired value from the editable dynamic field. To do so, paste the required Meta Field Key in the Additional arguments field.

fields difference callback

Multiple Fields

Fill in the Additional arguments field with the meta field you want to use as the second source for multiplication.

As you can see, now the default price has been multiplied by eight.

multiple fields callback

Custom Callback

Warning

Before proceeding with the next steps, create a backup or replicate the actions on the staging site. The backup ensures the website restoration if an error occurs. To learn more, proceed to the How to Backup and Restore a WordPress Website with a Plugin article.

Besides, you can also set a custom callback. Look at the available example.

config example

Head to WordPress Dashboard > Appearance > Theme Editor and paste the code in the Theme Functions of your active WordPress theme.

You can change the name of your callback by typing it instead of the ‘custom_callback’ value.

Moreover, mind altering the ‘guests-number’ into the meta field you want to use as an additional arithmetical value.

In our case, the result will be calculated based on the number of guests. Depending on whether there are fewer or more guests than 10, the formula will change.

You can also change any needed calculation conditions. Push the “Update File” button once the code is ready.

theme editor custom callback

Move to the template you want to edit and scroll down to Filter field output. Enable this toggle and select the “Calculated field” from the Callback drop-down menu.

Pick the created custom callback among the available options in the Calculated Callbacks. Once done, the price of the custom post will already be calculated.

In this case, this part of the formula works:

elseif ( 5 <= $additional_field_value && $additional_field_value < 10 ) {
	$result = $field_value * $additional_field_value - $field_value * $additional_field_value * 0.1;
custom callback

Besides, you can use the Customize field output feature. Type the desired characters before and/or after the “%s” sign.

customized field output

Whenever you are ready, click on the “Publish/Update” button to save the changes and head to the page you want to place the listing.

Place the Listing Grid widget on the page. Select the Listing you have just created.

listing grid with custom callback in elementor

Once all the Listing Grid settings are adjusted, click on the “Publish/Update” button. Let’s check the result.

listing grid with custom callback on the front end

Everything works fine. The price is calculated depending on the number of guests, the price entered in the custom post type meta fields, and the formula pasted in the Theme Editor.

Now you know how to use the Calculated Callback add-on by the JetEngine plugin.

Was this article helpful?
YesNo

Need help?

Ask Facebook community

Get answers from 22K Crocoblock Community experts from all over the world.

Start a live chat

Ask question to support agent and share its details via chat messages.