1

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.

enter image description here

1
  • 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 Djukic May 20 '20 at 17:21
-1

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.

3
  • How do i get it to display to multiple roles? Like this: "'Administrator', 'Wholesaler',"? – YxngLBZ May 17 '20 at 13:45
  • I've edited my question. If it helps you, please accept it. – jxxe May 17 '20 at 17:27
  • 1
    All working, thank you very much! – YxngLBZ May 18 '20 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.