Support » Plugin: Members - Membership & User Role Editor Plugin » Not restricting woocommerce content

  • Hello,

    I would like to hide my shop page and products (woocommerce) but it doesn’t work. Do i do something wrong ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter p4ssc3


    UP : I just see the snipet you give 4 days ago, it works on products well. So now it’s just about the “Shop page”, still not working on this.

    Plugin Author Caseproof


    Hi @passce

    Here’s the snippet for WooCommerce Shop pages:

    add_action( 'template_redirect', function() {
    	// Redirect users without the required capability
    	$cap = 'custom_cap'; // Change this to whatever capability
    	if ( function_exists( 'is_shop' ) && is_shop() && ! current_user_can( $cap ) ) {
    		$redirect = 'https://woocommerce.test/unauthorized'; // Change this to the correct URL
    		wp_redirect( $redirect );
    } );

    You can add this at the end of your theme’s functions.php file. The $cap variable needs changed to whatever capability should have permission to view the shop page. The $redirect should be changed to the redirect URL for when a user doesn’t have permission.


    • This reply was modified 1 month, 1 week ago by Caseproof.

    Hi @caseproof,

    I have the same problem and you say on your solution to add that snippet at the end of my theme’s functions.php file, but where exactly? at the last line or before the line which returns the theme’s instance? Just want to now where exactly.

    Side question – what do you mean by capabilities? can you show a example with user roles

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.