Woocommerce login and logout menu options

Important - Please BACKUP your wordpress files and databases before editing header.php
Try placing this code in your 'header.php'
Change "www.yoursite.com" to your website name



<!-- start of by me -->
<?php
add_action
( 'loop_start', 'personal_message_when_logged_in' );

function personal_message_when_logged_in() {

if ( is_user_logged_in() ) {
$current_user
= wp_get_current_user();
echo $current_user
->user_login;
} else {
$items
.= '<a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Register</a>';
echo $items
;
}

}

add_action
( 'loop_start', 'login_logout_status' );

function login_logout_status() {
if ( is_user_logged_in() ) {
$login_status
.= '<a href="http://www.yoursite.com/my-

account/customer-logout/">Log out</a>'
;
echo $login_status
;
} else {
$items
.= '<a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log in</a>';
echo $items
;
}
}
?>

<ul class="headerlinks">
<li><?php personal_message_when_logged_in(); ?></li>
<li><?php login_logout_status(); ?></li>
</ul>

<!-- end of by me -->
Styles
/* start of my style */
ul
.headerlinks {
position
:relative !important;
float: right;
z
-index:500 !important;
background
-color: #e3e3e3;
margin
-bottom: 10px;
}
ul
.headerlinks li {
list
-style: none !important;
display
:inline !important;
margin
:0 5px 0 0 !important;
padding
:0;
}
/* end of my style */

No comments

Powered by Blogger.