Home Forums ACF PRO Sum of a post field and a user field


Sum of a post field and a user field

  • I am using the following code to sum up two fields
    1. custom field of a CPT (base fee)
    2. custom user field (addon fee, hence some users have to see a higher number than others, usually that vaulue will be 0 except for some users)

    Is my code ok (particularly the “$extra_fees += $default_fees;” part for that or would it need adjusting, that I am not seeing right now 😉

    $default_fees = get_field('acf_jobs_basefee');
    $user_id = get_current_user_id();
    $extra_fees = get_field('acf_jobs_extrafee', 'user_'.$user_id);
    $extra_fees += $default_fees;
    <span>Fees: </span><?php echo $extra_fees; ?>%
  • Code looks good to me. Are you having a problem? There could be an issue with users that do not have a value set because that might return NULL and I don’t know what the result would be for adding something to NULL or false.

  • No problems so far, was just wondering if there might be something wrong with it 😉

    If users have no value it just outputs the default fees, so that works as well.

    Thanks for looking into this 😉

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.