I am working with a company that provides online content in the form of semesters you pay to access. The semester is set up like a product that you purchase through WooCommerce.

We've been applying a convoluted and inefficient method to grant access to the semester's tutorials, but it's the way it's been done since its inception. However, they are coming out with another semester this week and this process will no longer be viable. Users now have multiple options to choose from, and whichever class they choose needs to be unlocked while keeping the alternative semesters locked.

I feel the best way to grant them access to their chosen class is to query the database to find information on the user and which semester they purchased. That may require WP_Query, $wpdb->, combining tables, or there may be a much simpler answer I'm just not seeing.

I know that a woocommerce purchase is a custom post type called shop order, what I don't know is what column identifies the specific product, how to tie a user to that product, and how to create the database query to pull the users. Any help would be greatly appreciated.


You'll find details here: https://gist.github.com/lukecav/05afef12feaf980c121da9afb9291ad5


Another approach is https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query . Use if....else and store order data in Arr[product_id] = OrderArr

Kindly accept my answer if it is of any help.

  • Thank you. Your answer was helpful. – Mainfram3 Oct 4 '19 at 18:13
  • 1
    this was helpful to me. – Amol Bhandari SJ Nov 1 '19 at 5:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.