WordPress.org

Forums

WooCommerce - excelling eCommerce
[closed] redirect if user is not logged in. (4 posts)

  1. dezahyner
    Member
    Posted 1 year ago #

    I have a woocommerce site that I want to redirect users that are not logged in to the login page, but only for one product.

    I have copied the single-product.php to my theme folder and added the following before "get header"

    if( !is_user_logged_in() && $product_id = 7854 ) {
    	wp_redirect('my-site-url');
    }

    but... this redirects all product links to login page. I only want one of them to redirect. How can I do this without using a plugin. I want to avoid that.

    Any help would be greatly appreciated

    https://wordpress.org/plugins/woocommerce/

  2. dezahyner
    Member
    Posted 1 year ago #

    I also tried......

    if( !is_user_logged_in() && is_product(7854))  {
    	wp_redirect('my-site-url');
    	exit;
    }
    else

    and again.. when you click on any product, it redirects to login, even though, I have specified the product id..

    Thoughts?

  3. photocurio
    Member
    Posted 1 year ago #

    Did you fix this? I'm working on a similar problem.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else's topic.

    I am now closing this 4 month old topic as it references an older version of WordPress.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic