0

I am trying to redirect logged in user but not with a membership, from a specific page to product page. But it is showing error if I land on that page. Let's say join is the page with id 1867. Here is my code:

function redirect_member_to_product(){
    if (is_page(1867)){
        if (is_user_logged_in() && !wc_memberships_is_user_active_member('channel-mcgilchrist')){
            template_redirect('/product/channel-mcgilchrist');
            exit;
        }
    }
}
add_action('template_redirect', 'redirect_member_to_product');

What I am doing wrong here?

  • So I moved my previous comment to an answer and also, I rolled back your edit because you shouldn't edit your code like that because it invalidated the original question. :) – Sally CJ Jul 13 at 12:10
0

Your code is fine to me, except you made a mistake here:

template_redirect('/product/channel-mcgilchrist');

WordPress does not have a function named template_redirect, only a hook with that name.

So you should have used either wp_redirect() or wp_safe_redirect() which are valid functions to perform URL/page redirections in WordPress.

wp_safe_redirect( '/product/channel-mcgilchrist' );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.