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 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
    • ¥50 如何openEuler 22.03上安装配置drbd
    • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
    • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
    • ¥15 Windows11, backspace, enter, space键失灵