Stand with Ukraine. Fight for freedom and democracy

Donate
Back to contents

JetEngine DevTools: Calculated Callback Add-on

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

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

The initial step is activating the callback add-on from the JetEngine plugin. Follow the link and copy the code.

Go to the Appearance > Theme Editor directory. Click on the Theme functions tab of your active WordPress theme and paste the code you have copied earlier.

Push the “Update File” button.

functions php calculated callback

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.

NOTE
“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

Besides, you can also set a custom callback. The example you can find by following this link.

config example

Head to 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 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, price entered in the custom post type meta fields, and formula pasted in the Theme Editor.

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