Skip to content

Instantly share code, notes, and snippets.

@BoyetDgte
Last active August 9, 2019 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BoyetDgte/c2cdc7de13cf8f0a96e3b1abc550c699 to your computer and use it in GitHub Desktop.
Save BoyetDgte/c2cdc7de13cf8f0a96e3b1abc550c699 to your computer and use it in GitHub Desktop.
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;
}
@BoyetDgte
Copy link
Author

BoyetDgte 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