WordPress shortcode/cart count/ current page URL/check user login
Below function has WordPress shortcode/cart count/ current page URL/checking user is logged-in or logged-out
cartlogin function will return the cart and different message for logged-in and logged-out user.
function cartlogin_func( $atts ) {
global $current_user;
get_currentuserinfo();
$div .= ‘<a href=”/cart/” target=”_self” rel=”noopener noreferrer” aria-label=”link to /wishlist/”><i class=”fas fa-cart-plus” aria-hidden=”true”><b>’.WC()->cart->get_cart_contents_count() .'</b></i></a>’;
if ($current_user->ID == ”) {
global $wp;
$rd = home_url( add_query_arg( array(), $wp->request ) );
$div .= ‘<a class=”loginre” title=”Quick Login/Register” href=”#”>Login/Register</a></pre>
<div class=”sociallogin nsl-container nsl-container-block” data-align=”left”>
<div class=”nsl-container-buttons”><a href=”/wp-login.php?loginSocial=facebook&redirect=’.$rd.’” rel=”nofollow” aria-label=”Continue with <b>Facebook</b>” data-plugin=”nsl” data-action=”connect” data-provider=”facebook” data-popupwidth=”475″ data-popupheight=”175″><span class=”nsl-button nsl-button-default nsl-button-facebook”><span class=”nsl-button-label-container”>Continue with <b>Facebook</b></span></span></a><a href=”/wp-login.php?loginSocial=google&redirect=’.$rd.’” rel=”nofollow” aria-label=”Continue with <b>Google</b>” data-plugin=”nsl” data-action=”connect” data-provider=”google” data-popupwidth=”600″ data-popupheight=”600″><span class=”nsl-button nsl-button-default nsl-button-google” data-skin=”uniform”><span class=”nsl-button-label-container”>Continue with <b>Google</b></span></span></a><a href=”/wp-login.php?loginSocial=twitter&redirect=’.$rd.’” rel=”nofollow” aria-label=”Continue with <b>Twitter</b>” data-plugin=”nsl” data-action=”connect” data-provider=”twitter” data-popupwidth=”600″ data-popupheight=”600″><span class=”nsl-button nsl-button-default nsl-button-twitter” style=”background-color: #4ab3f4;”><span class=”nsl-button-label-container”>Continue with <b>Twitter</b></span></span></a></div>
</div>’;
}else{
$div .= ‘<span style=”float: right;”>Welcome <a href=”https://hotandcoldoutlet.com.au/my-account/”>’.$current_user->user_firstname.'</a> </span>’;
}
return $div;
}
add_shortcode( ‘cartlogin’, ‘cartlogin_func’ );