如何从特定类别显示产品的子类别?

问题描述

功能运行良好,但它显示了每个子类别。我如何编辑它以仅显示某些子类别?例如,如果狗 (id 30) 是父类别,如何显示该类别的子类别?

// get all product cats for the current post
$categories = get_the_terms( get_the_ID(),'product_cat' ); 

// wrapper to hide any errors from top level categories or products without category
if ( $categories && ! is_wp_error( $category ) ) : 

    // loop through each cat
    foreach($categories as $category) :
      // get the children (if any) of the current cat
      $children = get_categories( array ('taxonomy' => 'product_cat','parent' => $category->term_id ));

      if ( count($children) == 0 ) {
          // if no children,then echo the category name.
          echo $category->name;
      }
    endforeach;

endif;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)