仅根据作者在WooCommerce中的前端中的用户角色显示产品
我有一个供应商市场。我只想显示由某个作者用户角色(供应商)创建的产品。
为了澄清,我不是要更改用户角色所看到的。仅尝试显示由供应商创建的产品。
我发现隐藏产品仅显示给WooCommerce中某些用户角色分配的产品答案代码,
但是我可以将代码的哪一部分更改为哪个部分添加作者用户角色?有建议吗?
I have a vendor marketplace. I’d like to only display products that was created by a certain author user role (vendor).
To clarify, I’m not trying to change what user role sees what. Only trying to display products which are created by vendor.
I found Hide products only show assigned products to certain user roles in woocommerce answer code
But what part of the code would I change to add the author user role? Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要仅根据用户角色显示产品,您可以使用
woocommerce_product_query
在我的答案中,我使用
get_users()
wordpress函数,检索与某些标准匹配的用户列表。一旦获得了属于用户角色的所有ID,我们就可以使用
wuter__in
显示与某些作者相关的帖子,因此您可以得到:
To display only products based on user roles you can use the
woocommerce_product_query
action hookIn my answer I use the
get_users()
WordPress function, to retrieve a list of users matching certain criteria.Once all IDs belonging to user roles have been obtained, we can use
author__in
to show posts associated with certain author(s)So you get: