The discussion revolves around synchronizing Discourse user suspension with WooCommerce Subscriptions membership status. omarfilip seeks guidance on suspending Discourse users when a WooCommerce subscription expires or is cancelled, and unsuspension upon renewal, using WooCommerce Subscriptions and Memberships as the SSO provider. They note that their current setup with dcpmp is no longer relevant. pfaffman references a Discourse meta guide but acknowledges it doesn’t handle suspension. simon confirms suspension is feasible and suggests hooking into the woocommerce_subscription_status_updated action, which provides the subscription object and status changes. omarfilip identifies specific actions like woocommerce_subscription_status_active, cancelled, and expired as relevant, and plans to test the subscription object to extract the associated user ID omarfilip.
Oh. I see. I don’t see that the plugin has a function to suspend the user (but may not know where to look). Worst can you can add an API call to the hook that gets called when their subscription fails and have it suspend the user. You can find it using Reverse engineer the Discourse API
Suspending and unsuspending users will be the easy part. The trick is to figure out which Woocommerce actions to hook into.
It looks like the woocommerce_subscription_status_updated action should work. That hook passes three parameter: $subscription, $new_status, $old_status. The status parameters are strings, so their value should be fairly self-explanatory. The $subscription parameter is a WC_Subscription object. I’m assuming that it contains details that let you find the user ID that the subscription is associated with. I’d have to take a look at it to confirm though.
Parameters:$subscription A WC_Subscription object representing the subscription that just had its status changed.
Description: This action is triggered after the subscription specified with $subscription has had its status changed to activated. The subscription’s status may have transitioned from pending to active, or on-hold to active or some other custom status to active.
Parameters:$subscription A WC_Subscription object representing the subscription that just had its status changed.
Description: This action is triggered after the subscription specified with $subscription has had its status changed.
The subscription’s status may have transitioned from pending to cancelled, or on-hold to cancelled, pending cancellation to cancelled or some other custom status to cancelled.
Action:'woocommerce_subscription_status_expired'
Parameters:$subscription A WC_Subscription object representing the subscription that just had its status changed.
Description: Triggered when a subscription reaches the end of its term, if a length was set on the subscription product when it was purchased or an end date was otherwise set on a subscription.