1
votes

I want to restrict woo commerce products, shop page and category pages to logged in user only.

I do not want to achieve it with any plugin.

Please let me know if anybody done it before with any hook/filter/action.

Or I have to make woo commerce template pages and add condition over there.

Regards,

1
There isn't anything inherently wrong with plugins. If you want to learn how to do it, that is one thing. Though you should probably be writing the resulting code in a plugin of your own and not in your theme since it is custom functionality and themes should be appearance-only so you never lock yourself into 1 particular theme.helgatheviking

1 Answers

1
votes

If I was to do this I would hook into the init action that WordPress offers.

Then do something like this in your theme's functions.php file:

function woo_check_logged_in()
{
    if ( (is_product() || is_shop() ) && is_user_logged_in() )
    {

    }
    else
    {
       die("You must be logged in to view this page");
    }
}
add_action('init', 'woo_check_logged_in');

I haven't tested this but I believe it should get you on the right path without having to use any plugins.