title: WC_Order does not return the product id by get_items()
body: <p>I have tried to get the product id and the product name by the following code: </p>
  
  <pre><code>if ( $query-&gt;have_posts() ) {
      $order_id = $query-&gt;posts[0]-&gt;ID;
      $order = new WC_Order( $order_id );
      $items = $order-&gt;get_items();
  }
  
      foreach ( $items as $item ) {
          $product_id = $item['product_id'];
          $product = wc_get_product( $item_id );
          $product_name = $item['name'];
      }
  </code></pre>
  
  <p>In the above code I got the product name, but the it is return 0 for $product_id. Is there any other method for this?</p>
  
  <p>I can't find any solution for this. </p>
  
  <p>My Edited Version:</p>
  
  <p>When I tried this: </p>
  
  <pre><code>$order_id = $query-&gt;posts[0]-&gt;ID;
  $order = new WC_Order( $order_id );
  $items = $order-&gt;get_items();
  
  foreach ( $items as $item ) {
      $item_id = $item['product_id'];
      $product_name = $item['name'];
      print_r( $item ); exit;
  }
  </code></pre>
  
  <p>I got this array:</p>
  
  <pre><code>WC_Order_Item_Product Object
  (
      [extra_data:protected] =&gt; Array
          (
              [product_id] =&gt; 0
              [variation_id] =&gt; 0
              [quantity] =&gt; 1
              [tax_class] =&gt; 
              [subtotal] =&gt; 0
              [subtotal_tax] =&gt; 0
              [total] =&gt; 0
              [total_tax] =&gt; 0
              [taxes] =&gt; Array
                  (
                      [subtotal] =&gt; Array
                          (
                          )
  
                      [total] =&gt; Array
                          (
                          )
  
                  )
  
          )
  
      [data:protected] =&gt; Array
          (
              [order_id] =&gt; 684
              [name] =&gt; Dark Skirt "Erebos" - Large, White
              [product_id] =&gt; 0
              [variation_id] =&gt; 0
              [quantity] =&gt; 1
              [tax_class] =&gt; 
              [subtotal] =&gt; 19
              [subtotal_tax] =&gt; 0
              [total] =&gt; 19
              [total_tax] =&gt; 0
              [taxes] =&gt; Array
                  (
                      [total] =&gt; Array
                          (
                          )
  
                      [subtotal] =&gt; Array
                          (
                          )
  
                  )
  
          )
  
      [cache_group:protected] =&gt; order-items
      [meta_type:protected] =&gt; order_item
      [object_type:protected] =&gt; order_item
      [id:protected] =&gt; 1
      [changes:protected] =&gt; Array
          (
          )
  
      [object_read:protected] =&gt; 1
      [default_data:protected] =&gt; Array
          (
              [order_id] =&gt; 0
              [name] =&gt; 
              [product_id] =&gt; 0
              [variation_id] =&gt; 0
              [quantity] =&gt; 1
              [tax_class] =&gt; 
              [subtotal] =&gt; 0
              [subtotal_tax] =&gt; 0
              [total] =&gt; 0
              [total_tax] =&gt; 0
              [taxes] =&gt; Array
                  (
                      [subtotal] =&gt; Array
                          (
                          )
  
                      [total] =&gt; Array
                          (
                          )
  
                  )
  
          )
  
      [data_store:protected] =&gt; WC_Data_Store Object
          (
              [instance:WC_Data_Store:private] =&gt; WC_Order_Item_Product_Data_Store Object
                  (
                      [internal_meta_keys:protected] =&gt; Array
                          (
                              [0] =&gt; _order_id
                              [1] =&gt; _name
                              [2] =&gt; _product_id
                              [3] =&gt; _variation_id
                              [4] =&gt; _quantity
                              [5] =&gt; _tax_class
                              [6] =&gt; _subtotal
                              [7] =&gt; _subtotal_tax
                              [8] =&gt; _total
                              [9] =&gt; _total_tax
                              [10] =&gt; _taxes
                              [11] =&gt; _product_id
                              [12] =&gt; _variation_id
                              [13] =&gt; _qty
                              [14] =&gt; _tax_class
                              [15] =&gt; _line_subtotal
                              [16] =&gt; _line_subtotal_tax
                              [17] =&gt; _line_total
                              [18] =&gt; _line_tax
                              [19] =&gt; _line_tax_data
                          )
  
                      [meta_type:protected] =&gt; order_item
                      [object_id_field_for_meta:protected] =&gt; order_item_id
                  )
  
              [stores:WC_Data_Store:private] =&gt; Array
                  (
                      [coupon] =&gt; WC_Coupon_Data_Store_CPT
                      [customer] =&gt; WC_Customer_Data_Store
                      [customer-download] =&gt; WC_Customer_Download_Data_Store
                      [customer-session] =&gt; WC_Customer_Data_Store_Session
                      [order] =&gt; WC_Order_Data_Store_CPT
                      [order-refund] =&gt; WC_Order_Refund_Data_Store_CPT
                      [order-item] =&gt; WC_Order_Item_Data_Store
                      [order-item-coupon] =&gt; WC_Order_Item_Coupon_Data_Store
                      [order-item-fee] =&gt; WC_Order_Item_Fee_Data_Store
                      [order-item-product] =&gt; WC_Order_Item_Product_Data_Store
                      [order-item-shipping] =&gt; WC_Order_Item_Shipping_Data_Store
                      [order-item-tax] =&gt; WC_Order_Item_Tax_Data_Store
                      [payment-token] =&gt; WC_Payment_Token_Data_Store
                      [product] =&gt; WC_Product_Data_Store_CPT
                      [product-grouped] =&gt; WC_Product_Grouped_Data_Store_CPT
                      [product-variable] =&gt; WC_Product_Variable_Data_Store_CPT
                      [product-variation] =&gt; WC_Product_Variation_Data_Store_CPT
                      [shipping-zone] =&gt; WC_Shipping_Zone_Data_Store
                  )
  
              [current_class_name:WC_Data_Store:private] =&gt; WC_Order_Item_Product_Data_Store
              [object_type:WC_Data_Store:private] =&gt; order-item-product
          )
  
      [meta_data:protected] =&gt; Array
          (
          )
  
  )
  </code></pre>
  
  <p>Of you see the [data:protected] array, you can see this where the [product_id] is 0. That is the problem I guess. But what is the solution for this?</p>