您可以采取至少两种不同的方法来解决此问题.
第一种是从每个帖子中获取产品,然后从每个产品中获取产品ID,然后使用if语句过滤使用wc_customer_bought_product或woocommerce_customer_bought_product(如果您使用的是旧的WooCommerece).
第一种方法的一个例子是
$user_id = get_current_user_id();
$current_user= wp_get_current_user();
$customer_email = $current_user->email;
$args = array(
'post_type' => 'product',
'posts_per_page' => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post(); $_product = get_product( $loop->post->ID );
if (wc_customer_bought_product($customer_email, $user_id,$_product->id)){
woocommerce_get_template_part( 'content', 'product' );
}
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>