$subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions();
var_dump( $subscriptions );
结果:
...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 :(得分: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;