If you include a tag in your Product Add-Ons Ultimate calculation formula for a field that doesn’t exist on the page, the calculation will normally return an empty value.
This means that if you have a formula like {field_123} + {field_456} you’ll only get a result if you have fields with the IDs 123 and 456 present on the page.
However, you might prefer the calculation to ignore a field if it’s not present and still return a value for those fields that are present. To enable this:
- Go to WooCommerce > Settings > Product Add-Ons > Calculations
- Enable the ‘Zero value for missing fields’ option.
The benefit of this option is that it allows you to create a single global calculation field which includes values for multiple fields, not all of which might be present on a single product.
Why might calculation fields be hidden?
Calculation fields are most likely to be hidden on the product page through conditions. If field #456 is hidden through a condition, then any calculation that includes a reference to it will not return a value unless you have the ‘Zero value for missing fields’ option enabled.
Why is it useful to return 0 for hidden fields?
Say you sell a product in Small, Medium and Large sizes. Only the Large variation has an extra field, which you show using a condition so it only appears when the customer picks Large.
Your pricing formula for the whole product might be something like:
{field_10} + {field_12} * 2
where field_12 is the extra field that only displays for the Large variation.
When a customer selects Small or Medium, field_12 wouldn’t return a value and the calculation would break. However, enabling “Zero value for missing fields” means that field_12 would just return 0 if it was hidden – allowing your formula to work correctly whatever fields were displayed on the page.