php 商品显示,php – WooCommerce仅显示购买的商品
您可以采取至少兩種不同的方法來解決此問題.
第一種是從每個帖子中獲取產(chǎn)品,然后從每個產(chǎn)品中獲取產(chǎn)品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();
?>
總結(jié)
以上是生活随笔為你收集整理的php 商品显示,php – WooCommerce仅显示购买的商品的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle里的concat,oracl
- 下一篇: php apc 失效时间,PHP APC