2016-09-28 11 views
0
$subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions(); 
var_dump($subscriptions); 

結果:Woocommerce ORDER_ID NULL

...snip... 

'2794_1425' => 
array (size=15) 
    'order_id' => null 
    'product_id' => string '106' (length=3) 
    'variation_id' => string '121' (length=3) 
    'status' => string 'on-hold' (length=7) 
    'period' => string 'month' (length=5) 
    'interval' => string '1' (length=1) 
    'length' => int 0 
    'start_date' => string '2016-08-26 14:31:25' (length=19) 
    'expiry_date' => int 0 
    'end_date' => int 0 
    'trial_expiry_date' => int 0 
    'failed_payments' => string '' (length=0) 
    'completed_payments' => 
    array (size=1) 
     0 => string '2016-08-26 14:52:47' (length=19) 
    'suspension_count' => string '1' (length=1) 
    'last_payment_date' => string '2016-09-27 14:28:38' (length=19) 

    ...snip... 

如何ORDER_ID爲NULL?我可以在訂單頁面看到訂單,並且它有一個ID。

+0

哦,是的,這是很奇怪的,我還測試在我的身邊,用不同的訂單狀態,但我總是得到一個訂單ID。在代碼'2794_1425'=>'的第一行中,'_'字符之前的引用的第一部分似乎與訂單ID(在我的情況下)相匹配。所以你的訂單ID應該是** 2794 **。這是我能告訴你的唯一的事情。 – LoicTheAztec

回答

0

啊,我看了一下WC_Subscriptions_Manager這個班。

public static function get_all_users_subscriptions() { 
    _deprecated_function(__METHOD__, '2.0'); 

    foreach (get_users() as $user) { 
     foreach (wcs_get_users_subscriptions($user->ID) as $subscription) { 
      $subscriptions_in_old_format[ wcs_get_old_subscription_key($subscription) ] = wcs_get_subscription_in_deprecated_structure($subscription); 
     } 
    } 

    return apply_filters('woocommerce_all_users_subscriptions', $subscriptions_in_old_format); 
} 

wcs_get_subscription_in_deprecated_structure($subscription)在不推薦使用的結構中獲取訂閱。沒有繼續看這一點。取而代之的是,有像這樣所有訂閱:

$subscriptions = array(); 

    foreach (get_users() as $user) { 
     if (count(wcs_get_users_subscriptions($user->ID))) { 
      $subscriptions[] = wcs_get_users_subscriptions($user->ID); 
     } 
    } 

    // return false if there are no subscriptions 
    $return = count($subscriptions) ? array_values($subscriptions) : false;