I am creating a wordpress site for a client that wants to redirect certain products to login page. I have already had success redirecting entire shop page, etc.. but, I need to redirect only certain products....
This is what I have tried, but it redirects EVERY product to login page:
if( !is_user_logged_in() && $product_id = 7854 ) {
wp_redirect('my-site-url');
}
I have also tried :
if( !is_user_logged_in() && is_product(7854)) {
wp_redirect('my-site-url');
exit;
}
and again, it redirects ALL products to login page.
Am I missing something here? Thoughts would be greatly appreciated.