Blog

How to create a WooCommerce shop only for registered users?

create a WooCommerce shop only for registered users
Table of Contents

Have you ever wanted to hide some products or categories from your WooCommerce shop page? Or did you need to restrict access to certain products on your website? 

To create a private store for WooCommerce, you can use one of the following methods:

  1. Create WooCommerce members-only shop programmatically.
  2. WooCommerce product table plugin.

In this post, we will explain both methods to show you how to create a WooCommerce shop only for registered users.

Why do you need to create a WooCommerce members-only shop?

Creating a private WooCommerce store is useful for online shops that want to show a series of products or tags to specific users or only to registered users.

Many reputable stores need to hide products from visitors and make them available to their special users. So, visitors must buy a subscription to access some special content. 

It is also important for some store managers to show some products or categories to specific user roles.

If you also want to limit customers’ access to your WooCommerce products, continue reading to learn two practical methods for creating a WooCommerce shop only for registered users.

Creating a private store WooCommerce programmatically

The idea of writing this PHP snippet for creating a WooCommerce shop only for registered users is very simple. By running this code, when non-logged-in users visit your website, they will be redirected to the login page.

Before using this code, remember to know about code writing and working with function.php in WordPress. Otherwise, we recommend you ask an expert to do this. Although you can run this PHP snippet on the function.php file of your theme, it makes sense if you create a child theme and then use this code to create a WooCommerce private shop. It is also important to back up your site before running the code.

function my_redirect_non_logged_in_users() {
  if ( !is_user_logged_in() && ( is_WooCommerce () || is_cart() || is_checkout() ) ) {
    wp_redirect( get_permalink( get_option('WooCommerce _myaccount_page_id') ) );
    exit;
  }
}
add_action( 'template_redirect', 'my_redirect_non_logged_in_users' );
function my_redirect_non_logged_in_users() {
  if ( !is_user_logged_in() && ( is_WooCommerce () || is_cart() || is_checkout() ) ) {
    wp_redirect( get_permalink( get_option('WooCommerce _myaccount_page_id') ) );
    exit;
  }
}
add_action( 'template_redirect', 'my_redirect_non_logged_in_users' );

The function guides

To make WooCommerce members-only shop with this function, we hooked it to the template_redirect action. So, it is fired just before WordPress begins rendering the template file. Therefore, visitors who are not logged in will be redirected to the login page before observing any content on WooCommerce pages.

We also used the below function in the code:

  •  is_user_logged_in(): To check whether the users are registered. If not, the below functions work:
    • is_WooCommerce (): To check if the users are on a WooCommerce store page.
    • is_cart(): Check whether users are on a WooCommerce cart page.
    • is_checkout(): To check if the users are on a WooCommerce checkout page.
  • wp_redirect(): To redirect the visitors – not logged in – to the WooCommerce “My Account” page.
  • exit(): To terminate the current script and avoid further execution.

As you probably noticed, creating a private store WooCommerce programmatically has many limitations. For example, you cannot create a WooCommerce private category, and you can only hide your entire store to not logged users. To solve these problems, you need to use a powerful WooCommerce private store plugin free to create a WooCommerce shop only for registered users. Using the WooCommerce product table plugin, we will introduce below, you can easily restrict access to certain products or categories in your store.

Create a private WooCommerce shop by WooCommerce product table plugin

WooCommerce product table plugin is a very useful plugin for creating a private store in WooCommerce. You can add product fields, such as stock qty, price, etc., in a list with multiple columns and display it to users anywhere on the website using a shortcode. By adding filter, search, and other features, users can easily view and compare all products in the table and add the product to their shopping cart by clicking the add to cart button.

One of the useful features of this powerful plugin is the ability to set columns, rows, products, or specific categories to be displayed to registered users.

WooCommerce product table pro

Follow the simple steps below to create a WooCommerce shop only for registered users:

Step 1: Install the WooCommerce product table plugin

To install the plugin, just download and install and activate the plugin on your WordPress site. After activation, you will see that an item called Add new table has been added in the iT product table tab, by clicking on it and then the Get Start button, you will be led to the main page of the WooCommerce product table plugin.

select add new table section in iT product table menu

Step 2: Create a product table for WooCommerce private shop

On the main page, we provided all the essential tools for creating a product table with customer-friendly options. To customize the content and appearance of the table, set the items and configurations in the following tabs:Query: This is a good option if you want to create a table for some specific products or categories. You can include/exclude one or more products/categories to create a WooCommerce members-only shop by editing the items in this tab.

