I have the following code below and I am trying to achieve the following objectives :
- Change the wording hold to pause (this has been completed from the code below)
- Once a user logs into their account and puts their subscription 'on-hold'. After 30 days I need their subscription to automatically move back to being 'Active' and for the monthly payments to continue.
I am using woocommerce subscriptions plugin.
What I have is below but it doesn't completely work, It has been a over a month for some users who have put their subscription on hold and they haven't automatically re-activated, so I'm hoping to fix this with Stack Overflows help :)
add_filter( 'wcs_view_subscription_actions', 'wpse_custom_action_after', 11, 2 );
function wpse_custom_action_after( $actions, $subscription ) {
if (!empty($actions['suspend'])) {
$date = strtotime('+1 months');
$subscription_renew_date = date('Y-m-d', $date);
$actions['suspend']['url'] = $actions['suspend']['url'].'&suspend_end_date='.$subscription_renew_date;
$actions['suspend']['name'] = 'Pause';
}
return $actions;
}
add_action('woocommerce_customer_changed_subscription_to_on-hold','add_suspend_date_when_subscription_onhold');
function add_suspend_date_when_subscription_onhold($subscription) {
// print_r();exit();
$subscription_id = $subscription->get_id();
$date = strtotime('+1 months');
$subscription_renew_date = date('Y-m-d', $date);
update_post_meta($subscription_id, 'suspend_date',$subscription_renew_date);
}
Any help is much appreciated.
Thanks