Hi there,
I've found some code in one of your old support threads to calculate the sum of fields wrapped in [add-to-total][/add-to-total] but I wondered how to duplicate and alter the code to allow me to calculate the total of a separate group of fields (in this case, the first group is the total of the cost out, I'd like a separate total of cost in fields)
Original thread - https://toolset.com/forums/topic/custom-fields-calculations-sum-total-of-two-fields/
I presumed that I could just take this:
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');
and amend it to add a '2' after the shortcode names to give:
global $total;
function add_total_shortcode_2($atts, $content = '') {
global $total;
$total += wpv_do_shortcode($content);
}
add_shortcode('add-to-total-2', 'add_total_shortcode_2');
function show_total_shortcode_2() {
global $total;
$totalNew = $total;
$total = 0;
return $totalNew;
}
add_shortcode('show-total-2', 'show_total_shortcode_2');
And then use [add-to-event-2] and [show-total-2] as the shortcodes, but that didn't work.
Any pointers would be most appreciated.
Best regards
James