Tell us what you are trying to do? I currently have code that adds up multiple custom fields and posts the value in another custom field. This equation calculates the yearly total. As a new project, I need to calculate weekly totals using different custom fields without messing up the other addition problem. My code for both equations is below:
/** Toolset custom fields for adding yearly sales **/
add_action('cred_save_data', 'sum_monthly_sales',10,2);
function sum_monthly_sales($post_id, $form_data)
{
$sum_field = 'yearly-sales';
$forms = array( 15813 );
// if a specific form
if ( in_array( $form_data['id'], $forms ) )
{
$value1 = get_post_meta($post_id, 'wpcf-january-sales', true);
$value2 = get_post_meta($post_id, 'wpcf-february-sales', true);
$value3 = get_post_meta($post_id, 'wpcf-march-sales', true);
$value4 = get_post_meta($post_id, 'wpcf-april-sales', true);
$value5 = get_post_meta($post_id, 'wpcf-may-sales', true);
$value6 = get_post_meta($post_id, 'wpcf-june-sales', true);
$value7 = get_post_meta($post_id, 'wpcf-july-sales', true);
$value8 = get_post_meta($post_id, 'wpcf-august-sales', true);
$value9 = get_post_meta($post_id, 'wpcf-september-sales', true);
$value10 = get_post_meta($post_id, 'wpcf-october-sales', true);
$value11 = get_post_meta($post_id, 'wpcf-november-sales', true);
$value12 = get_post_meta($post_id, 'wpcf-december-sales', true);
$res = $value1 + $value2 + $value3 + $value4 + $value5 + $value6 + $value7 + $value8 + $value9 + $value10 + $value11 + $value12;
update_post_meta( $post_id, 'wpcf-' . $sum_field, $res );
}
}
/** END - Toolset custom fields for adding yearly sales **/
/** Toolset custom fields for adding weekly sales**/
add_action('cred_save_data', 'sum_weekly_sales',10,2);
function sum_weekly_sales($post_id, $form_data)
{
$sum_field2 = 'contest-total';
$forms2 = array( 34183 );
// if a specific form
if ( in_array( $form_data['id'], $forms2 ) )
{
// Sales
$wk1 = get_post_meta($post_ID, 'wpcf-july-1-12', true);
$wk2 = get_post_meta($post_ID, 'wpcf-july-13-19', true);
$wk3 = get_post_meta($post_ID, 'wpcf-july-20-26', true);
$wk4 = get_post_meta($post_ID, 'wpcf-july-17-august-2', true);
$wk5 = get_post_meta($post_ID, 'wpcf-august-3-9', true);
$wk6 = get_post_meta($post_ID, 'wpcf-august-10-16', true);
$wk7 = get_post_meta($post_ID, 'wpcf-august-17-23', true);
$wk8 = get_post_meta($post_ID, 'wpcf-august-24-30', true);
$contest_total = $wk1 + $wk2 + $wk3 + $wk4 + $wk5 + $wk6 + $wk7 + $wk8;
update_post_meta( $post_ID, 'wpcf-' . $sum_field2, $contest_total );
}
}
/** END - Toolset custom fields for adding weekly sales **/
Is there any documentation that you are following? I needed help with this previously so this is my previous support post where we figured out the first equation.
https://toolset.com/forums/topic/adding-custom-fields-together-into-custom-field-that-displays-the-total-sum/
Is there a similar example that we can see? hidden link
What is the link to your site? hidden link