I am trying to find a way to hide a product from the Woocommerce shop page. If the logged in user has already purchased said product.
I have already been able to block the user from purchasing again using woocommerce_is_purchasable
, and woocommerce_variation_is_purchasable
. But I would like to hide it all together not even shown to them in the shop page. I have been coming up empty on this one. So any help would be appreciated.
2
Answers
Bhautik's answer is technically correct based on the question asked. Hide product if user bought before.
However as mentioned in my question I'm already disabling purchase of said products using
woocommerce_is_purchasable
.Meaning the logic of what should be hidden is already in the software. Using his idea as a template I have made the answer more generic to operate off of
woocommerce_is_purchasable
. Meaning I only have to implement any conditional logic in that function and the shop will reflect by hiding said products (that are not purchasable).I am posting this as a second answer in case it helps others searching this problem. But will keep his as the selected answer to the question.
You can change the product query using the
pre_get_posts
action hook and then you can get current user products that they already purchased. pass all products id topost__not_in
. check the below code. code will go active theme function.php file.