title: WooCommerce subcategories(categories of categories) - A tale of php, stupidly limited functions and frustration
body: <p>The title should give you a pretty good idea about my misadventures. I am working on a project that's made in wordpress and uses WooCommerce, and after a lot of brainstorming and thought about possible compromise, i have reached the point where i am pretty much certain i have to get into the php code to solve the problem conveniently.</p>
  
  <p>The problem is that i have the following website:</p>
  
  <p><img src="https://i.stack.imgur.com/kapfE.jpg" alt="enter image description here"></p>
  
  <p>As you may have noticed, there is a mash of all the product categories, and what i need to do is split them into 2 main categories: food and drink. I turned what woocommerce can do by its built in functions and i just can't get it to work so i figured i'd have to write my own function. Now if any of you knows that i can actually do it with what i have i'd be happy if somebody told me. If not what i need is to create a function which can actually select all the categories belonging to a parent category or something the likes.</p>
  
  <pre><code>public function product_categories( $atts ) {
          global $woocommerce_loop;
  
          extract( shortcode_atts( array (
              'number'     =&gt; null,
              'orderby'    =&gt; 'name',
              'order'      =&gt; 'ASC',
              'columns'    =&gt; '4',
              'hide_empty' =&gt; 1,
              'parent'     =&gt; ''
              ), $atts ) );
  
          if ( isset( $atts[ 'ids' ] ) ) {
              $ids = explode( ',', $atts[ 'ids' ] );
              $ids = array_map( 'trim', $ids );
          } else {
              $ids = array();
          }
  
          $hide_empty = ( $hide_empty == true || $hide_empty == 1 ) ? 1 : 0;
  
          // get terms and workaround WP bug with parents/pad counts
          $args = array(
              'orderby'    =&gt; $orderby,
              'order'      =&gt; $order,
              'hide_empty' =&gt; $hide_empty,
              'include'    =&gt; $ids,
              'pad_counts' =&gt; true,
              'child_of'   =&gt; $parent
          );
  
          $product_categories = get_terms( 'product_cat', $args );
  
          if ( $parent !== "" )
              $product_categories = wp_list_filter( $product_categories, array( 'parent' =&gt; $parent ) );
  
          if ( $number )
              $product_categories = array_slice( $product_categories, 0, $number );
  
          $woocommerce_loop['columns'] = $columns;
  
          ob_start();
  
          // Reset loop/columns globals when starting a new loop
          $woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
  
          if ( $product_categories ) {
  
              woocommerce_product_loop_start();
  
              foreach ( $product_categories as $category ) {
  
                  woocommerce_get_template( 'content-product_cat.php', array(
                      'category' =&gt; $category
                  ) );
  
              }
  
              woocommerce_product_loop_end();
  
          }
  
          woocommerce_reset_loop();
  
          return '&lt;div class="woocommerce"&gt;' . ob_get_clean() . '&lt;/div&gt;';
      }
  </code></pre>
  
  <p>This i identified as the menacing WooCommerce function that does not behave. Help. Please help me :(</p>