1) For your first number, total points, you can use a CRED hook called 'cred_save_data':
https://toolset.com/documentation/user-guides/cred-api/#csd
So, if your CRED form ID is 123 you can do something like this:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
// if a specific form
if ($form_data['id']==123) {
// get the individual ratings
$rating1 = get_post_meta( $post_id, 'wpcf-rating1', true );
$rating2 = get_post_meta( $post_id, 'wpcf-rating2', true );
$rating3 = get_post_meta( $post_id, 'wpcf-rating3', true );
$rating4 = get_post_meta( $post_id, 'wpcf-rating4', true );
$rating5 = get_post_meta( $post_id, 'wpcf-rating5', true );
$rating6 = get_post_meta( $post_id, 'wpcf-rating6', true );
$rating7 = get_post_meta( $post_id, 'wpcf-rating7', true );
$rating8 = get_post_meta( $post_id, 'wpcf-rating8', true );
$rating9 = get_post_meta( $post_id, 'wpcf-rating9', true );
$rating10 = get_post_meta( $post_id, 'wpcf-rating10', true );
// add them up and save
$total = $rating1+$rating2+$rating3+$rating4+$rating5+$rating6+$rating7+$rating8+$rating9+$rating10;
update_post_meta($post_id, 'wpcf-total-rating', $total);
}
}
This code is calculating a total for each review.
2) To calculate a grand total you can use a similar approach, but you would store it in the options table instead:
add_action('cred_save_data', 'another_save_data_action',20,2);
function another_save_data_action($post_id, $form_data) {
global $wpdb;
// if a specific form
if ($form_data['id']==123) {
// Sum totals
$totals = $wpdb->get_row("SELECT COUNT(*) as num, SUM(meta_value) as total $wpdb->postmeta WHERE meta_key = 'wpcf-total-rating'");
// calculate average
$average = round( $totals->total / $totals->num, 2);
// save
update_option('total-average', $average);
}
}
3) You will need a custom shortcode to display the grand total.
For example:
add_shortcode('total-average', 'total_average_shortcode');
function total_average_shortcode() {
return get_option( 'total-average' );
}
This will allow you put the following code somewhere:
<h2>Average Ratings: [total-average]</h2>
Please let me know if you are satisfied with my reply and any other questions you may have.
Regards,
Caridad