title: WooCommerce products showing “Out of stock” message when not actually out of stock
body: <p>Having an issue with a client website where products are randomly displaying </p>
  
  <blockquote>
    <p>"This product is currently out of stock and unavailable."</p>
  </blockquote>
  
  <p><strong>The thing is that we don't have inventory tracking turned on, all products should be in stock all the time.</strong></p>
  
  <p>When I go into the WordPress admin and click the update button for the product (without changing anything) and then the message goes away and the "Add to Cart" button displays as it should. Unfortunately, the issue repeats itself on these items in the future and to fix it I have to update the product again (also clicking update in the WooCommerce settings temporarily solves the problem).</p>
  
  <p>I need to find a way to fix this problem permanently so it doesn't revert itself.</p>
  
  <p><strong>Site Details:</strong> </p>
  
  <ul>
  <li>Using WordPress 3.9.1</li>
  <li>WooCommerce 2.1.12</li>
  <li>PHP 5.3.10 (also tried locally w/ 5.5.10)</li>
  </ul>
  
  <p><strong>What I've tried</strong></p>
  
  <ul>
  <li>Removing all plugins but WooCommerce</li>
  <li>Changing themes (tried all standard WordPress themes and a few WooThemes themes to no avail)</li>
  <li>Updated WooCommerce (it was v 2.1.5)</li>
  <li>Manually inserted to wp_postmeta adding the meta key <code>_manage_stock</code> and set it to <code>no</code> (as observed in some of the working products we have)</li>
  <li>Manually inserted to wp_postmeta adding the meta key '_stock' and set it to <code>0</code> (as observed in some of the working products we have)</li>
  <li>Compared the postmeta of the product before and after clicking the update button to observe if anything had changed that would cause the problem...nothing</li>
  <li>No caching is turned on</li>
  <li>Used XDebug to track the <code>$available_variations</code> variable in <code>variable.php</code> and 
  <code>class-wc-ajax.php</code> and <code>class-wc-product-variable.php</code>.</li>
  </ul>
  
  <p>When debugging I noticed that in products that were working the <code>$available_variations</code> variable contained 2 arrays filled with product information, however on the products that didn't, it was an empty array (which results in the out of stock message being displayed as served by <code>variable.php</code>). Clicking the update button and then tracking the variable shows the information correctly.</p>
  
  <p>Honestly at this point I'm at a loss. I think the issue is somewhere in either of the classes, but I can't tell.</p>
  
  <p>Has anyone else had issues with this? Any way around this issue so I don't have to keep updating products for this client.</p>
  
  <p>Link to product that is out of stock (as of posting) <a href="http://highlandsministriesonline.org/product/basement-tapes/resentment-in-the-church-135/" rel="noreferrer">http://highlandsministriesonline.org/product/basement-tapes/resentment-in-the-church-135/</a></p>
  
  <p>Link to product that is displaying correctly <a href="http://highlandsministriesonline.org/product/basement-tapes/bt0111-church-at-corinth-i/" rel="noreferrer">http://highlandsministriesonline.org/product/basement-tapes/bt0111-church-at-corinth-i/</a></p>
  
  <p><strong>Error Log</strong>
  I added an error log to the product variation class. Heres the result:</p>
  
  <p>For products with the "out of stock" message, nothing displays in the log.</p>
  
  <p>An example of a product that function correctly:</p>
  
  <pre><code>WC_Product_Variation Object
  (
      [variation_id] =&gt; 1310
      [parent] =&gt; WC_Product_Variable Object
          (
              [children] =&gt; Array
                  (
                      [0] =&gt; 1311
                      [1] =&gt; 1310
                  )
  
              [total_stock] =&gt; 
              [id] =&gt; 1308
              [post] =&gt; WP_Post Object
                  (
                      [ID] =&gt; 1308
                      [post_author] =&gt; 1
                      [post_date] =&gt; 2012-04-03 14:29:42
                      [post_date_gmt] =&gt; 2012-04-03 18:29:42
                      [post_content] =&gt; This audio presentation on homeschooling is a Basement Tape conversation on homeschooling.
  &lt;h2&gt;What are The Basement Tapes?&lt;/h2&gt;
  &lt;em&gt;The Basement Tapes&lt;/em&gt; are conversations between Dr. R.C. Sproul Jr., Rev. Laurence Windham, their friends and special guests, on subjects related to the “good life,” a simple, separate, and deliberate life, lived out for the glory of God and for the building of His Kingdom.
  
  You might even say that the Basement Tapes serve to help us develop a Christian worldview. Started in 2002, we now have over #140 conversations on all areas of life that we are seeking to think biblically about so that we might take dominion over them for the King and His kingdom.
  
  &lt;strong&gt;Format: Available in both CD and MP3&lt;/strong&gt;
  
  &lt;strong&gt;Length: Sixty minutes&lt;/strong&gt;
                      [post_title] =&gt; Basement Tape #109: Homeschooling Redux
                      [post_excerpt] =&gt; It's been 108 weeks since we last talked about the subject of homeschooling our children. Our tykes have grown into teenagers. What have we learned in the past nine years? What has changed? What remains the same is that homeschooling means discipleship; passing down your most important convictions to your children and teaching them our holy religion.
                      [post_status] =&gt; publish
                      [comment_status] =&gt; open
                      [ping_status] =&gt; closed
                      [post_password] =&gt; 
                      [post_name] =&gt; bt0109-homeschooling-reducks
                      [to_ping] =&gt; 
                      [pinged] =&gt; 
                      [post_modified] =&gt; 2014-07-07 11:08:46
                      [post_modified_gmt] =&gt; 2014-07-07 15:08:46
                      [post_content_filtered] =&gt; 
                      [post_parent] =&gt; 0
                      [guid] =&gt; http://50.57.190.158/?post_type=product&amp;#038;p=1308
                      [menu_order] =&gt; 0
                      [post_type] =&gt; product
                      [post_mime_type] =&gt; 
                      [comment_count] =&gt; 0
                      [filter] =&gt; raw
                  )
  
              [product_type] =&gt; variable
          )
  
      [variation_data] =&gt; Array
          (
              [attribute_pa_audio-options] =&gt; mp3-download
          )
  
      [variation_has_length] =&gt; 
      [variation_has_width] =&gt; 
      [variation_has_height] =&gt; 
      [variation_has_weight] =&gt; 
      [variation_has_stock] =&gt; 
      [variation_has_sku] =&gt; 1
      [variation_shipping_class] =&gt; 
      [variation_shipping_class_id] =&gt; 
      [variation_has_tax_class] =&gt; 
      [variation_has_downloadable_files] =&gt; 1
      [id] =&gt; 1308
      [post] =&gt; WP_Post Object
          (
              [ID] =&gt; 1308
              [post_author] =&gt; 1
              [post_date] =&gt; 2012-04-03 14:29:42
              [post_date_gmt] =&gt; 2012-04-03 18:29:42
              [post_content] =&gt; This audio presentation on homeschooling is a Basement Tape conversation on homeschooling.
  &lt;h2&gt;What are The Basement Tapes?&lt;/h2&gt;
  &lt;em&gt;The Basement Tapes&lt;/em&gt; are conversations between Dr. R.C. Sproul Jr., Rev. Laurence Windham, their friends and special guests, on subjects related to the “good life,” a simple, separate, and deliberate life, lived out for the glory of God and for the building of His Kingdom.
  
  You might even say that the Basement Tapes serve to help us develop a Christian worldview. Started in 2002, we now have over #140 conversations on all areas of life that we are seeking to think biblically about so that we might take dominion over them for the King and His kingdom.
  
  &lt;strong&gt;Format: Available in both CD and MP3&lt;/strong&gt;
  
  &lt;strong&gt;Length: Sixty minutes&lt;/strong&gt;
              [post_title] =&gt; Basement Tape #109: Homeschooling Redux
              [post_excerpt] =&gt; It's been 108 weeks since we last talked about the subject of homeschooling our children. Our tykes have grown into teenagers. What have we learned in the past nine years? What has changed? What remains the same is that homeschooling means discipleship; passing down your most important convictions to your children and teaching them our holy religion.
              [post_status] =&gt; publish
              [comment_status] =&gt; open
              [ping_status] =&gt; closed
              [post_password] =&gt; 
              [post_name] =&gt; bt0109-homeschooling-reducks
              [to_ping] =&gt; 
              [pinged] =&gt; 
              [post_modified] =&gt; 2014-07-07 11:08:46
              [post_modified_gmt] =&gt; 2014-07-07 15:08:46
              [post_content_filtered] =&gt; 
              [post_parent] =&gt; 0
              [guid] =&gt; http://50.57.190.158/?post_type=product&amp;#038;p=1308
              [menu_order] =&gt; 0
              [post_type] =&gt; product
              [post_mime_type] =&gt; 
              [comment_count] =&gt; 0
              [filter] =&gt; raw
          )
  
      [product_type] =&gt; variation
      [product_custom_fields] =&gt; Array
          (
              [_sku] =&gt; Array
                  (
                      [0] =&gt; BT0109MP3
                  )
  
              [_price] =&gt; Array
                  (
                      [0] =&gt; 3
                  )
  
              [_sale_price] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_weight] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_length] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_width] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_height] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_stock] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_thumbnail_id] =&gt; Array
                  (
                      [0] =&gt; 0
                  )
  
              [_virtual] =&gt; Array
                  (
                      [0] =&gt; yes
                  )
  
              [_downloadable] =&gt; Array
                  (
                      [0] =&gt; yes
                  )
  
              [_download_limit] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_downloadable_files] =&gt; Array
                  (
                      [0] =&gt; a:1:{s:32:"a0a87d43e69ed9de646ba479c252c9fb";a:2:{s:4:"name";s:29:"109-Homeschooling-Reducks.mp3";s:4:"file";s:113:"http://highlandsministriesonline.org/wp-content/uploads/woocommerce_uploads/2012/04/109-Homeschooling-Reducks.mp3";}}
                  )
  
              [_regular_price] =&gt; Array
                  (
                      [0] =&gt; 3
                  )
  
              [_sale_price_dates_from] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_sale_price_dates_to] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [_download_expiry] =&gt; Array
                  (
                      [0] =&gt; 
                  )
  
              [attribute_pa_audio-options] =&gt; Array
                  (
                      [0] =&gt; mp3-download
                  )
  
          )
  
      [sku] =&gt; BT0109MP3
      [downloadable_files] =&gt; a:1:{s:32:"a0a87d43e69ed9de646ba479c252c9fb";a:2:{s:4:"name";s:29:"109-Homeschooling-Reducks.mp3";s:4:"file";s:113:"http://highlandsministriesonline.org/wp-content/uploads/woocommerce_uploads/2012/04/109-Homeschooling-Reducks.mp3";}}
      [downloadable] =&gt; yes
      [virtual] =&gt; yes
      [sale_price_dates_from] =&gt; 
      [sale_price_dates_to] =&gt; 
      [price] =&gt; 3
      [regular_price] =&gt; 3
      [sale_price] =&gt; 
      [total_stock] =&gt; 0
      [dimensions] =&gt; 
  )
  </code></pre>
  
  <p><strong>Potential Next Steps</strong> My next thought if I cant get this resolved is to write a script that will go through and update each product on the website on a nightly basis (since the temporary fix seems to work for at least 24 ours). Though if I can save some of my time I'd rather not if someone else has been able to solve this issue permanently.</p>
  
  <p><strong>Update as of October 23,2014</strong></p>
  
  <p>This issue is still occurring despite attempting the answers below. I have created a logging plugin to hopefully help track the frequency of the out of stock messages and hopefully help correlate the message with any actions taken place on the website. It's currently customized to this specific website, but I'm working on a version to share with you all so that even if I can't find the answer, someone can.</p>