WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Logout link doesn't work! (22 posts)

  1. pandaj
    Member
    Posted 1 year ago #

    I have the latest WordPress update along with the latest WooCommerce update.

    The following code is in my header file:

    <div id='sales-nav'><?php if ( is_user_logged_in() ) { ?>
     	<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a><a href="<?php echo wp_logout_url( home_url() ) ?>" title="Logout">Logout</a>
     <?php }
     else { ?>
     	<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?></a>
     <?php } ?><div id='cart_container'><a href='/cart'>Cart - <?php global $woocommerce; echo "<div id='cart_total'>" . $woocommerce->cart->get_cart_total() . "</div></a></div>";?> <?php if (sizeof($woocommerce->cart->cart_contents)>0) :?>
    <a href="<?php echo $woocommerce->cart->get_checkout_url()?>" title="<?php _e('Checkout','woothemes') ?>"><?php _e('Checkout','woothemes') ?></a>
    <?php endif; ?></div>

    Everything displays perfectly, however there are a couple of problems.

    Firstly - After clicking logging out, and confirming that you want to log out, the redirect to the home page doesn't work. You are just taken to 'wp-login.php'.
    The first logout URL looks like:
    http://domain.com/wp-login.php?action=logout&_wpnonce=xxxxxxxxxx
    The second logout URL looks like:
    http://domain.com/wp-login.php?loggedout=true

    Now the other problem (and bigger problem) is that if you click the 'Back to SITE_NAME' button or just go to the site again, the user is still logged in! 'My Account' and 'Logout' still show in the header. It seems impossible to logout.

    Any help will be much appreciated!

    Thanks

    http://wordpress.org/extend/plugins/woocommerce/

    [No bumping, thank you.]

  2. mikejolley
    Member
    Plugin Author

    Posted 1 year ago #

    wp_logout_url is a WP function - this looks unrelated to WooCommerce to be honest.

    Are you using SSL on any pages/login? Try turning that off and see if its related.

  3. pandaj
    Member
    Posted 1 year ago #

    I have an SSL certificate and ticked the option to force a secured connection for the cart.

    I posted here because I used a couple of Jay's snippets to display the links.

    EDIT: I've just noticed however, when attempting to go to 'wp-login.php' you do in fact have to log in again.

    The problem seems to lie with Woocommerce as you can still view your account information when viewing 'my-account'?

  4. mikejolley
    Member
    Plugin Author

    Posted 1 year ago #

    My-account is https too. It will be down to whether you login with SSL or not. You could perhaps try enforcing SSL with login? This is in the WP Codex.

  5. pandaj
    Member
    Posted 1 year ago #

    I've tried with ticking and unticking the force secured connection but no difference. I'll try what you suggested, thanks.

    It's just weird how the user is logged out of WordPress itself but can still see the my-account page.

  6. pandaj
    Member
    Posted 1 year ago #

    Nope, still the same. I would post in the normal WordPress support forum, but the user IS actually logged out of WordPress, it's just that they can still see all the info on the 'my-account' page. Really not sure what to do.

  7. pandaj
    Member
    Posted 1 year ago #

    Can't edit, but I will happily pay someone at Woo to help me out?

  8. esmi
    Forum Moderator
    Posted 1 year ago #

  9. pandaj
    Member
    Posted 1 year ago #

    I don't really understand why it's only me this has happened to.

  10. pandaj
    Member
    Posted 1 year ago #

    This is the last thing I need to sort out before I'm happy with how the site works. If it logs out of WordPress okay but I can still see the my-account page, does that not mean it's something to do with the Woo Commerce session? Is there a way this can be killed on logout?

  11. royho
    Member
    Posted 1 year ago #

    I am afraid this is only happening to you it seems...I just did a test and it works fine...

  12. pandaj
    Member
    Posted 1 year ago #

    Yeah I have no idea why! I could try reinstalling Woocommerce but not sure if that will help. I'd love to understand what could be causing this.

  13. royho
    Member
    Posted 1 year ago #

    Its not woocommerce...its probably your plugins or theme...woocommerce uses WP native logout function...

  14. pandaj
    Member
    Posted 1 year ago #

    I just don't know where to look. I've been trying to fix this for over a week now, it's stopping me from sorting everything else out :(

  15. royho
    Member
    Posted 1 year ago #

    Why don't you post your issue on that jobs board to see if anyone can help you.

  16. pandaj
    Member
    Posted 1 year ago #

    Okay have done. Upon further testing it doesn't actually seem to log out of WordPress. So may be completely unrelates to WooCommerce, in which case - I can only apologise!!!

  17. jitenoswal1
    Member
    Posted 1 year ago #

    But were you able to solve this problem .. what is the solution .. ??
    Even my logout is not working and me happen to use WooCommerce .. :/
    Please help ..

  18. pandaj
    Member
    Posted 1 year ago #

    @jitenoswal1 it was so simple, I stupidly set the WordPress Address (URL) and Site Address (URL) to different things. Make them the same under General Settings.

  19. jitenoswal1
    Member
    Posted 1 year ago #

    ohh yea .. sry I got that .. :P thanks anyways .. :)

  20. bexxie
    Member
    Posted 1 year ago #

    This is happening to me as well but only on IE8. I checked my wordpress and site url and they are exactly the same. Does anyone else have another solution?

    Thanks!

  21. jitenoswal1
    Member
    Posted 1 year ago #

    I might have the solution drop me an email on my personal email address with link to your website.

    Jiten

  22. carl_erikl@hotmail.com
    Member
    Posted 1 year ago #

    I found a solution that helped me.

    My solution is changing in wp-login.php, yes i know I should not do that, so I was hoping someone could tell me what to do instead.

    My solution:
    change this in wp-login.php line 406

    case 'logout' :
    	check_admin_referer('logout');
    	wp_logout();
    
    	$redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?loggedout=true';
    	wp_safe_redirect( $redirect_to );
    	exit();
    
    break;

    change
    check_admin_referer('logout');
    to
    check_admin_referer('log-out');

    Reason:
    Woocommerce creates the nonce when page loads.
    calls function wp_logout_url($redirect = '') which creates the logout url.
    in wp-includes/general-template.php

    which creates the logout_url with among other:

    $logout_url = wp_nonce_url( $logout_url, 'log-out' );

    there is the 'log-out', and not as expected 'logout'.

    someone who knows more than me should figure it out.

    kind regards
    carl erik

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic