title: Get product weight from Wordpress
body: <p>The code below is used to get data on a products of the category "books" in my Wordpress website using Woocommerce.</p>
  
  <pre><code>&lt;?php
   $args = array( 'post_type' =&gt; 'product', 'posts_per_page' =&gt; 200, 'product_cat' =&gt; 'books');
         $loop = new WP_Query( $args );
  
  
      $send_array = array();
         while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); 
          global $product; 
  
      $send_array[] = array(
  
          'id' =&gt; get_the_ID(),
          'title' =&gt; get_the_title(),
          'content' =&gt; get_the_content(),
          'regular_price' =&gt; get_post_meta( get_the_ID(), '_regular_price', true),
          'sale_price'=&gt; get_post_meta( get_the_ID(), '_sale_price', true),
          'weight' =&gt; woocommerce_get_product_terms($product-&gt;id, 'weight', 'names')
  
      );
  
       endwhile; 
  
       wp_reset_query(); 
          ob_clean();
          echo json_encode($send_array);
          exit();
  
      ?&gt;
  </code></pre>
  
  <p>This works fine and returns the data correctly except for the <code>weight</code> attribute. </p>
  
  <p>This is a custom attribute set in my website using Woocommerce. In my database the weight attribute shows up in the <code>wp_woocommerce_attribute_taxonomies</code> table. This table has the fields <code>attribute_id</code>, <code>attribute_name</code>, <code>attribute_label</code> etc.</p>
  
  <p>The code I used above to get the <code>weight</code> value of the product doesn't work. </p>
  
  <p>I also tried <code>'weight' =&gt; get_post_meta( get_the_ID(), '_weight', true)</code>, but it shows up as an empty string (weight:"") even though that product has a Weight value on the website. </p>
  
  <p>How do I get the weight for each product and add it to the array to the key <code>weight</code> as I have attempted above.</p>
  
  <p>Have been doing some research and this seemed to be the item to work. What am I doing wrong?</p>
  
  <p>How do I fix this?</p>