A
A
Andrew2017-04-17 03:28:21
WordPress
Andrew, 2017-04-17 03:28:21

Creating woocommerce side navigation menu?

How to create a category navigation sidebar on a product page?
Of this type57da72ce8b144db49afb4ff2a065941a.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sklyarov, 2017-04-17
@0example

I wrote this for myself a long time ago, I use it to this day:

<ul class="main-cat-menu">
                <?php
//Вывод рубрик товаров Woocommerce
$args               = array(
    'number' => $number,
    'orderby' => 'term_id',
    'order' => 'ASC',
    'hide_empty' => $hide_empty,
    'include' => $ids,
    'parent' => '0'
);
$product_categories = get_terms('product_cat', $args);
$count              = count($product_categories);
if ($count > 0) {
    foreach ($product_categories as $product_category) {
        $args          = array(
            'hierarchical' => 1,
            'show_option_none' => '',
            'hide_empty' => 0,
            'parent' => $product_category->term_id,
            'taxonomy' => 'product_cat'
        );
        $numberOflinks = $numberOflinks + 1;
        $subcats       = get_categories($args);
        if (empty($subcats)) {
            $arrow = 'no-arrow';
        } else {
            $arrow = '';
        }
        echo '<li class="' . $product_category->slug . ' ' . $arrow . '">
              <a href="' . get_term_link($product_category) . '">
                            <img src="' . get_template_directory_uri() . '/img/svg/' . $numberOflinks . '.svg" height="25" class="svg" />
                ' . $product_category->name . '
              </a>
              ';
        if (!empty($subcats)) {
            echo '<ul>';
        }
        foreach ($subcats as $sc) {
            $link = get_term_link($sc->slug, $sc->taxonomy);
            echo '<li><a href="' . $link . '">' . $sc->name . '</a></li>';
        }
        if (!empty($subcats)) {
            echo '</ul>';
        }
        echo '
  </li>';
    }
}
?>
                </ul>

Perhaps the quality of the code is lame, but it works.

S
Site Developer, 2017-04-17
@secsite

Standard WC widget - categories.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question