Support

Account

Home Forums General Issues Show products by custom fields Reply To: Show products by custom fields

  • Okay I will try it.

    I’ve got a Woocommerce shop. There the customers can register. There are also four different customer categories: A, B, C and D. If a customers has registered, the admin can choose (with the radio button field ‘kundentyp’) on the profile page which typ the customer will be.

    Then there are the normal product categories. In the backend on the category page the admin also can choose (with a radio button field called ‘kundenzugang’) which customer category is allowed to visit this category.

    Every product has a field, where the admin can choose if the product should be published or not. So if there’s a customer B and want to visit the category ‘test’ where he hasn’t got an access (because only D is allowed to) and this category includes a product where this “public field” is tiggered, he is able to see this product in the frontend. Otherwise this public field isn’t tiggered he isn’t able to that product.

    So I’ve created a function for my functions.php which should go through all posts and check if the user is allowed to see the products. If there are product’s he isn’t able to see, the id of this product is written in an array ($id_arr). After that the array is taken to the ‘post__not_in’ to exclude them from the query.

    But my function (see first post) will not work and I don’t know why..

    I hope it’s a better explanation. Thanks for your help. 🙂