• I have code who displays woocommerce categories (category name + link) by parent category. But it only displays on woocomerce category (inside category), when i click on subcategory its dissapeears. I need to display and inside of subcategories

    Here is the screenshots for more understanding what i need:

    Category: https://i64.tinypic.com/2rwtkll.png
    Subcategory: https://i63.tinypic.com/24q97au.png

    My code:

    <?php
      function tutsplus_product_subcategories($args = array())
      {
          $parentid = get_queried_object_id();
          $args     = array(
              'parent' => $parentid
          );
          $terms    = get_terms('product_cat', $args);
          if ($terms) {
              echo '<ul class="gallery-list">';
              foreach ($terms as $term) {
                  echo '<li class="product-category">';
                  echo '<h2>';
                  echo '<a href="' . esc_url(get_term_link($term)) . '" class="' . $term->slug . '">';
                  echo $term->name;
                  echo '</a>';
                  echo '</h2>';
                  echo '</li>';
              }
              echo '</ul>';
          }
      }
      add_action('woocommerce_before_shop_loop', 'tutsplus_product_subcategories', 50);
      function tutsplus_product_cats_css()
      {
          /* register the stylesheet */
          wp_register_style('tutsplus_product_cats_css', plugins_url('style.css', __FILE__));
          /* enqueue the stylsheet */
          wp_enqueue_style('tutsplus_product_cats_css');
      }
      add_action('wp_enqueue_scripts', 'tutsplus_product_cats_css');
    ?>
Viewing 1 replies (of 1 total)
  • Sorry, this forum is for WordPress support, if you copied some code that you do not understand from TutsPlus, ask your question in the comments section of that page. If you have questions regarding WooCommerce, they have a HUGE support site.

Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce “get_terms” – how to get subcategories?’ is closed to new replies.