简体   繁体   English

获取Woocommerce订阅的订阅产品作者

[英]Get Subscription Product author of a Woocommerce subscription

How can I iterate through all current active woo subscriptions and print the user ID of the user who published the product related to each active subscription (PHP)? 如何遍历所有当前的活动woo订阅并打印发布与每个活动的订阅(PHP)相关的产品的用户的用户ID? I think something like this will give just the subscriptions: 我认为类似这样的东西只会提供订阅:

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

The following code will query all active subscriptions to get the author Id (that published the product of the active subscription): 以下代码将查询所有活动订阅以获取作者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>';
    }
}

Tested and works. 经过测试和工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM