获取Woocommerce订阅的订阅产品作者 [英] Get Subscription Product author of a Woocommerce subscription

查看:108
本文介绍了获取Woocommerce订阅的订阅产品作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)? 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 );

推荐答案

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

The following code will query all active subscriptions to get the author Id (that published the product of the active subscription):

// 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.

这篇关于获取Woocommerce订阅的订阅产品作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