Following the woocommerce documentation, I added an endpoit to my-account page in woocommerce.
I want to make this endpoint visible only to a specific user role, lets say shop_manager.
Is there a way to redirect to a 404 page users who try to access directly that endpoint?
Thanks in advance.
2
Answers
Just add the follows code snippet in your active theme’s functions.php and this is only for
administrator
user role, you can change it as per you –After this just
flush_rewrite_rules
from Backend Settings > Permalinks. Thats it.Assuming that you have already created a custom endpoint to my account section (see this related answer), you can redirect all non allowed user roles to a specific page using
template_redirect
hook in this simple way:You need to specify your custom end point, your allowed user role and the url redirection.
Code goes in functions.php file of your active child theme (or active theme). It could works.
Related: