Permalink
Showing with 6 additions and 7 deletions.
  1. +6 −7 woocommerce-functions.php
View
13 woocommerce-functions.php
@@ -802,14 +802,14 @@ function woocommerce_process_registration() {
wp_set_auth_cookie($user_id, true, $secure_cookie);
// Redirect
- if ( wp_get_referer() ) {
- wp_safe_redirect( wp_get_referer() );
- exit;
+ if ( wp_get_referer() ) {
+ $redirect = esc_url( wp_get_referer() );
} else {
- wp_redirect(get_permalink(woocommerce_get_page_id('myaccount')));
- exit;
+ $redirect = esc_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) );
}
+ wp_redirect( apply_filters( 'woocommerce_registration_redirect', $redirect ) );
+ exit;
}
}
@@ -1725,8 +1725,7 @@ function woocommerce_save_address() {
* @param string $file_url
* @return string
*/
-
function woocommerce_get_filename_from_url( $file_url ) {
$parts = parse_url( $file_url );
return basename( $parts['path'] );
-}
+}

7 comments on commit 014e319

@alexey13

Thank you very much! How i can set now redirect after registration? I have upgrade woocommerce to last one.

@scotcrop

I had been wrestling with doing this some and finally got it working after a few approaches. Redirecting on login only seems to be as simple as adding this to form-login.php

<input type="hidden" name="redirect" value="/set-redirect-url">

to the login form inputs. On the registration form inputs, this doesn't work at all. Which is odd but I guess it's just ignored, haven't bothered digging through the code that handles the registration yet.

Now, with the above filter, my solution involved doing something like this in form-login.php on the registration form inputs. I check for something and then add this input if its true. I only want to redirect to a particular page if the user is doing something unique to my site

<input type="hidden" name="my_redirect_var" value="/set-redirect-url">

Then just add this in functions.php

add_filter ( 'woocommerce_registration_redirect', 'my_registration_redirect');
function my_registration_redirect( $redirect ) {

    if ( $_POST['my_redirect_var'] ) {
        $redirect = $_POST['my_redirect_var'];
    }

    return $redirect;
}

If my check in form-login.php is true, it adds the hidden input, which is found in my filter and the $redirect is changed.

@Chabin

Hi sorry to bother you and re-up this post but I need some helps on how to do what you have done :O where to put those lines ? can you tell me step by steps what you've done ? thanks anyway .. :)

@tm-tm

Awesome!! This is just what I was looking for!

@mkdizajn

Hey guys,, just looking at login and register forms on my site and found out there is hidden field _wp_http_referer that holds curent url..

I added this to my plugin (or just to functions.php file of your theme) and it works for both login and registration :)

add_filter( 'woocommerce_login_redirect', 'krex_redirect');
add_filter( 'woocommerce_registration_redirect', 'krex_redirect'); 

function krex_redirect( $redirect_to ) {

    if ( ! empty( $_REQUEST['_wp_http_referer'] ) ){
        $ref = wp_unslash( $_REQUEST['_wp_http_referer'] );
    }
    return $ref;
}

cheers, k

@parvanova
parvanova commented on 014e319 Jun 8, 2016 edited

Hello,

Can someone please help me with this filter! I just can't make it work...
Here is my code

// After registration, redirect to home page
function custom_registration_redirect() {
    return home_url('/');
}
add_filter('woocommerce_registration_redirect', 'custom_registration_redirect', 20);

The site keeps redirecting me to the /my-account or to the page with registration form if it is different

Thank you!

@mikejolley
WooThemes member

Support qu's go on the forum please https://wordpress.org/support/plugin/woocommerce

Please sign in to comment.