Any way to put woocommerce shop page into [protect][/protect]?

Hello! I would like to show woocommerce shop page to logged in users only (without plugins).
I could put [products] short code into protected area and it works fine, but I want the main shop page itself to be in [protect][/protect]?

Is it possible?

(woo had a short code for shop page, but now they don’t use it…)

Thanks

Hi @magneticum,

Do you mean doing this function/feature without using an extra plugin?

If yes, that means custom code only. Shop page is controlled by a template and protect elements will not work on it. Unfortunately, custom code is outside the scope of our support. Your options to achieve is either custom code or using a plugin. I am not sure why you don’t want to use a plugin but I did some research and found this that might help you. It is not an official recommendation and the plugin is not tested with the theme so if you decide using it, any issues encountered should be directed to the plugin developer.

Hope this helps.

Thanks. I found this code, does it seem to be correct to force all users who want to access woocomerce shop page to login?

function woo_login_redirect() {
	if (! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout()) ) {
		wp_redirect( '/my-account/' );
		exit;
	}
}
add_action('template_redirect', 'woo_login_redirect');

Hello @magneticum,

The given code which may have came from this link: https://stackpilot.io/article/force-visitors-login-accessing-woocommerce-shop/, will redirect the users the the my account page.

You may need to use 3rd party plugin to accomplish what you have in mind. Kindly check the WordPress plugin repository:

Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.