Last active
August 9, 2019 12:30
-
-
Save BoyetDgte/c2cdc7de13cf8f0a96e3b1abc550c699 to your computer and use it in GitHub Desktop.
Custom WooCommerce login and dashboard button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/