Skip Navigation

[Resolved] Delete post when WooCommerce Subscription expires or is canceled

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to delete a post when a User's WooCommerce Subscription is canceled or expires.

Solution: Toolset does not have any hooks that will help you respond to WooCommerce Subscription events, so I would ask WooCommerce Subscriptions' support team if they offer an API that will allow you to perform some action when a subscription is canceled or expires. If so, then you can use some custom code to set the post to "draft" status, which would effectively remove it from the front-end of the site. You could reinstate the post at any time if the subscription is renewed. Here's an example ticket on stackoverflow that modifies a post's status:
https://wordpress.stackexchange.com/questions/12512/how-to-update-page-status-from-publish-to-draft-and-draft-to-publish

0% of people find this useful.

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#728196

Tell us what you are trying to do?

Supplier registers to a subscription service,
creates a Listing for his business ( CPT 'supplier listing' )
and when the subscription is cancelled/not renewed the Listing data disappears from the front end.

Is there any documentation that you are following?

I have set off down several routes so far.

Route 1: Cred NEW USER Form + SUMO Subscriptions + Custom Post Type (Supplier)
Result: User created with no role set.

Route 2: Cred NEW USER Form + Woocommerce Subscriptions + Custom Post Type (Supplier)
Result: Clashes with which plugin should register the account type.

Route 3: Most promising so far.
1. Visitor registers (NEW USER cred FORM or otherwise)
2. A visitor creates a Suppliers Listing listing via A CRED POST form & Cred Commerce.
3. Payment is taken and subscription is initiated. (Sumo or WooSubscription)
-- So far all working ok --

The bit I need help with is if Joe Blogs does NOT renew his subscription or we CANCEL it,
Can his custom post (Supplier listing) be deactivated?

Or what plugin will actually turn off or change a value if not renewed?

PLease and thanks

#729283

Toolset does not have any hooks that will help you respond to WooCommerce Subscription events, so I would ask WooCommerce Subscriptions' support team if they offer an API that will allow you to perform some action when a subscription is canceled or expires. If so, then you can use some custom code to set the post to "draft" status, which would effectively remove it from the front-end of the site. You could reinstate the post at any time if the subscription is renewed. Here's an example ticket on stackoverflow that modifies a post's status:
https://wordpress.stackexchange.com/questions/12512/how-to-update-page-status-from-publish-to-draft-and-draft-to-publish