Logout code snippet (3 posts)

  1. bexxie
    Posted 3 years ago #


    I'm trying to add a logout link when the user is logged into the site. I'm currently using this code on my functions.php page:

    <ul class="quick-cart">
    		<li><span class="quick-cart-copy">Your Cart Has:</span><?php global $woocommerce; ?>
    		<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
    		<li><?php if (sizeof($woocommerce->cart->cart_contents)>0) :?>
    		<a href="<?php echo $woocommerce->cart->get_checkout_url()?>" title="<?php _e('Checkout','woothemes') ?>" class="checkout button">  <?php _e('Checkout','woothemes') ?></a>
    		<?php endif; ?> </li>
    		<li>  <?php if ( is_user_logged_in() ) { ?>
    		<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>" class="my-account button">   <?php _e('My Account','woothemes'); ?></a>
    		<?php }
    		else { ?>
    		<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>" class="login button"><?php _e('Login / Register','woothemes'); ?></a>
    		<?php } ?></li>

    But there doesn't appear to be anything that allows the user to logout. Any help is much appreciated. Thanks!


  2. bexxie
    Posted 3 years ago #

    Ok, I figured it out. I just needed to add this snippet:

    <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>

    However, I'm getting a different issue where I can't logout on IE8. Every other browser works fine, but on IE8, I have to click logout a couple of times and then it goes to a page that says "Are you sure you want to logout" and then redirects to a WordPress login page. Obviously, I don't want customers going to that page. I've googled this issue and can't seem to figure it out. Any help is greatly appreciated!

  3. bexxie
    Posted 3 years ago #

    I forgot to mention that this only happens when I'm logged in as a "customer." It works fine if I'm logged in as an administrator. I'm using the latest version of WordPress and Woocommerce.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic