Skip to content

Instantly share code, notes, and snippets.

@axxe16
Created May 2, 2020 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axxe16/3c0fd2f896add5e8193f1a6aab43a1c6 to your computer and use it in GitHub Desktop.
Save axxe16/3c0fd2f896add5e8193f1a6aab43a1c6 to your computer and use it in GitHub Desktop.
Woocommerce aggiungere login/logout a menù #woocommerce #woo #menù
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( wc_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment