首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按分类分类对Woocommerce产品进行分类筛选

按分类分类对Woocommerce产品进行分类筛选
EN

Stack Overflow用户
提问于 2018-02-12 18:56:21
回答 1查看 881关注 0票数 0

我有自定义分类设备与我的产品与Woocommerce默认产品类别。

我想把我的产品列在每个产品类别下,根据自定义分类进行搜索。

例如,

设备有价值:devise-1devise-2

使用devise-1进行搜索时,列表将是:

  • 类别-1
    • 产品-1
    • 产品-2

  • 类别-2
    • 产品-1
    • 产品-2

EN

回答 1

Stack Overflow用户

发布于 2018-02-13 06:26:34

我找到了一种符合我要求的解决办法,但我认为它很昂贵。因为它是每个类别的查询DB。

`

代码语言:javascript
复制
<?php
   $args               = array(
  'orderby'    => 'title',
  'order'      => 'ASC',
      'hide_empty' => TRUE,
      'taxonomy'   => 'product_cat'
    );

    $product_categories =  get_terms($args);
    foreach ($product_categories as $product_category) : ?>
        <h2 class="title ">
        <a href=" <?php echo get_term_link($product_category) ?>"> <?= $product_category->name; // Print Product categories ?> </a>
        </h2>

  <?php
           $args     = array(
          'posts_per_page' => -1,
          'tax_query'      => array(
            'relation' => 'AND',
            array(
              'taxonomy' => 'product_cat',
              'field'    => 'slug',
              'terms'    => $product_category->slug
            ),
            array(
              'taxonomy' => 'device',
              'field'    => 'slug',
              'terms'    => $device_type,
              'operator' => 'IN'
            )
          ),
          'post_type'      => 'product',
          'orderby'        => 'sku,'
        );
        $products = new WP_Query($args);
     // Inner Product loop
     while ($products->have_posts()): $products->the_post(); ?>
            <?php wc_get_template_part('content', 'product');  ?>
          <?php endwhile; ?>

`

任何人都有一个简单的解决方案。谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48753562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档