Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active December 16, 2024 16:27
Show Gist options
  • Select an option

  • Save neilgee/075a1e75cb5b5186748f to your computer and use it in GitHub Desktop.

Select an option

Save neilgee/075a1e75cb5b5186748f to your computer and use it in GitHub Desktop.
Add WooCommerce MyAccount Login/Logout Menu Items to Registered Menu
<?php //<~ don't add me in
add_filter( 'wp_nav_menu_items', 'my_account_loginout_link', 10, 2 );
/**
* Add WooCommerce My Account Login/Logout to Registered Menu
*
* @link https://support.woothemes.com/hc/en-us/articles/203106357-Add-Login-Logout-Links-To-The-Custom-Primary-Menu-Area
*/
function my_account_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') { //change your theme registered menu name to suit
$items .= '<li><a href="'. wp_logout_url( get_permalink( wc_get_page_id( 'shop' ) ) ) .'">Log Out</a></li>'; //change logout link, here it goes to 'shop', you may want to put it to 'myaccount'
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {//change your theme registered menu name to suit
$items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
}
return $items;
}
@aftoledo
Copy link
Copy Markdown

It works very well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment