Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #555594

    Hello,
    single post login (you must be logged in to post a comment) redirects to /wp-login.php. I would like it to redirect to /myaccount page, where registration form is. Thanks

    #555652

    Hi demarko19!

    Please try a plugin like
    https://wordpress.org/plugins/theme-my-login/

    and let us know if that is what you was in need

    Cheers!
    Basilis

    #556091

    Thanks for reply, Basilis. Plugin creates second registration, form. Plus it redirects hidden wp-admin login to simple login. And since copy/paste isn’t allowed on my website, it would be a hell to write 20+ letter long pwd every time :)

    A bit of google and editing gave me a few codes to child functions.php.
    This one resolved redirection to myaccount page:

    add_filter( 'comment_form_defaults', 'my_custom_phrase' );
    function my_custom_phrase( $array ){
     $array['must_log_in'] = sprintf( __( '<p class="must-log-in">Please <a href="%s">Log In</a> to post a comment.</p>' ), get_permalink( wc_get_page_id( 'myaccount' ) ) );
     return $array;
    }

    Since woocommerce by default, after login redirects to my account and not previous visited page, I thought this might help:

    // Custom redirect for users after logging in
    add_filter('woocommerce_login_redirect', 'wcs_login_redirect');
    function wcs_login_redirect( $redirect ) {
         //Redirect to the previous visited page or, if not available, to the home
    	 $redirect = wp_get_referer() ? wp_get_referer() : home_url();
         return $redirect;
    }

    But it redirects to home page. And if I delete ? wp_get_referer() : home_url(). It redirects to empty page.
    Your team is great with codes, maybe you can help me with this :)

    #556181

    Hi!

    Try the following code, to redirect to previous page after login:

    if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
            add_filter('login_redirect', 'my_login_redirect', 10, 3);
            function my_login_redirect() {
                    $location = $_SERVER['HTTP_REFERER'];
                    wp_safe_redirect($location);
                    exit();
            }
    }

    Best regards,
    Basilis

    #556213

    Hi. It redirects to myaccount page same as woo default.

    #557601

    Hey!

    I’d suggest posting your question in the WP Forums as it’s more related to a WordPress-specific functionality:
    https://wordpress.org/support/

    Regards,
    Josue

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.