0

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>

1 Answer 1

2

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.

4
  • 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, 2017 at 22:58
  • Thanks. Unfortunatley, that did not work. It returned MY ACCOUNT | LOGOUT} else{ echo LOGIN | REGISTER Feb 13, 2017 at 17:00
  • Make sure you are not logged in
    – David Lee
    Feb 13, 2017 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, 2017 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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