I am simply trying to add conditional Woocommerce login links to a widget area. I need help identifying my code issues. I would like it to Welcome the user in the initial conditional statement but didn't get that far.

<div class="account_links">
    <?php if ( is_user_logged_in() ) {
        echo <a href="/my-account/" title="My Account Page">MY ACCOUNT</a>
        <span> | </span>
        <a href="/my-account/customer-logout/">LOGOUT</a>} 
    else {
       echo <a href="/my-account/" title="Login Page">LOGIN</a>
        <span> | </span>
        <a href="/my-account" title="Create an Account">REGISTER</a>
    <?php endif; ?>
</div>

You are missing quotation marks, closing tags, almost everything:

<div class="account_links">
    <?php if ( is_user_logged_in() ) {
        echo '<a href="/my-account/" title="My Account Page">MY ACCOUNT</a>
        <span> | </span>
        <a href="/my-account/customer-logout/">LOGOUT</a>'; 
    } else {
       echo '<a href="/my-account/" title="Login Page">LOGIN</a>
        <span> | </span>
        <a href="/my-account" title="Create an Account">REGISTER</a>';
     } ?>
</div>

that should do it.

  • The OP also should understand that those pages and endpoints can be changed by the client, so hard coding is not a good idea. – Christina Feb 9 '17 at 22:58
  • Thanks. Unfortunatley, that did not work. It returned MY ACCOUNT | LOGOUT} else{ echo LOGIN | REGISTER – Erik Truchan Feb 13 '17 at 17:00
  • Make sure you are not logged in – David Lee Feb 13 '17 at 17:05
  • can you edit your question with the code of where you are putting this? i think you are missing quotation marks are you using an IDE? – David Lee Feb 13 '17 at 17:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.