Give Totals Shortcode Presentation
under review
r
rik
Hi all, we did some development on this ourselves, and it is actually quite easy to report some nice totals for GiveWP on your website. I'm posting here the code so that everyone can use it. The code basically produces 4 shortcodes for:
- the total donated amount across all forms
- the total nr of donations
- the total nr of donors
- the total nr of forms
You can then put that shortcode in any place you like to make it look good. E.g. we use it in the "counter" elements of Elementor.
Here is how to produce the shortcodes:
Step 1. Download this plugin Code Snippets https://wordpress.org/plugins/code-snippets/
Step 2. Duplicate the "Example HTML shortcode" and give it a new name.
Step 3. Copy paste the following code into this snippet that you just gave a new name:
function givereturntotalamount_function() {
global $wpdb;
$result = $wpdb->get_results( "SELECT sum(meta_value) as result_value FROM {$wpdb->prefix}give_formmeta WHERE meta_KEY = '_give_form_earnings' ");
return $result[0]->result_value;
}
add_shortcode('givereturntotalamount', 'givereturntotalamount_function');
function givereturntotaldonations_function() {
global $wpdb;
$result = $wpdb->get_results( "SELECT sum(meta_value) as result_value FROM {$wpdb->prefix}give_formmeta WHERE meta_KEY = '_give_form_sales' ");
return $result[0]->result_value;
}
add_shortcode('givereturntotaldonations', 'givereturntotaldonations_function');
function givereturntotaldonors_function() {
global $wpdb;
$result = $wpdb->get_results( "SELECT count(purchase_count) as result_value FROM {$wpdb->prefix}give_donors WHERE purchase_count > 0 ");
return $result[0]->result_value;
}
add_shortcode('givereturntotaldonors', 'givereturntotaldonors_function');
function givereturntotalcharities_function() {
global $wpdb;
$result = $wpdb->get_results( "SELECT count(meta_value) as result_value FROM {$wpdb->prefix}give_formmeta WHERE meta_key = '_give_form_status' AND meta_value = 'open' ");
return $result[0]->result_value;
}
add_shortcode('givereturntotalcharities', 'givereturntotalcharities_function');
Step 4. Save and activate the snippet
Done! You can now use these 4 shortcodes anywhere on your site to produce these totals:
- the total donated amount across all forms: [givereturntotalamount]
- the total nr of donations: [givereturntotaldonations]
- the total nr of donors: [givereturntotaldonors]
- the total nr of forms: [givereturntotalcharities]
R
Rik
If the output for these data points is just a number, then we can use our own layout builders to visualize it as we want
r
rik
I agree. As an admin, i would like to have standard shortcodes, blocks or counters as part of the GiveWP plugin that provide analytics for our website visitors: total amount of donations, total number of donations, total number of donors and total number of forms. This should be just the number, so that, for example, the 'counter' blocks in Elementor can work with the output.
Kevin Hoffman
under review