How can I create an Hook in woocommerce (wordpress) to be able to trigger a function when a subscription expires?
Something like this
add_action('woocommerce_subscription_expired', 'my_function', 10, 1);
function my_function($order_id) {
echo "yeahhhh";
}
UPDATE
I found in the developer doc the following
Action: ‘subscription_expired’
Parameters: $user_id Integer The ID of the user for whom the
subscription expired. $subscription_key String The key for the
subscription that just expired on the userâs account.Description: Triggered when a subscription reaches the end of its
term, if a length was set on the subscription when it was purchased.
This event may be triggered by either WooCommerce Subscriptions, which
schedules a cron-job to expire each subscription, or by the payment
gateway extension which can call the
WC_Subscriptions_Manager::expire_subscription() function directly.
Where should I place this to have it working
Thanks
Looks like you are almost there. You just need to use Subscription’s action hook and pass the correct parameters. This seems like a start:
The
wcs_get_subscription_from_key
is now deprecated, since version 2.0.You can now use:
More hooks (and this one) at Subscriptions Action Reference