How to hide the WooCommerce Shop page

I’ve been asked if it is possible to hide the WooCommerce Shop page based on Groups’ access restrictions. As it is, trying to apply the normal way (checking a capability in the Access restrictions of the page) simply doesn’t work.

So what does work? Here’s an example:

Let’s assume that you are protecting your pages using the standard groups_read_post capability, any user that belongs to a group with that capability should be able to access the Shop page.

Create the woocommerce folder under the base folder of your active theme and copy archive-product.php from woocommerce/templates there.

At the top of your fresh copy, insert:

if ( class_exists( 'Groups_User' ) ) {
	$redirect = true;
	if ( $user_id = get_current_user_id() ) {
		$user = new Groups_User( $user_id );
		if ( $user->can( 'groups_read_post' ) ) {
			$redirect = false;
	if ( $redirect ) {
		wp_redirect( get_bloginfo( 'home' ) );

… right before:


This will redirect visitors who try to access the Shop page to the site’s home page.

, , , ,

32 Responses to How to hide the WooCommerce Shop page

  1. lastafa October 4, 2013 at 6:56 am #

    Great stuff! Does this or another approach with the groups plugin work for single products? I have tried many plugins for having members-only products, restricting access to the product and removing it from catalog etc.

    Thank you for any input or direction. :)

    • antonio October 4, 2013 at 8:46 am #

      yes, you can restrict access to products.

      • Valeriy December 2, 2013 at 11:23 pm #

        Hi Antonio, how i can hide products in shop page if user without registration


        • kento December 4, 2013 at 11:09 am #

          Hi Valeriy,

          For example, add the groups_read_post capability to the Registered group. Then use the Access restrictions box – add groups_read_post under Enforce read access – on those products you want to hide from unregistered visitors.

          • Valeriy December 4, 2013 at 6:50 pm #

            kento hi, i need use plugin?

            • kento December 4, 2013 at 7:03 pm #

              Only Groups :)

              • Mo October 28, 2014 at 7:50 am #

                Hi, after adding this capability to products, is there anyway to redirect the product to login page instead of hiding them?

                • kento October 30, 2014 at 8:41 pm #

                  Hi, yes, instead of wp_redirect( get_bloginfo( 'home' ) ); you can use:

                  $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                  wp_redirect( wp_login_url( $current_url ) );

                  This would also return to the shop page after login.

  2. lastafa October 4, 2013 at 10:22 am #

    Thanks Antonio, this works absolutely brilliant!

  3. Bernhard January 2, 2014 at 4:06 am #


    I am also using groups access restrictions in order to realize a member’s only section on my page. Everything works fine, but the woocommerce categories are still shown. No products are shown for registered members, but all categories.

    How can we hide the categories as well?

    thx for your help,

    • kento January 9, 2014 at 9:38 am #

      Hi Bernhard,

      This is something I’m currently looking at – restricting categories based on groups. It might be made part of the core plugin or a separate extension, depending on the impact and complexity.

      One approach you could use currently is to adjust the templates used to display products in categories and the categories themselves – Groups’ API can be used to check the membership and display them conditionally.

      I hope that helps at least to point you in the right direction.


      • Bernhard January 29, 2014 at 1:57 pm #

        Hi Kento,

        thx for your reply. I think it could help if I would be clever enough to build it into the template like you suggested. Sadly that is beyond my scope..

        So I do hope this feature becomes available as plugin feature soon..


        • kento January 29, 2014 at 2:43 pm #

          Thanks for the feedback and the suggestion Bernhard, yes that would require adequate knowledge on how to code it into the template. It might be an option with advanced logic built into the plugin, but this hasn’t been done yet.

  4. Masayuki January 24, 2014 at 3:23 pm #


    I am using WooCommerce, Groups, Groups WooCommerce and Affiliates Enterprise.
    I think these are fantastic plugins!
    I want to know how to set a specific product is not shown to the Premium group.

    My client has a product for Non-registration customers.(ex.Product A)
    And also, client has product for Premium group members.(ex.Product B)
    It is the scenario which is promoted to a Premium group member when the Non-registration customer buys product A.

    [Visibility Restriction Case 1]
    Non-registration customer can see Product A.
    Premium group member can not see Product A.

    [Visibility Restriction Case 2]
    Premium group member can see Product B.
    Non-registration customer can not see Product B.

    Case 2 is easy to setup using “groups_read_post” capability.
    But I could not set Case 1.
    I have searched for Forum, but I did not find useful information.
    I feel it can be set if there is something like “groups_unread_post”….

    Please advise how to set Restriction Case 1.

    Thank you.

    • kento January 29, 2014 at 1:49 pm #

      Hi Masayuki,

      Many thanks for the feedback on the plugins and for using them :)

      For the case you have explained, one way is to use product-related capabilities assigned to product-specific groups.

      For example:

      Product “A” – Group “A” – capability “a”
      Product “B” – Group “B” – capability “b”

      Then you can distinguish more precisely who can see what based on group membership. The only thing that this doesn’t cover, is hiding Product A from the Premium group members. This is something that you could build into the template but you can’t achieve it using the back end UI elements.


  5. Masayuki January 29, 2014 at 2:38 pm #

    Hi Kento,

    Thank you for your response.
    I understand.
    In the meantime, I decided that the non-registration customers will added to something new group after registration.


  6. Groggy February 15, 2014 at 5:47 am #

    Hi Kento
    Many thanks for explaining this – I have manage to block the shop page and redirect to the home page but is there any chance you could explain that instead of redirecting to the home page how to redirect to the login page and then to the shop? I would really appreciate your help. Thanks

  7. Groggy February 15, 2014 at 9:42 pm #

    ok I have found some code that will redirect to the shop after login

    add_filter(‘woocommerce_login_redirect’, ‘ras_login_redirect’);

    function ras_login_redirect( $redirect_to ) {
    $redirect_to = “”;
    return $redirect_to;

    but the only thing I need know is how to direct the user to the login (my-account) when they click on shop on the homepage instead of being redirected back to the homepage – I’ve tried a few variables but they do not work as I’m not much of a coder – really appreciate your help on this one

  8. Dan February 20, 2014 at 12:39 am #

    Hi. My comment appears to have got deleted. I was just wondering how to redirect to the may account instead of wp_redirect( get_bloginfo( ‘home’ ) );


    • kento February 20, 2014 at 11:33 am #

      Hi Dan, probably an over-enthusiastic spam filter ate it ;)

      Do you mean something like this … ?

      $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
      wp_redirect( wp_login_url( $current_url ) );

      • Dan February 20, 2014 at 8:03 pm #

        Many thanks for taking to respond Kento. That works great.

  9. Thomas June 14, 2014 at 2:10 pm #

    How would I hide the woocommerce shop page based on affiliate log in? I would like the shop page to be seen only by affiliates who are logged in. I am using Affiliates Enterprise and Woocommerce. Thanks.

  10. Howard September 11, 2014 at 1:30 am #

    Hi Kento,
    We’re using the Groups plugin with WooCommerce. Is it possible to ‘hide’ a product from a registered group, instead of the opposite?
    So, we want to set up a free membership as a product. Once they join, the ‘membership’ product should then be hidden from members of that group. But it is still visible to everyone else.
    We want it this way as free membership also comes with a free product, so members can only join once.

    • kento September 12, 2014 at 2:17 pm #

      Hi Howard,

      You would need to implement a customized solution for that, it can use Groups’ API and similar to what is explained in Exclude products from a particular category on the shop page, if you use a category for these and also check if the user belongs to the product’s group, then you should be able to achieve that effect.

      Does that help?

  11. Anne B February 10, 2015 at 11:06 pm #

    I am using WordPress Multisite and want to hide the shop page in one of the client sites…. multisite doesn’t allow you to play around with theme directories for the individual client sites (that I can figure out anyway!). So any ideas how I can do this restriction without your suggestion in the blog post above?

  12. Henrik February 24, 2015 at 10:33 am #

    Everything works great with the code below, but I would like to redirect the user to the Woocommerce “My Account” page instead of the WordPress login. I have tried different solutions but can’t get my head around it.

    $current_url = ( is_ssl() ? ‘https://’ : ‘http://’ ) . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’];
    wp_redirect( wp_login_url( $current_url ) );

    • kento February 24, 2015 at 7:52 pm #

      Hi Henrik,

      Wouldn’t it be easier to simply indicate the My Account page’s URL as the parameter to wp_redirect() ?

      • henrik February 25, 2015 at 6:36 am #

        Yes that worked! I wasn’t thinking clearly. Thanks for the support!

Leave a Reply