WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] WooCommerce Login Redirect (9 posts)

  1. whitneyr
    Member
    Posted 1 year ago #

    FYI: I have done extensive research on this topic.

    I have a members only site running woo commerce.

    1. I would like users to be redirected to the home page (http://mydomain.com) after login and registration. Currently users are directed to their account page.

    The woocommerce site lists the following fix. However, I've had no luck with it.

    /*
     * goes in theme functions.php or a custom plugin
     *
     * By default login goes to my account
     **/
    add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');
    
    function custom_login_redirect( $redirect_to ) {
         $redirect_to = 'http://anypage.com';
    }

    2. Is there a way to moderate Registration. Meaning if a user registers, they are held in a queue until I can approve them.

    Thank you kindly.

  2. Ana Aires
    Member
    Posted 1 year ago #

    Hi,

    not sure about 2, but I can help on issue 1.

    I believe the fix they suggest only works if you are using the login widget on your site. If it's the login form directly you need to do something different.

    This how I did manage to redirect the user after woocommerce logged in.

    You just need to add an <input type="hidden" name="redirect" value="<?php echo get_home_url(); ?>" /> to your login form and set the value attribute with the url you want to redirect to.

    Please make sure you are not editing the form-login.php file directly on woocommerce, if you need you can add a copy of this file on your theme directory (my-theme/woocommerce/myaccount/form-login.php) and do whatever you need to do here.

    Hope this is helpful.

  3. whitneyr
    Member
    Posted 1 year ago #

    Very helpful!
    This worked like a charm!

  4. whitneyr
    Member
    Posted 1 year ago #

    One more thing.
    I tried to do this in the same file for the registration.
    I want to forward to the home page after the customer registers for the first time. Instead it goes to the my acct page.

    Any idea on how to get this to work?

    Thank you!

  5. iwona
    Member
    Posted 1 year ago #

    hi
    Is it important add this code to specific place?
    I did it in my copy of form-login.php (Karma theme) and it doesn`t seem to work for me.

  6. Scott
    Member
    Posted 1 year ago #

  7. RazzET
    Member
    Posted 1 year ago #

    If you want it to work on the normal login form for woocommerce, you should change the filter hook to woocommerce_login_redirect and add a return statement containing the url variable.

    add_filter('woocommerce_login_redirect', 'ras_login_redirect');
    
    function ras_login_redirect( $redirect_to ) {
         $redirect_to = 'http://anypage.com';
         return $redirect_to;
    }

    All of this should of course go in your themes functions file.

  8. i-gen2013
    Member
    Posted 1 year ago #

    Hi, i tried adding at the bottom of templates/form-login.php in many ways the code you gave ( <input type="hidden" name="redirect" value="<?php echo get_home_url(); ?>" /> ) but no result. Could someone please give the exact code for redirection to homepage? My site url is http://i-gen.gr/ if needed.
    I would appreciate any answer from anyone.

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    @i-gen2013: As per the Forum Welcome, please post your own topic.

Topic Closed

This topic has been closed to new replies.

About this Topic