Home Forums General Issues Calculate fields and update the "total field" Reply To: Calculate fields and update the "total field"

  • Hi @dilladakilla

    You should be able to do this by using the update_field() function. It should be something like this:

    $field1 = floatval(get_field('falt_1','user_'. $curauth->ID));
    $field2 = floatval(get_field('falt_2','user_'. $curauth->ID));
    $field3 = floatval(get_field('falt_3','user_'. $curauth->ID));
    $total = ($field1 * $field2) * $field3;
    update_field('mojlig_besparing', $total, 'user_'. $curauth->ID);
    echo '<h3>Fält1: '.$field1.'</h3>';
    echo '<h3>Fält2: '.$field2.'</h3>';
    echo '<h3>Fält3: '.$field3.'</h3>';
    echo '<h2>Totalt:' .$total.'</h2>';

    Please keep in mind that the value will be saved when you open the page. If you want to save it when along with the other fields, kindly use the acf/save_post hook instead.

    I hope this helps 🙂