Link Login/Register button to My Account page + Change Button to "My Account" once Logged in

Hi Team,

Need help here.
I tried to combine these two and my webpage can’t load after that.


I added this to child theme’s function.php

add_action( ‘wp_enqueue_scripts’, ‘leto_child_wc_pages’, 9999 );
function leto_child_wc_pages() {
$wc_pages = array(
‘my_account’ => get_permalink( wc_get_page_id( ‘myaccount’ ) ),
);
wp_localize_script( ‘leto-main’, ‘wc_pages’, $wc_pages );
}
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 );
}

And this using Custom Javascript plugin

(function($){

  if( $('.nav-link-account a').length ) {
    $('.nav-link-account a').attr('href', wc_pages.my_account);
  }

})(jQuery);

(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);

I have no php/javascript knowledge at all so appreciate if you can point out my mistake.Thank you!

Regards
Manhua

Hello Manhua,

I’m not sure what exactly you want to achieve.

Do you want to revert your changes?

Kind Regards, Roman.

Hi Roman,

I would like to link “Login/Register” button to My Account instead of wp-admin.
Also, I would like to change to button name to “My account” or “Log out” after customer logged in.

I combined the codes from the 2 previous topics and my webpage couldn’t load…

Regards
Manhua

1 Like

Hello Manhua,

You can check this extensive guide, it might help:
https://barn2.co.uk/woocommerce-login-plugins/

Kind Regards, Roman.

1 Like

Hey manhua,
Im working on the same issue as you did. can you help me how you solved this?

@ersel95

I have sent you a message