我运行 WordPress、WooCommerce、WooCommerce 会员资格和 WooCommerce 订阅。
在这里,我试图查找用户和他们购买的会员资格,每个会员资格基本上都是一个产品,然后我试图循环显示他们订阅的会员信息 - 每个会员的特色图像和名称。
我在下面的代码列出了所有成员资格,但我不知道我做错了什么。
<div id="sidebar">
<div class="sidebar-title">
<h2>My Subscriptions</h2>
</div>
<div class="sidebar-body">
<div class="channel-package-list">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 20,
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
// get all active memberships for a user;
// returns an array of active user membership objects
$user_id = get_current_user_id();
$args = array(
'status' => array( 'active', 'complimentary', 'pending', 'free_trial' ),
);
$active_memberships = wc_memberships_get_user_memberships( $user_id, $args );
while ( $loop->have_posts() ) : $loop->the_post();
if ( ! empty( $active_memberships ) ) {?>
<div class="package-list-item">
<div class="active-package"><i class="fa fa-check" aria-hidden="true"></i></div>
<a href="javascript:;" class="group-link" data-id="27">
<figure>
<img src="<?php echo get_the_post_thumbnail_url($post , 'thumbnail'); ?>" class="img-responsive" style="max-width: 100px; max-height: 100px" alt="">
<figcaption><?php echo get_the_title($post ); ?></figcaption>
</figure>
</a>
</div>
<?php } endwhile;
} else {
echo __( 'No packages found' );
}
wp_reset_postdata(); ?>
</div>
</div>
</div>