Columns: The Columns tab is the most important part of this plugin, allowing you to add as many columns and rows as you need to the product table and assign different content to the table cells.

select columns tab in iT product table plugin

Navigations: In the Navigation tab, you can add extra features like filtering, sorting, multi add to cart option, mini cart, etc. To the product table and make it more attractive for your customers.

select navigation tab in iT product table plugin

Style: You can find all configurations essential for customizing the appearance of your product table, here. Some preset templates make this task easier for you.

select style tab in in iT product table plugin

Now, let’s suppose that you have created a product table for selling food and wines like below and you want to create a private WooCommerce store. 

result food and wines table in private WooCommerce store

Note: To make this product table available on your website, you can add its shortcode to a new page of WordPress and publish it on your website.

Step 3: Create a WooCommerce shop only for registered users

You have flexible options to create a WooCommerce members-only shop in the WooCommerce private store plugin. Let’s review them one by one.

Create a WooCommerce members-only shop

If you want to hide the WooCommerce shop page for not logged-in users, you can go to the plugin Settings tab, locate Show for user roles field then choose Customer – or any other user role that you have created in WordPress Users tab for registered users.

select show for user roles field in settings tab

By choosing this option, when not logged-in users visit your shop page, they will see an empty page like below:

result user roles field in shop page

However, if they register to your website, the created product table will be displayed to them:

result product table for customers in private WooCommerce store

Hide some rows in the table to create a WooCommerce private shop

Sometimes, you don’t want to hide the whole product table for unregistered users. You just need to hide some rows in the table cells.

For example, suppose you have created one column and added Price and Quantity to one row. Now, you want to hide this row and not let unregistered users set quantity or review the product prices.

To make this happen, follow the below steps:

  • Click on the Setting button (1) of the Row in the Cell Content part of the column as illustrated below:
set hide rows for private shop in columns tab
  • Go to the General tab in the left panel and open the Condition for row tab.
  • Mark Add user role condition (2).
  • Choose Customer from the list of users.

Note: All users you have created in WordPress will be displayed here automatically. So, mark as many user roles as you need to create your WooCommerce private store.

select user role in general tab

The final result is like below for unregistered users:

result hide table rows for private shop

Hide some fields to create a WooCommerce shop only for registered users

In this WooCommerce private store plugin, you have the option for hiding some fields and making them private for registered users. For example, consider that you want to hide the Price field in your WooCommerce private store and just let customers see this field.

To do this, follow the below steps:

  • Add the Price element to one of the columns in the product table.
  • Click on the Price element to see the element setting panel. 
  • Scroll down the General tab in the Left panel to see the Condition for Element tab.
  • Open this tab and mark Add user role condition item.
  • Mark Customer from the list of users.
set hide fields for registered users in cell content

That’s it. You have successfully created your WooCommerce shop only for registered users. So, when not logged-in users visit the shop page, they won’t see the price of your products as illustrated below:

result hide table fields for registered users

Create a WooCommerce private category

Creating a WooCommerce private category is one of the most popular requirements of store managers. For example, consider that you are selling products in the food and wine categories in your shop, and you want to show the products in the Wine category only to registered users.

To make this happen, you need to create two separate tables and make queries for food and wines. Then, set some configuration for the Wines table to make it a WooCommerce private category.

Let’s see how.

  • Go to the Query tab and choose wine in the Include Taxonomy field.
select include taxonomy field in query tab
  • Customize your table content and design in the Columns, Navigation, and Style tab.
  • Open the Settings tab and scroll down to find Show for user roles.
  • Choose Customer from the list of users.
select show for user roles in settings tab
  • Insert a name for your table and save it.
  • Return to the WordPress Dashboard and go to the below address:

iT Product Table > Settings (1)

set category override in settings menu
  • In the General tab of Settings, Open Category Override tab (2).
  • Choose the category you want to show to the registered users only (3).
  • Open the dropdown list of the Override table and choose the name of your table from the list (4).

Your task is done. Now, the Wine category is only available for shop members, only.

WooCommerce product table pro

Conclusion

If you manage an online store, you probably need to restrict visitors from visiting the WooCommerce shop page or some part of it. To make this happen, you need to use a WooCommerce private store plugin like the WooCommerce product table plugin to have full control over the display of your shop page content. In this post, we described how using the WooCommerce product table plugin can help you easily create a WooCommerce members-only shop. If you have any further questions, feel free to ask us in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart
Sign in

No account yet?

We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.

Start typing to see products you are looking for.