Home > other >  I have different woocommerece registration forms on website for one of them I want users to get redi
I have different woocommerece registration forms on website for one of them I want users to get redi

Time:10-24

I am trying to redirect users from one page to my account page of woocommerce while not effecting after registration behavior of other pages, I am trying to use this code snippet in functions.php of my child theme but it does not seems to work.

add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 );
function custom_redirection_after_registration( $reg_url, $user ){
if( str_contains( $reg_url, 'login-or-register' ) ) {
    $reg_url = get_permalink( wc_get_page_id( 'myaccount' ) );
}

return $reg_url;
}

I will be glad get any help.

Thanks in advance.

CodePudding user response:

You have access to $_SERVER variable. you can check the request referral link and set your conditions.

I hope this helps,

add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 );
    function custom_redirection_after_registration( $reg_url ) {
        if ( str_contains( $_SERVER['REQUEST_URI'], 'login-or-register' ) ) {
            $reg_url = get_permalink( wc_get_page_id( 'myaccount' ) );
        }
        
        return $reg_url;
    }
  • Related