T
T
Tipello2017-06-05 21:41:33
WordPress
Tipello, 2017-06-05 21:41:33

How to make dropdown menu of Woocommerce product categories in sidebar widget on click?

I wanted to implement a vertical menu of the product categories widget as an accordion, which, when you click on a specific category, opens subcategories. Tried plugins, but did not find a sensible solution. I came across one article , but I can not implement it. The menu structure and classes are identical.

<ul class="product-categories">
  <li><a>Для малышей</a></li>
  <li><a>Для мальчиков</a></li>
  <li><a>Для девочек</a></li>
  <li class="cat-parent"><a>Прочие игрушки</a>
    <ul class='children'>
      <li><a>Фигурки и персонажи</a></li>
      <li><a>Игры</a></li>
      <li><a>Конструкторы и головоломки</a></li>
      <li><a>Другие игрушки</a></li>
    </ul>
  </li>
  <li class="cat-parent"><a>Прочие товары</a>
    <ul class='children'>
    <li class="cat-item cat-item-19"><a>Мобили</a></li>
    </ul>
  </li>
</ul>

added js code
$(function() {
  $('.product-categories .cat-parent').children('a').click(function() {
    $(this).siblings('.children').slideToggle();
    return false;
  });
});

And CSS
ul.children{
  display: none;
}

But there is no result. The child categories are hidden, but when you click it, nothing happens. Please tell me what could be the reason. Or is there any alternative solution (without plugins)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question