Thanks Christian! I really appreciate the help.
A little more detail on what I'm trying to accomplish. I have a CRED form that will update a user's custom field for their weekly sales. When the user enters their sales via the CRED form, the code I'm providing subtracts the user's weekly quota (custom field) from the users weekly sales to total the difference (custom field updated with CRED form). All that works no problem but once the user enters sales above their weekly quota, it then goes into a negative number (See attached screenshot). To avoid that, I was trying to write an if statement and I think your input helps. I was not defining the field that I want to be updated when the difference is equal to or greater than the weekly quota. The custom field I want to change will be wpcf-difference. I revised my code to update that field but it didn't work so I am still messing something up. The revised code is as follows:
/** 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';
$sum_field3 = 'difference';
// if a specific form
if ( $form_data['id'] == 34183 || $form_data['id'] == 34200 )
{
// Sales
$wk1 = get_user_meta($post_id, 'wpcf-july-1-12', true);
$wk2 = get_user_meta($post_id, 'wpcf-july-13-19', true);
$wk3 = get_user_meta($post_id, 'wpcf-july-20-26', true);
$wk4 = get_user_meta($post_id, 'wpcf-july-17-august-2', true);
$wk5 = get_user_meta($post_id, 'wpcf-august-3-9', true);
$wk6 = get_user_meta($post_id, 'wpcf-august-10-16', true);
$wk7 = get_user_meta($post_id, 'wpcf-august-17-23', true);
$wk8 = get_user_meta($post_id, 'wpcf-august-24-30', true);
$contest_total = $wk1 + $wk2 + $wk3 + $wk4 + $wk5 + $wk6 + $wk7 + $wk8;
update_user_meta( $post_id, 'wpcf-' . $sum_field2, $contest_total );
//Quota
$weekly_quota = get_user_meta($post_id, 'wpcf-weekly-quota',true);
$quotacomplete = "Great Job! Add more sales for more changes to win!";
$weekly_difference = $weekly_quota - $wk1;
if ($weekly_difference >= $weekly_quota) {
update_user_meta( $post_id, 'wpcf-' . $sum_field3, $quotacomplete );
} else {
update_user_meta( $post_id, 'wpcf-' . $sum_field3, $weekly_difference );
}
}
}
/** END - Toolset custom fields for adding weekly sales **/
Thank you!!