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


#1

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


#2

Hello Manhua,

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

Do you want to revert your changes?

Kind Regards, Roman.


#3

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


#4

Hello Manhua,

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

Kind Regards, Roman.


#5

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


#6

@ersel95

I have sent you a message