Support

Account

Home Forums General Issues Custom My Account Page Using ACF User Fields

Helping

Custom My Account Page Using ACF User Fields

  • Hey All!

    I’m building a membership site and am trying to customize the my account page to allow member direct access to cert sections of the site that are “hidden” from the main navigation. I’ve created ACF user fields where I can put in specific Links to sections, but want to create a statement that will display a message other than the link if the field is left blank in the user account.

    I’m no php expert, but took a stab at the code for the if else statement. Unfortunately it’s not working properly and it’s stating there’s a syntax error, but I can’t find it. Here’s what I’ve got:

    <?php $user_ID = get_current_user_id(); $number = 'user_' . $user_ID; 
    	if ( get_field('current_workout_phase', $number) ): ;
    		echo "<p><a href='<?php the_field('current_workout_phase', $number); ?>' >View My Current Workouts </a>	</p>";
        else 
    		echo "Your current membership level doesn't offer custom workout plans.  You can, however <a href='/exercises'> view all of our exercises and their instructions here.</a>";
        endif; 
    	?>

    Any help would be greatly appreciated!

  • Hi @hconsalvi

    You have an extra semicolon and some syntax errors there. Could you please try this code instead?

    <?php $user_ID = get_current_user_id(); $number = 'user_' . $user_ID; 
        if ( get_field('current_workout_phase', $number) ) {
            echo '<p><a href="' . the_field('current_workout_phase', $number) . '" >View My Current Workouts </a>	</p>';
        } else {
            echo "Your current membership level doesn't offer custom workout plans.  You can, however <a href='/exercises'> view all of our exercises and their instructions here.</a>";
        }
    ?>

    To learn more about PHP, please take a look at this page: http://www.w3schools.com/php/.

    Hope this helps!

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

The topic ‘Custom My Account Page Using ACF User Fields’ is closed to new replies.