• Resolved p4ssc3

    (@passce)


    Hello,

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

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

    (@passce)

    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

    (@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 );
    		exit;
    	}
    } );

    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.

    Best

    • This reply was modified 3 years, 8 months 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)
  • The topic ‘Not restricting woocommerce content’ is closed to new replies.