Skip Navigation

[Resolved] Mathematical operations with Number custom field

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.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 6 months ago.

Assigned support staff: Beda.

Author
Posts
#376784

Can I perform mathematical calculation with data from a Number type custom field?
What I would like to do is this:
I have a price data in a Number field.
I have a discount value in another Number field.
I want to perform an operation that will output the discounted price.
Something like this:

[type field="price"][/type] * ([type field="discountrate" id="$discount"][/type]/100)

I know this particular code would never work, but can it be done somehow?

#376952

This is no possible with Toolset.

I can below give a example of a Custom ShortCode you can build to achieve such results.

Calculate Custom fields within a calculate ShortCode that acts like the PHP operator $value += $result

Register this 2 ShortCodes:

global $total;
function add_total_shortcode($atts, $content = '') {
global $total;
 
$total += wpv_do_shortcode($content);
}
 
add_shortcode('add-to-total', 'add_total_shortcode');
function show_total_shortcode() {
global $total;
$totalNew = $total;
$total = 0;
return $totalNew;
}
 
add_shortcode('show-total', 'show_total_shortcode');

Register those ShortCodes in Views > Settings > Compatibility > 3rd Party ShortCodes

Use the ShortCodes in a View as this:

<wpv-loop>
    
    [add-to-total]
      
    [/add-to-total]
</wpv-loop>
[show-total]

More info here:
https://toolset.com/forums/topic/nested-view-with-conditional-sums/

It seems -unfortunately- that for now you need custom programming work which is beyond the scope of our support.

At this point I would suggest you consider contacting one of our certified partners from this link:
https://toolset.com/consultant/

You will get the custom assistance you need to get on with your project.