不要显示特定的woocommerce类别

问题描述 投票:-1回答:1

我有这个代码用于在移动主题中将新产品显示为hscroll但我想不显示具有1230 id的类别产品

我想通过添加一些代码来添加思考:$products->category-> != 1230首先如果请引导

<?php
    // new arrivals products
    $new_args = array( 
        'post_type' => 'product', 
        'posts_per_page' => 8,
        'orderby' =>'date',
        'order' => 'DESC'
    );
    $products = new WP_Query( $new_args );
?>


<?php if ( $products->have_posts() ) { ?>
<div class="title-intro content-block-title"><?php _e( 'New Arrivals', 'woomobify' ); ?></div>
<div class="product-hscroll swiper-container swiper-init" data-auto-height="true" data-free-mode="true" data-slides-per-view="auto">
    <div class="swiper-wrapper">

        <?php while ( $products->have_posts() ) : $products->the_post(); global $product; ?>

        <div class="swiper-slide">
            <div class="card">
                <div class="card-content">
                    <a href="<?= get_the_permalink(); ?>">
                        <?php 
                        if ( has_post_thumbnail($products->post->ID) ) {
                            echo get_the_post_thumbnail( $products->post->ID, 'shop_catalog' ); 
                        } else {
                            echo '<img src="'.wc_placeholder_img_src().'"/>'; 
                        } ?>
                    </a>

                        <div class="title"><?php the_title(); ?></div>
                        <div class="item-text product-price">
                            <span class="price"><?= wc_price( $product->get_price() ); ?></span>
                        </div>  </div> </div>
        <?php endwhile; ?>
woocommerce show-hide product categories
1个回答
0
投票

我认为你正在寻找的解决方案将在下面描述

https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/

或者为了使其更容易,使用下一个参数来检索所有产品,除非产品属于类别(id)1230

$args = array(
  'posts_per_page' => -1,
  'orderby' =>'date',
  'order' => 'DESC',
  'tax_query' => array(
    array(
        'taxonomy'      => 'product_cat',
        'field'         => 'id',
        'terms'         => array('1230'),
        'operator'      => 'NOT IN'))); 
© www.soinside.com 2019 - 2024. All rights reserved.