Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom WooCommerce login and dashboard button
add_filter( 'wp_nav_menu_items', 'custom_login_dashboard', 10, 2 );
function custom_login_dashboard( $items, $args ) {
if (is_user_logged_in() && $args->primary-menu == 'primary') { //change your theme registered menu name to suit - currently for DIVI theme
$items .= '<li><a class="mydashboard" href="'. get_permalink( wc_get_page_id( 'myaccount' ) ) .'">My Dashboard</a></li>' . '<style> #top-header { background: #7a0101!important;} #main-header, #main-footer, #footer-bottom { background: black!important;}</style>';
//the style is changing the theme's color once you are logged in
}
elseif (!is_user_logged_in() && $args->primary-menu == 'primary') {//change your theme registered menu name to suit
$items .= '<li><a class="mydashboard" href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
}
return $items;
}
@ErnestPH

This comment has been minimized.

Copy link
Owner Author

@ErnestPH ErnestPH commented May 23, 2019

Once the condition is added. You can now add CSS properties to the class to hide the navigation from other nav menu such as footer and secondary. To prevent duplication. Here's the complete guide, https://www.radiocastvps.com/blog/add-a-custom-woocommerce-login-button-the-way-you-wanted/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.