The Calculation field

The Extended version of Advanced Product Fields comes with a “Calculation” field type. This field allows you to perform custom calculations using formulas. It serves two main purposes:

  1. Display calculated information: for example, you can calculate and display the total surface area (e.g., square feet or square meters) based on user input.
  2. Add extra costs: you can calculate an additional price and have it added to the final product price.

Below is an example image illustrating both use cases. You can test the actual demo product here.

Examples of the calculation field

The first calculation displays the total surface area, based on the width and height entered by the user. This calculation is purely informational and does not affect the product price.

The second calculation displays the total product cost, based on the same inputs. Unlike the first, this one does adjusts the final product price.

Creating a calculation field

To add a calculation field to your product, follow these easy steps:

  1. Edit the WooCommerce product you’d like to add a calculation to (or create a global field group instead).
  2. In the Custom Fields section of your product, click Add a Field and choose Calculation as the field type. A number of new settings will appear:
    The backend settings for APF's calculation field
  3. Configure the settings:
    • Label: this is the text that appears on the left of the calculation.
    • Calculation Type: choose whether this is a purely informational calculation or one that alters the final product price. If it changes the price, the result will be added to or subtracted from the product’s total price.
    • Formula: in this section, you can write any mathematical or “Excel-alike” formula to calculate your result. If you are new to writing formulas for our plugin, we recommend reading our “Getting Started with Formulas” article!
    • Result Text: use this to add a prefix or suffix to the calculated value. For example, to show “square ft.” after the number, enter: {result} square ft.

Here are the settings for the “Total Surface Coverage” calculation in the example image above:

Example backend settings for APF's calculation field

While this example is fairly simple, there are a lot of complex use-cases that can be built using this field type!

Was this article helpful?

Related Articles