-3

WordPress Experts can anyone help me with this topic? I am creating a directory for a client. They have a membership site using woocommerce subscriptions. I created a custom post type for their members to manage their listings. I am trying to hide listings for anyone who lets their membership expire. I can't find a way to do it. It seems to me that this should be possible but I haven't found a solution and I am hoping I might have missed it or that someone else may have come across this already.

Any help is greatly appreciated.

1 Answers1

0

You can use the wc_memberships_user_membership_status_changed hook to catch every membership's status update. Whenever a membership becomes cancelled or expired, you need to:

  1. Get user ID
  2. Get all user's posts belonging to your custom post type
  3. Loop through each post and update its status to private using the wp_update_post() function (or run a single SQL query doing the same thing)
Artemy Kaydash
  • 459
  • 5
  • 4
  • Forgot to add: if you use WooCommerce Subscriptions without the WooCommerce Memberships, you'll need to use other actions: read more in the [WooCommerce Subscriptions documentation](https://woocommerce.com/document/subscriptions/develop/action-reference/#section-2) – Artemy Kaydash Jan 20 '22 at 18:46