【问题标题】:Get Subscription Product author of a Woocommerce subscription获取 Woocommerce 订阅的订阅产品作者
【发布时间】:2019-07-29 23:00:15
【问题描述】:

如何遍历所有当前活动的 woo 订阅并打印发布与每个活动订阅相关的产品的用户的用户 ID (PHP)?我认为这样的事情只会提供订阅:

$args = array( 'subscriptions_per_page' => -1, 'post_type'   => 'shop_subscription', // WC orders post type
                'post_status' => 'wc-active' );
            $subscriptions = wcs_get_subscriptions( $args );

【问题讨论】:

    标签: php wordpress woocommerce author woocommerce-subscriptions


    【解决方案1】:

    以下代码将查询所有活动订阅以获取作者 ID(即发布活动订阅的产品):

    // Get all active subscriptions
    $subscriptions = wcs_get_subscriptions( array(
        'subscriptions_per_page' => -1,
        'subscription_status' => array('active') // Active subscriptions
    ) );
    
    // 1) Loop through quieried active subscriptions
    foreach($subscriptions as $subscription)
    {
        // 2) Loop through subscription items
        foreach( $subscription->get_items() as $item_id => $item ) 
        {
            // Get the subscription product author
            $author_id = get_post_field ('post_author', $item->get_product_id());
            // Display
            echo $author_id . '<br>';
        }
    }
    

    经过测试并且有效。

    【讨论】:

      猜你喜欢
      • 2017-12-03
      • 2021-01-25
      • 2017-06-18
      • 2016-12-29
      • 2017-09-17
      • 1970-01-01
      • 2017-03-11
      • 2022-08-19
      • 2021-07-01
      相关资源
      最近更新 更多