哪个钩子可以根据用户角色过滤Woocommerce产品

I'm trying to filter the products based on the the type of customer that logs in. Using an attribute in the customer record which filter method would I use to automatically filter certain products from a custom so they cannot see them?

I've come across 'woocommerce_product_filters' in the docs but I'm not sure if this is the correct hook to use.

Any pointers would be a great help

To alter the product query in woocommerce archive pages and shop, you should better use on of this hooks:

  • woocommerce_product_query (action hook)
  • woocommerce_product_query_tax_query (filter hook)
  • woocommerce_product_query_meta_query (filter hook)

There is many examples on StackOverFlow and you will be able to filter easily from user roles using conditional function current_user_can( 'the_user_role' )