Tell us what you are trying to do?
Trying to display (or hide) front-end content based on purchased product.
I have a custom post type that includes a Woocommerce product field - using the post reference field that holds the product ID.
I want to hide the content if the user has not purchased the product.
I am currently doing this by simply checking if the current user is a customer (if they are not a customer, they can't see the content), but now I need to hide it if the customer has not purchased the SPECIFIC product.
The customer id and the product id are both available in the "wp_wc_order_product_lookup" table, but I'm not sure how to write the conditional to hide the content if the customer has not purchased the product.
Thanks for any assistance!
Hello,
There isn't such kind of built-in feature within Toolset plugins, you might consider custom codes.
For example:
1) Create a custom shortcode with PHP function:
https://developer.wordpress.org/reference/functions/add_shortcode/
2) In this PHP function, get current post ID:
https://developer.wordpress.org/reference/functions/get_the_id/
Use above post ID to get the related product post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Use above product ID to check if current logged-in user purchased that product:
hidden link
Then output what you want.
Luo,
I don't understand why I need to add additional custom functions in a shortcode to get the IDs of post and product - I already have both of these ID's available in my View's output.
In order to check if the current logged-in user has purchased that product, you need to get the related product ID, and it is only an suggestion for your reference.