Customer Logged In or Logged out of a Jigoshop store, php snippet

The purpose of this SlickTips php snippet is to show you how to check if a customer is logged in or notĀ and show appropriate buttons based on theirĀ status for a Jigoshop store.

The Idea

– If user is not logged in show the “Log In” button so the user can log into the store.

OTHERWISE

– If user is logged in show “Log Out” and “My Account” buttons in the store menu.

The Script

You can add or overwrite this by going to your themes header.php file and placing this in the store menu area.

wp-content/themes/YOURTHEME/header.php

Overwrite your existing store menu if you are using a Jigoshop store theme OR just place in the header where you would like the store menu to be.

//Only show "Login" button if not logged in otherwise show "My Account" button if user logged in.
<?php if ( is_user_logged_in() ) {
echo '<a href="/my-account/" class="header-my-account-btn">My Account</a>';
} else {
echo '<a class="header-store-sign-in" href="/wp-login.php"> Login</a>';
}

//Always show "Checkout" and "Cart" buttons
echo '/ <a class="header-store-sign-up" href="/checkout/">Checkout</a> / <a class="header-store-checkout" href="/cart/">Cart</a>';

//Only show "Log Out" button If user is logged in show.
if ( is_user_logged_in() ) {
echo '/ <a href="/wp-login.php?loggedout=true" class="header-logout-btn">Log out</a>';
}
?>