How to hide the WooCommerce Shop page

Posted by kento on February 12, 2013 11:36 am

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:

get_header('shop');

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

About kento
Computer Science Engineer, IT & Business Consultant, Drupal, WordPress, Scenario Planning ...

Leave a comment

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

*


five + 9 =

Please follow the Support guidelines.

Premium Support is available for customers in the Forums.