Bhavesh
Bhavesh

Reputation: 365

Only logged in users should be able to view product in WooCommerce

I want to restrict WooCommerce products, shop page and category pages to logged in users 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 WooCommerce template pages and add condition over there.

Upvotes: 2

Views: 4872

Answers (1)

BIOSTALL
BIOSTALL

Reputation: 1696

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.

Upvotes: 1

Related Questions