<?php
// http://pastebin.com/kHpaHQvi originally
// http://www.gravityhelp.com/forums/topic/show-total-donations
// usage: [donations form=9] where 9 is the form ID
add_shortcode('donations', 'total_donations');
function total_donations($atts) {
$form_id = $atts['form'];
$start_date = $atts['start_date'];
$end_date = $atts['end_date'];
// function to pull all the entries for one form
$donations = RGFormsModel::get_leads($form_id);
// start the total at zero
$total = 0;
echo "C "; echo $start_date; echo " по ";
echo $end_date;
// initialize a counter for the number of donations made
$i = 0;
// loop through all the returned results
foreach ($donations as $amount) {
// add each donation amount to the total
// change 3 here to the field ID which holds the donation amount
$data = $amount[49];
if ($data >= $start_date && $data <= $end_date){$total += $amount[48];}
// increment the counter so we know how many donations there are as well
$i++;
}
// do some formatting and return the html output from the shortcode
$output = "Итого продаж $total";
// just the string above will be returned. You can style it here or where you are using the shortcode
return $output;
}
// needed for the above to process the donation shortcode in sidebar widget
add_filter('widget_text', 'do_shortcode');
?>