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.