Changing the Login/Register to user account when signed in

Hello, I would like to ask if it’s possible to show the user profile instead of the Login/Register button when certain user is signed in. Thank you.

Hello there,

To accomplish it, firstly you’ll need to add the below function to your theme’s functions.php file or use a functionality plugin like Code Snippets.

    /**
     * Get WC page URL
     */
    add_action( 'wp_enqueue_scripts', 'leto_child_wc_pages', 9999 );
    function leto_child_wc_pages() {

      if( !is_user_logged_in() ) {
        return;
      }

      $wc_pages = array(
        'my_account' => get_permalink( wc_get_page_id( 'myaccount' ) ),
      );

      wp_localize_script( 'leto-main', 'wc_pages', $wc_pages );

    }

Then do the below steps:

  1. Install and activate the TC Custom JavaScript plugin
  2. Go To Appearance > Custom JavaScript
  3. Paste the following code into the provided box
    (function($){

      if( wc_pages.my_account != '' && $('.nav-link-account a').length ) {
        $('.nav-link-account a').attr('href', wc_pages.my_account).text('My Account');
      }

    })(jQuery);
  1. Update
  2. Flush/clear any applied cache

Regards,
Kharis

Hi! If I use the second code, I get an warning that the code is not correct. So, what can I do?

Hello there,

Do you have a link to your site you could share here, so I could have a look?

Regards,
Kharis

Hi, the link is www.auko.nl.

At the moment I ‘solved’ it by redirecting the wp/login link to my-account. But that’s not a real solution? :wink:

Hi Kharis, could you explain what is going wrong on my site? I still would like to change the wp/login tot my-account.

Greets!

Dear Heleen,

I had the same problem, in my case the program did not work on my site. Maybe this screenshots can help you out. Also the name of the programs i use are displayed.

Kind Regards,

Kevin

Hi Kevin,

I can’t seem to find the plugin Simple JS Paste…? Does it have another name?

So step 1, adding the code to Code Snippets works fine, but then…

Hi heleen,

I have the old version, this is the new one: https://wordpress.org/plugins/custom-css-js/
so the what you need to do is delete the old plugin. Download the new plugin and then stap one.
First i did not work by me also. So this is what i did, copy it and put you own link on the place were i put mine. Then step two, go to the simple new js plugin and make a new document in javascript. The put the code Kharis provided into the box. Then it should work… if not, let me know !

Kind Regards,

Kevin

Je stappen gevolg, maar het werkt nog steeds niet…

Code 1 heb ik in code snippets staan, link aangepast.
Code 2 als ccs code in de Custom CSS & JS.

Zoveel vragen en reacties over dit onderwerp, maar toch krijg ik het niet voor elkaar. Frustrerend!

Hello there,

I’d like to help, but, I am sorry I can’t understand what you wrote because I only speak English. Would you mind re-writing it in English?

Regards,
Kharis

@kharisblank

She said, I followed you steps and still it does not work.

code 1 i pasted in snippets and changed the link as i did last time.
code 2 as css code in the costom css&js

so mutch qusetions and reactions but still it does not work.

@heleenn1

can you please take a look if have it in the right box so javascript

Hi Kharis,

So, still no results. I tried different plugins, but nothings helps. De login/register still links to the login page instead of the my-account.

Hope to solve this!

What I’ve tried:

  1. Installing code snippets and adding code 1.
  2. Going to appearance > customizer > extra css > enter code 2

When I enter this code, I get an error.

So, where am I going wrong? Hope to solve this!

Greets,
Heleen

@heleenn1 can you make a screenshot of the error?

Here it is, a screenshot of the error. It says: there are 30 errors that have to be fixed before saving.

@heleenn1 Because you put a javascript code into a css box. That wont work!

Ok, because of all my attempts for making this work, I think I forgot these steps:

  1. Install and activate the TC Custom JavaScript 1 plugin
  2. Go To Appearance > Custom JavaScript
  3. Paste the following code into the provided box

So, works fine now! :grinning:

Only, is it possible to change the text ‘my account’? Then it would be perfect!

that is a bit to much for me so @kharisblank or @roman can you guys help her with that ?

Hello there,

Only, is it possible to change the text ‘my account’? Then it would be perfect!

    (function($){

      if( wc_pages.my_account != '' && $('.nav-link-account a').length ) {
        $('.nav-link-account a').attr('href', wc_pages.my_account).text('My Account');
      }

    })(jQuery);

In the code above, you can change the My Account inside the text() method.

If you want to use your own page link to replace the default yoursite.com/my-account, you can go to WooCommerce > Settings menu. Then in Advanced panel, you can set My account page.

Regards,
Kharis