Skip Navigation

[Closed] Conditional display based on purchased Woocommerce product

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2555799

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!

#2556363

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.

#2556655

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.

#2557835

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.

The topic ‘[Closed] Conditional display based on purchased Woocommerce product’ is closed to new replies.