Troubleshooting formula-based pricing
Are you using (complex) formulas, but your product’s grand total is incorrect or remains zero? Then there is a high chance your formula is wrong. Below are some tips on finding the issue.
The basics
- Make sure your formula really is a formula. If your formula is just a simple number, then it is not a valid formula. If you want your product price to increase with a number, you should select “flat fee” or “quantity-based flat fee” as the pricing type.
- If you’re using functions inside your formula (such as
round
orceil
), make sure the functions are available in your version of the plugin. We have a “Pro” and “Extended” version and most functions are only available in our Extended version. You can check the complete list of available functions (and in which version they’re available). - When using functions inside formulas, make sure you use the semicolon
;
character to divide function parameters. Do not use a comma. - Make sure there are no typos in the formula. Here are 2 common mistakes:
- Don’t use spaces inside shortcodes. For example, the shortcode to get the base product price
[price]
. Don’t write[ price ]
. It’s subtle, but notice how it has spaces inside the square brackets. That’s not allowed. - Do not use curly brackets with shortcodes. The correct writing is
[price]
, not{price}
.
- Don’t use spaces inside shortcodes. For example, the shortcode to get the base product price
Dive deeper
If the above basic checks didn’t fix your issue, you can do the following checks to further debug your formula:
Use sufficient brackets
Make sure to use sufficient brackets to group operations. If you don’t do it, your formula may produce unwanted results.
Consider this example: 2 * 4 + 1
. It’s dubious because it’s not clear what should be executed first: 2 * 4
or 4 + 1
and both ways would have a different result (9
or 10
, in this example).
You should instruct the system which operation to perform first by using brackets. For example 2 * (4 + 1)
results in 10
because you instructed the system to calculate 4+1
first.
[field] shortcode should point to numeric values
When using the [field.ID]
shortcode in your formula, make sure the field points to a proper numeric value.
For example, say you have a field of type Select that has a few options like this: 10 sqm
, 20 sqm
, 30 sqm
, etc… Pointing to this field with the shortcode [field.ID]
will not work because 10 sqm
is not a valid number, it is text because “sqm” is not a number.
One solution to solve this is to remove all instances of “sqm” from your field’s options. This is easy but not the best approach because keeping information in the options makes things clearer for your customers.
Instead, you can map field values to numbers by using the Variables feature to solve this.
Simplify complex formulas
If you’re using long or complex formulas, break it up in smaller parts during testing.
For example, if you have a complex formula (A + B) * (C + D)
, you can first save your fields using only a part of the formula, like (A + B)
. Test your product, and if it works, you know the error is somewhere in the other part (C + D)
.
If a smaller part works, you know the whole formula is at fault and you can start to fine-tune which part has the error.
Lookup tables
If you’re using lookup tables in your formulas, we’ve written a detailed guide on how to troubleshoot issues with your lookup table here.
I’m still getting unwanted results
Have you checked the above list but are still getting an error? Please contact support so we can help you out!