Skip Navigation

[Resolved] calculation field 1 minus field 2

This thread is resolved. Here is a description of the problem and solution.

Problem:
calculation field 1 minus field 2

Solution:
To process the field value to subtract one value from another, you need to add custom shortcode shared with proposed solution to your current theme's functions.php file.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/calculation-field-1-minus-field-2/#post-955465

Relevant Documentation:

100% of people find this useful.

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 3 voices.

Last updated by thisaraN 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#955459

Hello team

I have two numerical fields in views (old price & new price), the new price is always sale, i would like to show the discount on the website

The fields are:

[types field='oude-prijs' format='FIELD_NAME: FIELD_VALUE'][/types] minus
[types field='aanbiedingsprijs' format='FIELD_NAME: FIELD_VALUE'][/types]

And show the result on the website , is that possible?

Thanks in advance
Greetings Pascal

#955465

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - to process the field value to subtract one value from another, you need to add custom shortcode to your current theme's functions.php file.

For example:

add_shortcode('wpv_subtract', 'func_subtract_value');
function func_subtract_value($atts,$content=null) {

$field1 = $atts['field1'];
$field2 = $atts['field2'];
$result = $field1 - $field2;

return number_format($result, 2, ',' , '.') ;
}

And call the above shortcode as given under:

[wpv_subtract  field1="[types field='oude-prijs'][/types]" field2="[types field='aanbiedingsprijs'][/types]"]

Could you please check and try to resolve your issue.

#956433

Hello Minesh

Thanks again for the great support!

Greetings Pascal

#1135733

This was helpful. Thanks!