获取第三级类别WooCommerce

时间:2017-04-27 作者:Ammad Nazir

我正在尝试获得三级WooCommerce类别。下面是我的源代码:

$args = array(
    \'hierarchical\' => 1,
    \'show_option_none\' => \'\',
    \'hide_empty\' => 0,
    \'parent\' =>18,
    \'taxonomy\' => \'product_cat\'
);
$subcats = get_categories($args);
echo \'<div class="wooc_sclist">\';
foreach ($subcats as $sc) {
    $link = get_term_link($sc->slug, $sc->taxonomy);
    echo \'<ul><a href="\' . $link . \'">\' . $sc->name . \'</a>\';
$args2 = get_term(array(
            \'hierarchical\' => 0,
            \'hide_empty\' => false,
           // \'taxonomy\' => \'product_cat\'
        ));
        $subsubCats = get_categories($agrs2);
        foreach ($subsubCats as $subsubCats) {
            $SubLinks = get_term_link($subsubCats->slug, $subsubCats-
   >taxonomy);
            echo \'<li>sub -<a href=\' . $SubLinks . \'>\' . $subsubCats->name .\'</a></li>\';
        }
echo \'</ul>\';
}
echo \'</div>\';
wp_reset_query();

1 个回复
SO网友:Ammad Nazir

我自己解决的

      $args = array(
        \'hierarchical\' => 1,
        \'show_option_none\' => \'\',
        \'hide_empty\' => 0,
        \'parent\' => $number = 16,
        \'taxonomy\' => \'product_cat\'
    );
    $subcats = get_categories($args);
    echo \'<div class="wooc_sclist">\';
    foreach ($subcats as $sc) {
        $link = get_term_link($sc->slug, $sc->taxonomy);
        echo \'<ul><a href="\' . $link . \'">\' . $sc->name . \'</a>\'.$sc->term_id;
        $args2 = get_terms(\'product_cat\',array(
            \'child_of\' => $sc->term_id,
            \'hierarchical\' => 1,
            \'hide_empty\' => 1,
        ));
        foreach ($args2 as $subsubCats) {
            $SubLinks = get_term_link($subsubCats->slug, $subsubCats->taxonomy);
            echo \'<li>sub - <a href=\' . $SubLinks . \'>\' . $subsubCats->name . \'</a></li>\';
        }
        echo \'</ul>\';
    }
    echo \'</div>\';
    wp_reset_query();

相关推荐