doushun1904 2018-03-29 09:13
浏览 67
已采纳

哪个钩子可以根据用户角色过滤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

  • 写回答

1条回答 默认 最新

  • dtjw6660 2018-03-29 09:44
    关注

    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' )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?