最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Hide account tab to certain users

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked May 16, 2020 at 13:31 YxngLBZYxngLBZ 233 bronze badges 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 Commented May 20, 2020 at 17:21
Add a comment  | 

1 Answer 1

Reset to default -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.

发布评论

评论列表(0)

  1. 暂无评论