0
array (
0 => 
WC_Memberships_User_Membership::__set_state(array(
 'id' => 52330,
 'plan_id' => 18952,
 'plan' => 
WC_Memberships_Membership_Plan::__set_state(array(
   'id' => 18952,
   'name' => 'Level 2 Access Until June',
   'slug' => 'level-2-access-until-june',
   'post' => 
  WP_Post::__set_state(array(
     'ID' => 18952,
     'post_author' => '8',
     'post_date' => '2017-09-11 11:05:13',
     'post_date_gmt' => '2017-09-11 15:05:13',
  )),
   'access_method_meta' => '_access_method',
   'rules' => 
  array (
  ),
)),
 'user_id' => '5213',
 'status' => 'wcm-active',
 'post' => 
WP_Post::__set_state(array(
   'ID' => 52330,
   'post_title' => 'Auto Draft',

)),
 'product' => NULL,
 'renewal_login_token_meta' => '_renewal_login_token',
 'locked_meta' => '_locked',
)),
 1 => 
 WC_Memberships_User_Membership::__set_state(array(
 'id' => 28639,
 'plan_id' => 27786,
 'plan' => 
WC_Memberships_Membership_Plan::__set_state(array(
   'id' => 27786,
   'name' => 'Level 1 – Ethical and Professional Standards',
   'slug' => 'level-1-ethical-and-professional-standards',
   'post' => 
  WP_Post::__set_state(array(
     'ID' => 27786,
     'post_author' => '8',
     'post_mime_type' => '',
     'comment_count' => '0',
     'filter' => 'raw',
  )),
   'access_method_meta' => '_access_method',
   'email_content_meta' => '_email_content',
   'rules' => 
  array (
  ),
)),
 'user_id' => '5213',
 'status' => 'wcm-active',
 'post' => 
WP_Post::__set_state(array(
   'ID' => 28639,
   'post_author' => '5213',
   'post_date' => '2017-11-27 21:41:06',
   'filter' => 'raw',
)),
 'product' => NULL,
 'type' => 'manually-assigned',
 'locked_meta' => '_locked',
 )),
);

我有 woocommerce 方法给出的这个数组: wc_memberships_get_user_active_memberships($user_id);

我需要提取用户拥有的成员资格的名称,它必须在一个循环中,因为用户可以拥有多个成员资格。我希望找回姓名 = 2 级访问权限,直到 6 月,1 级 - 道德和专业标准

4

2 回答 2

1

根据您发布的内容,我会尝试以下操作:

$memberships_info = wc_memberships_get_user_active_memberships($user_id);

foreach ($memberships_info as $membership) {
    echo $membership['plan']['name'];
}

从 woocommerce 文档中,您可以指定活动会员的状态。因此,您可能希望这样做以包括所有成员资格类型:

$args = array( 
    'status' => array( 'active', 'complimentary', 'pending' ),
);  
$memberships_info = wc_memberships_get_user_active_memberships($user_id, $args); // adding the args bit to get all memberships

foreach ($memberships_info as $membership) {
    echo $membership['plan']['name'];
}

Woocommerce 文档:https ://docs.woocommerce.com/document/woocommerce-memberships-function-reference/

于 2017-12-22T21:37:52.970 回答
0

这最终对我有用。

$user_id = get_current_user_id();
$memberships = wc_memberships_get_user_active_memberships($user_id);

foreach ($memberships as $membership => $val) {
    echo $val->plan->name . '<br>';
};
于 2021-06-29T17:40:40.593 回答