title: Get category id by product in WooCommerce
body: <p>What I want to do is make a foreach loop to get all products and from those products I want to get their category id. This so I can later check for certain categories.</p>
  
  <pre><code>$order = new WC_Order( $order_id );
  $items = $order-&gt;get_items();
  
  foreach ( $items as $item ) {
      $product_catagory_id .= $item['catagory_id']; //in between these brackets I need a value that gives me the catagory id.
  }
  
  //Some validation here if one of the catagorie_id's was found.
  //I can build this. It's not part of the question
  </code></pre>
  
  <p>After some comments, this is where I'm stranded:</p>
  
  <pre><code>$order = new WC_Order( $order_id );
  $items = $order-&gt;get_items();
  foreach ( $items as $item ) {
      $product_id = $item['product_id'];
      var_dump($product_id);
      $terms = get_the_term_list( $product_id, 'term_id' );
      var_dump($terms);
  }
  </code></pre>
  
  <p>This results in the following:</p>
  
  <pre><code>string(2) "79"
  object(WP_Error)#9148 (2) {
      ["errors"]=&gt;
          array(1) {
          ["invalid_taxonomy"]=&gt;
              array(1) {
                  [0]=&gt;
                  string(19) "Ongeldige taxonomie" //invalid taxonomy
              }
          }
      ["error_data"]=&gt;
      array(0) {
      }
  }
  </code></pre>
  
  <p>So the product ID is read perfectly, I can work with that but the category isn't returned properly.</p>