How to add login/logout links to menu in Woocommerce
First of all you need to add a menu and make it primary menu of the site.
After creating menu, add the following lines of code at the end of your theme’s functions.php file.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == 'primary') { $items .= '<li><a href="'. wp_logout_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>'; } elseif (!is_user_logged_in() && $args->theme_location == 'primary') { $items .= '<li><a href="' . get_permalink( woocommerce_get_page_id( 'myaccount' ) ) . '">Log In</a></li>'; } return $items; }
Add the above code in functions.php file of your theme.
Now if you go to front end and refresh the page you’ll see the login link being added to the menu.
After logging in you’ll see the logout link.
And that is all we need.