Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter rhysparry88

    (@rhysparry88)

    Hi there

    Thank you for your reply.

    What you have suggested is great but unfortunately my client doesn’t have the budget to pay outright for this license I was hoping I could somehow reference the cff field and store in an acf field if this is possible.

    Thanks again

    Thread Starter rhysparry88

    (@rhysparry88)

    Hi Nick

    Thank you for this video and info much appreciated.

    The thing is I don’t want to use or create a post I want to basically be able to store the ACF fields and values in the user profile and then display these on the frontend.

    I have even gone and created the ACF fields myself using the below code:

    add_action( 'show_user_profile', 'extra_user_profile_fields' );
    add_action( 'edit_user_profile', 'extra_user_profile_fields' );
    
    function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Macro Profile Information", "blank"); ?></h3>
    
    <table class="form-table">
    <tr>
    <th><label for="current_carbs"><?php _e("Current Carbs Allowence"); ?></label></th>
    <td>
    <input type="text" name="current_carbs" id="current_carbs" value="<?php echo esc_attr( get_the_author_meta( 'current_carbs', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the members Carb allowance"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="current_fats"><?php _e("Current Fats Allowence"); ?></label></th>
    <td>
    <input type="text" name="current_fats" id="current_fats" value="<?php echo esc_attr( get_the_author_meta( 'current_fats', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the members Fat allowance"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="current_protein"><?php _e("Current_Protein"); ?></label></th>
    <td>
    <input type="text" name="current_protein" id="current_protein" value="<?php echo esc_attr( get_the_author_meta( 'current_protein', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the members Protein allowance"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="current_kcal"><?php _e("Current_Kcal"); ?></label></th>
    <td>
    <input type="text" name="current_kcal" id="current_kcal" value="<?php echo esc_attr( get_the_author_meta( 'current_kcal', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the members Kcal allowance"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="recipe_chosen"><?php _e("Recipe_Meal"); ?></label></th>
    <td>
    <input type="text" name="recipe_chosen" id="recipe_chosen" value="<?php echo esc_attr( get_the_author_meta( 'recipe_chosen', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the carbs from the recipe"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="recipe_carbs"><?php _e("Recipe_Carbs"); ?></label></th>
    <td>
    <input type="text" name="recipe_carbs" id="recipe_carbs" value="<?php echo esc_attr( get_the_author_meta( 'recipe_carbs', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the carbs from the recipe"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="recipe_fats"><?php _e("Recipe_Fats"); ?></label></th>
    <td>
    <input type="text" name="recipe_fats" id="recipe_fats" value="<?php echo esc_attr( get_the_author_meta( 'recipe_fats', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the fats from the recipe"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="recipe_protein"><?php _e("Recipe_Protein"); ?></label></th>
    <td>
    <input type="text" name="recipe_protein" id="recipe_protein" value="<?php echo esc_attr( get_the_author_meta( 'recipe_protein', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the protein from the recipe"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="recipe_kcal"><?php _e("Recipe_Kcal"); ?></label></th>
    <td>
    <input type="text" name="recipe_kcal" id="recipe_kcal" value="<?php echo esc_attr( get_the_author_meta( 'recipe_kcal', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter the kcal from the recipe"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label>DO NOT TOUCH THESE FIELDS AS THEY ARE AUTOMATICALLY CALCUALTED</label>
    </tr>		
    <tr>
    <th><label for="live_carbs"><?php _e("Live Carbs value"); ?></label></th>
    <td>
    <input type="text" name="live_carbs" id="live_carbs" value="<?php echo esc_attr( get_the_author_meta( 'live_carbs', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Total Carbs Left"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="live_fats"><?php _e("Live Fats value"); ?></label></th>
    <td>
    <input type="text" name="live_fats" id="live_fats" value="<?php echo esc_attr( get_the_author_meta( 'live_fats', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Total Fats Left"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="live_protein"><?php _e("Live Protein value"); ?></label></th>
    <td>
    <input type="text" name="live_protein" id="live_protein" value="<?php echo esc_attr( get_the_author_meta( 'live_protein', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Total Protein Left"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="live_kcal"><?php _e("Live Kcal value"); ?></label></th>
    <td>
    <input type="text" name="live_kcal" id="live_kcal" value="<?php echo esc_attr( get_the_author_meta( 'live_kcal', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Total Kcal Left"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="data_5"><?php _e("Ignore"); ?></label></th>
    <td>
    <input type="text" name="data_5" id="data_5" value="<?php echo esc_attr( get_the_author_meta( 'data_5', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Ignore"); ?></span>
    </td>
    </tr>
    	<tr>
    <th><label for="data_6"><?php _e("Ignore"); ?></label></th>
    <td>
    <input type="text" name="data_6" id="data_6" value="<?php echo esc_attr( get_the_author_meta( 'data_6', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Ignore"); ?></span>
    </td>
    </tr>
    	<tr>
    <th><label for="data_7"><?php _e("Ignore"); ?></label></th>
    <td>
    <input type="text" name="data_7" id="data_7" value="<?php echo esc_attr( get_the_author_meta( 'data_7', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Ignore"); ?></span>
    </td>
    </tr>
    	<tr>
    <th><label for="data_8"><?php _e("Ignore"); ?></label></th>
    <td>
    <input type="text" name="data_8" id="data_8" value="<?php echo esc_attr( get_the_author_meta( 'data_8', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Ignore"); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="updated_carbs"><?php _e("Latest Carbs Value"); ?></label></th>
    <td>
    <input type="text" name="updated_carbs" id="updated_carbs" value="<?php echo esc_attr( get_the_author_meta( 'updated_carbs', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Latest Carbs Value"); ?></span>
    </td>
    </tr>
    	<tr>
    <th><label for="updated_carbs"><?php _e("Latest Fats Value"); ?></label></th>
    <td>
    <input type="text" name="updated_fats" id="updated_fats" value="<?php echo esc_attr( get_the_author_meta( 'updated_fats', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Latest Fats Value"); ?></span>
    </td>
    </tr>
    	<tr>
    <th><label for="updated_protein"><?php _e("Latest Protein Value"); ?></label></th>
    <td>
    <input type="text" name="updated_protein" id="updated_protein" value="<?php echo esc_attr( get_the_author_meta( 'updated_protein', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Latest Protein Value"); ?></span>
    </td>
    </tr>
    	<tr>
    <th><label for="updated_kcal"><?php _e("Latest Kcal Value"); ?></label></th>
    <td>
    <input type="text" name="updated_kcal" id="updated_kcal" value="<?php echo esc_attr( get_the_author_meta( 'updated_kcal', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Latest Kcal Value"); ?></span>
    </td>
    </tr>
    </table>
    <?php }
    
    add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
    //add_action('edit_user_profile_update', 'update_extra_profile_fields');
    
    function save_extra_user_profile_fields( $user_id ) {
    
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    
    update_user_meta( $user_id, 'current_carbs', $_POST['current_carbs'] );
    update_user_meta( $user_id, 'current_fats', $_POST['current_fats'] );
    update_user_meta( $user_id, 'current_protein', $_POST['current_protein'] );
    update_user_meta( $user_id, 'current_kcal', $_POST['current_kcal'] );
    update_user_meta( $user_id, 'recipe_chosen', $_POST['recipe_chosen'] );
    update_user_meta( $user_id, 'recipe_carbs', $_POST['recipe_carbs'] );
    update_user_meta( $user_id, 'recipe_fats', $_POST['recipe_fats'] );
    update_user_meta( $user_id, 'recipe_protein', $_POST['recipe_protein'] );
    update_user_meta( $user_id, 'recipe_kcal', $_POST['recipe_kcal'] );
    update_user_meta( $user_id, 'live_carbs', $_POST['current_carbs'] - $_POST['recipe_carbs']  );	
    update_user_meta( $user_id, 'live_fats', $_POST['current_fats'] - $_POST['recipe_fats']  );
    update_user_meta( $user_id, 'live_protein', $_POST['current_protein'] - $_POST['recipe_protein']  );
    update_user_meta( $user_id, 'live_kcal', $_POST['current_kcal'] - $_POST['recipe_kcal']  );
    update_user_meta( $user_id, 'data_5', $_POST['live_carbs']  );
    update_user_meta( $user_id, 'data_6', $_POST['live_fats']  );
    update_user_meta( $user_id, 'data_7', $_POST['live_protein']  );
    update_user_meta( $user_id, 'data_8', $_POST['live_kcal']  );
    update_user_meta( $user_id, 'updated_carbs', $_POST['data_5'] - $_POST['recipe_carbs'] );	
    update_user_meta( $user_id, 'updated_fats', $_POST['data_6'] - $_POST['recipe_fats'] );	
    update_user_meta( $user_id, 'updated_protein', $_POST['data_7'] - $_POST['recipe_protein'] );	
    update_user_meta( $user_id, 'updated_kcal', $_POST['data_8'] - $_POST['recipe_kcal'] );	
    }

    The Issue with this now is basically if I use ACF Frontend Forms to display these fields, its stil; not updating the calculations to what I need and displaying zero values unless I go into the backend and update the user profile manually then the calculations all come up.

    Very frustrating but I hope these is a solution ot something to solve this for me.

    Thanks again

    Thread Starter rhysparry88

    (@rhysparry88)

    Hi Nick

    Thanks for the reply back. Right ok so basically your saying if I coded in acf form myself as a snippet short code and used that Instead of this acf frontend forms which is what I am using now it should solve the issue for now?

    Just another quick question have you or anyone here used another calculated field on a free form plugin which allows you to then store these values in acf fields on form submission? I was looking into CF7 or forminator.

    Thanks

    Hi guys

    I had a similar issue to you but now what’s happening is my calculated values aren’t being updated on the front end for example I put in nutrition macros into my acf frontend form and then click update which updates these acf fields and then the calculated fields I have should update with the new values however I have to go to the backend of my site under user profile to then click update user for the new calculated values to show. Any ideas on how this can be done automatically?

    Thanks

    Thread Starter rhysparry88

    (@rhysparry88)

    Hi Jonathan

    Thank you for your message and information much appreciated.

    I guess I want to go down the API route more as basically what I have done is create extra user profile fields for users of my WordPress site which are basically four macros and named the same as what I have on my form.

    What I want to now do is on form submission update these new custom fields as you could say with the data from the four fields in my form to these fields.

    I then basically want to reference these four extra user fields (which have now been updated from the form submission) on four custom fields or input fields on my form.

    The reasoning behind this is so that the user who is logged in can view their current macro data on the form before continuing with the other fields on there.

    I hope this makes sense. Thanks

Viewing 5 replies - 1 through 5 (of 5 total)