Skip to content
Advertisement

How to restrict a menu item and its content to logged users in WooCommerce

On WordPress, I’m setting up my online shop with WooCommerce plugin. I have a PHP script that generate a pricing table.

But actually everyone can see it.

How can I add it to my WordPress menu and no one could see it without being login in?

Advertisement

Answer

In your script you will add is_user_logged_in() in an IF statement like:

JavaScript

Now in your WordPress menu, you can add additional CSS classes enabling “css Classes” in the “Screen options” tab located up right of the “Menus” settings page.

enter image description here

Then once enabled, in your menu item you will be able to set a custom CSS class:

enter image description here

Then you will be able to hide from unlogged users this menu item using (here the additional class is hide_if_non_logged):

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.


You can even add redirection when user is not logged in for the page where the content that you want to hide from non logged users (You will need to set the correct page slug or ID in the code):

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement