2016-09-28 1 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;