以编程方式扩展WooCommerce订阅

时间:2020-04-28 14:57:44

标签: php wordpress woocommerce woocommerce-subscriptions woocommerce-memberships

我有超过30,000个WooCommerce订阅过期的用户,我希望这些订阅可以轻松扩展。有没有办法我可以通过编程方式做到这一点?还是我可以运行的简单MySQL语句?有人做过吗?任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

add_action( 'admin_init', 'change_expired_subscription_to_active' );

function change_expired_subscription_to_active() {
    $expired_subscriptions = get_posts( array( 'post_type' => 'shop_subscription', 'post_status' => 'wc-expired' ) );
    if(!empty(expired_subscriptions)){
      foreach ( $expired_subscriptions as $post ) {
        update_post_meta( $post->ID, '_requires_manual_renewal', true );
        wp_update_post( array( 'ID' => $post->ID, 'post_status' => 'wc-active' ) );
    }
  }
}

尝试此代码