Hi there i was wondering if it was possible to hide the "Wholesale Ordering Form" to users who are not logged in as Wholesaler, we have made it so other user roles cannot access this section but preferably would want it to not display to regular customers at all. The account tab has been linked using a custom snippet provided by Wholesale Suite for WooCommerce Wholesale Order Form.
-
Can you provide the snippet they gave you and what user roles you want it to display for? Like the actual user-role name that gets assigned in the DB. This should be relatively simply but I'd need that info to provide you with the code.– Tony DjukicCommented May 20, 2020 at 17:21
1 Answer
I'm not sure what the snippet you used is, but you can wrap it in an if statement like this:
if(in_array('wholesaler', wp_get_current_user()->roles)) {
// Your snippet here
}
This will only run the snippet that adds that tab when the user that is logged in has the wholesaler role. Be sure to replace wholesaler
with whatever the slug of that role is on your website.
Edit:
If you want to check multiple arrays, you can just do this:
$roles = wp_get_current_user()->roles;
if(in_array('wholesaler', $roles) || in_array('administrator', $roles)) {
// Your snippet here
}
If you have more than two roles you want to check, here's an answer on how to check multiple values with in_array.
-
How do i get it to display to multiple roles? Like this: "'Administrator', 'Wholesaler',"?– YxngLBZCommented May 17, 2020 at 13:45
-
-
1