douxiuyu2028 2019-05-30 07:11
浏览 54

如何在用户订阅30天后自动重新激活用户订阅?

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Qt安装后运行不了,这是我电脑的问题吗
    • ¥15 数据量少可以用MK趋势分析吗
    • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
    • ¥15 大智慧怎么编写一个选股程序
    • ¥100 python 调用 cgps 命令获取 实时位置信息
    • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
    • ¥15 C语言使用vscode编码错误
    • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
    • ¥20 ensp怎么配置让PC1和PC2通讯上
    • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法