【问题标题】:Programmatically extending a WooCommerce Subscription以编程方式扩展 WooCommerce 订阅
【发布时间】:2020-08-12 10:45:41
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:
    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' ) );
        }
      }
    }
    

    试试这个代码

    【讨论】:

      猜你喜欢
      • 2013-06-14
      • 2018-08-06
      • 2019-10-14
      • 2017-01-27
      • 2021-11-10
      • 2013-03-19
      • 2018-08-21
      • 1970-01-01
      • 2021-10-20
      相关资源
      最近更新 更多