dsux90368 2017-08-15 21:10
浏览 38
已采纳

获取所有WooCommerce订阅

I a need to create a wordpress template to collect all Woocommerce subscriptions, but I'm having trouble with the documentation. I need to know which files to import and which function to call.

Thank you in advice.

  • 写回答

2条回答 默认 最新

  • dougu4448 2017-08-16 00:45
    关注

    Update: Better use wcs_get_subscriptions() as explained in the answer of Andrew Schultz.

    As subscriptions are a custom post type, You can get all subscriptions IDs first. Then in a foreach loop you will be able to get the WC_subscription object.

    global $wpdb;
    
    // get all subscriptions IDS
    $subscriptions_ids = $wpdb->get_col("
        SELECT ID  FROM {$wpdb->prefix}posts 
        WHERE post_type LIKE 'shop_subscription'
    ");
    
    // Loop through subscriptions Ids
    foreach($subscriptions_ids as $subscription_id){
        // Get an instance of the WC_Subscription object
        $subscription = new WC_Subscription( $subscription_id );
    }
    

    Then with the $subscription object and the $subscription_id you will be able to do what you want, using WC_Subscription methods to get the desired data or the using subscription ID on dedicated functions.


    Official developer Documentation:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)
  • ¥30 notepad++ 自定义代码补全提示
  • ¥15 MATLAB有限差分法解一维边值问题
  • ¥200 内网渗透测试 横向渗透 Windows漏洞 Windows权限维持
  • ¥15 数据结构图的相关代码实现
  • ¥15 python中aiohttp.client_exceptions.ContentTypeError
  • ¥30 DeepLung肺结节检测生成最大froc值对应的epoch报错
  • ¥15 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家