title: Woocommerce Order cart array by cat and sub cat
body: <p>Hi we are trying to sort the Woo Cart by Main product category and list under the products in that category.  Like below:</p>
  
  <p>Wheel Parts</p>
  
  <ul>
  <li>spokes 12</li>
  <li>Tyre's</li>
  </ul>
  
  <p>Frame</p>
  
  <ul>
  <li>Y Frame</li>
  <li>X Frame</li>
  <li>Z Frame</li>
  </ul>
  
  <p>Seat</p>
  
  <ul>
  <li>Seat 1</li>
  <li>Seat 2</li>
  </ul>
  
  <p>We have managed to get to display by cat order but it is not ordering them into Main Cat -> Sub Cat</p>
  
  <p>We have the below code and trying to order cart array by cat and sub cat</p>
  
  <pre><code>add_action( 'woocommerce_cart_loaded_from_session', function() {
  
      global $woocommerce;
      $products_in_cart = array();
      foreach ( $woocommerce-&gt;cart-&gt;cart_contents as $key =&gt; $item ) {
          $terms = wp_get_post_terms($item['data']-&gt;id, 'product_cat' );
  
          $products_in_cart[ $key ] = $terms[0]-&gt;name;
      }
  
      natsort( $products_in_cart );
  
      $cart_contents = array();
      foreach ( $products_in_cart as $cart_key =&gt; $product_title ) {
          $cart_contents[ $cart_key ] = $woocommerce-&gt;cart-&gt;cart_contents[ $cart_key ];
  
      }
      $woocommerce-&gt;cart-&gt;cart_contents = $cart_contents;
  
  }, 100 );
  </code></pre>
  
  <p>Any one have any ideas please?</p>