php 商品显示,php – WooCommerce仅显示购买的商品

您可以采取至少两种不同的方法来解决此问题.

第一种是从每个帖子中获取产品,然后从每个产品中获取产品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();

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值