I am using the following code to redirect the user to the page they came from after successful login. This code has been tested and works fine:
add_action( 'woocommerce_login_form_end', 'actual_referrer' ); function actual_referrer() { if ( ! wc_get_raw_referer() ) return; echo ''; }
Now, when the user enters my-account from the registration page to register, after the registration is successful, I want to return to his original page, such as the code above.
For this, I found a code that redirects the user to the home page after successful registration:
add_filter( 'woocommerce_registration_redirect', 'customer_register_redirect' ); function customer_register_redirect( $redirect_url ) { $redirect_url = get_home_url(); return $redirect_url; }
Is there a way to edit this code like the login code to redirect the user to the page they came from?
You can use
wp_registration_url( urlencode( get_permalink() ) );
, and you will be redirected to the previous page after successful registration.In your case, since it is woocommerce, the link to your page should be:
Where wp_registration_url is the URL of the registration page, and add the ?redirect_to parameter (including the current page).
Depending on your situation, you can change the code in the filter to:
If redirect_to is not set, we will redirect to the home page or another page you like.