I am trying to redirect user after Woocommerce registration. I have tried everything and it is not working.
I have tried some methods found on internet but they didn't work…
When I change 'myaccount' to another permalink it just freezes when you click register.. not sure why.
wp_safe_redirect( apply_filters( 'woocommerce_registration_redirect', wp_get_referer() ? wp_get_referer() : wc_get_page_permalink( 'welcome' ) )
I even tried with the page id
wp_safe_redirect( apply_filters( 'woocommerce_registration_redirect', wp_get_referer() ? wp_get_referer() : wc_get_page_permalink( '1072' ) )
Any help?
Important update (working on last version 3.2.x)
First the
woocommerce_registration_redirect
is a filter hook, but NOT an action hook.A filter hook has always at least one argument and always require to return something. It can be the main function argument (the first one) or some custom value.
The correct tested and functional code is:
add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 );
function custom_redirection_after_registration( $redirection_url ){
// Change the redirection Url
$redirection_url = get_home_url(); // Home page
return $redirection_url; // Always return something
}
Code goes in function.php file of your active child theme (or theme)...
Some common redirections urls used in woocommerce:
$redirection_url = get_home_url();
$redirection_url = get_permalink( wc_get_page_id( 'shop' ) );
$redirection_url = wc_get_cart_url();
$redirection_url = wc_get_checkout_url();
$redirection_url = get_permalink( wc_get_page_id( 'myaccount' ) );
$redirection_url = get_permalink( $post_id );
$post_id
is the id of the post or the page)
$redirection_url = home_url('/product/ninja/');
The accepted answer didn’t work for me. What worked for me was this:
// After registration, logout the user and redirect to home page
function custom_registration_redirect() {
wp_logout();
return home_url('/');
}
add_action('woocommerce_registration_redirect', 'custom_registration_redirect', 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With