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' ) );
exit;
}
}
… right before:
get_header('shop');
This will redirect visitors who try to access the Shop page to the site’s home page.
Leave a Reply