Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce products showing “Out of stock” message when not actually out of stock

Having an issue with a client website where products are randomly displaying

"This product is currently out of stock and unavailable."

The thing is that we don't have inventory tracking turned on, all products should be in stock all the time.

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).

I need to find a way to fix this problem permanently so it doesn't revert itself.

Site Details:

  • Using WordPress 3.9.1
  • WooCommerce 2.1.12
  • PHP 5.3.10 (also tried locally w/ 5.5.10)

What I've tried

  • Removing all plugins but WooCommerce
  • Changing themes (tried all standard WordPress themes and a few WooThemes themes to no avail)
  • Updated WooCommerce (it was v 2.1.5)
  • Manually inserted to wp_postmeta adding the meta key _manage_stock and set it to no (as observed in some of the working products we have)
  • Manually inserted to wp_postmeta adding the meta key '_stock' and set it to 0 (as observed in some of the working products we have)
  • 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
  • No caching is turned on
  • Used XDebug to track the $available_variations variable in variable.php and class-wc-ajax.php and class-wc-product-variable.php.

When debugging I noticed that in products that were working the $available_variations 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 variable.php). Clicking the update button and then tracking the variable shows the information correctly.

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.

Has anyone else had issues with this? Any way around this issue so I don't have to keep updating products for this client.

Link to product that is out of stock (as of posting) http://highlandsministriesonline.org/product/basement-tapes/resentment-in-the-church-135/

Link to product that is displaying correctly http://highlandsministriesonline.org/product/basement-tapes/bt0111-church-at-corinth-i/

Error Log I added an error log to the product variation class. Heres the result:

For products with the "out of stock" message, nothing displays in the log.

An example of a product that function correctly:

WC_Product_Variation Object (     [variation_id] => 1310     [parent] => WC_Product_Variable Object         (             [children] => Array                 (                     [0] => 1311                     [1] => 1310                 )              [total_stock] =>              [id] => 1308             [post] => WP_Post Object                 (                     [ID] => 1308                     [post_author] => 1                     [post_date] => 2012-04-03 14:29:42                     [post_date_gmt] => 2012-04-03 18:29:42                     [post_content] => This audio presentation on homeschooling is a Basement Tape conversation on homeschooling. <h2>What are The Basement Tapes?</h2> <em>The Basement Tapes</em> 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.  <strong>Format: Available in both CD and MP3</strong>  <strong>Length: Sixty minutes</strong>                     [post_title] => Basement Tape #109: Homeschooling Redux                     [post_excerpt] => 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] => publish                     [comment_status] => open                     [ping_status] => closed                     [post_password] =>                      [post_name] => bt0109-homeschooling-reducks                     [to_ping] =>                      [pinged] =>                      [post_modified] => 2014-07-07 11:08:46                     [post_modified_gmt] => 2014-07-07 15:08:46                     [post_content_filtered] =>                      [post_parent] => 0                     [guid] => http://50.57.190.158/?post_type=product&#038;p=1308                     [menu_order] => 0                     [post_type] => product                     [post_mime_type] =>                      [comment_count] => 0                     [filter] => raw                 )              [product_type] => variable         )      [variation_data] => Array         (             [attribute_pa_audio-options] => mp3-download         )      [variation_has_length] =>      [variation_has_width] =>      [variation_has_height] =>      [variation_has_weight] =>      [variation_has_stock] =>      [variation_has_sku] => 1     [variation_shipping_class] =>      [variation_shipping_class_id] =>      [variation_has_tax_class] =>      [variation_has_downloadable_files] => 1     [id] => 1308     [post] => WP_Post Object         (             [ID] => 1308             [post_author] => 1             [post_date] => 2012-04-03 14:29:42             [post_date_gmt] => 2012-04-03 18:29:42             [post_content] => This audio presentation on homeschooling is a Basement Tape conversation on homeschooling. <h2>What are The Basement Tapes?</h2> <em>The Basement Tapes</em> 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.  <strong>Format: Available in both CD and MP3</strong>  <strong>Length: Sixty minutes</strong>             [post_title] => Basement Tape #109: Homeschooling Redux             [post_excerpt] => 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] => publish             [comment_status] => open             [ping_status] => closed             [post_password] =>              [post_name] => bt0109-homeschooling-reducks             [to_ping] =>              [pinged] =>              [post_modified] => 2014-07-07 11:08:46             [post_modified_gmt] => 2014-07-07 15:08:46             [post_content_filtered] =>              [post_parent] => 0             [guid] => http://50.57.190.158/?post_type=product&#038;p=1308             [menu_order] => 0             [post_type] => product             [post_mime_type] =>              [comment_count] => 0             [filter] => raw         )      [product_type] => variation     [product_custom_fields] => Array         (             [_sku] => Array                 (                     [0] => BT0109MP3                 )              [_price] => Array                 (                     [0] => 3                 )              [_sale_price] => Array                 (                     [0] =>                  )              [_weight] => Array                 (                     [0] =>                  )              [_length] => Array                 (                     [0] =>                  )              [_width] => Array                 (                     [0] =>                  )              [_height] => Array                 (                     [0] =>                  )              [_stock] => Array                 (                     [0] =>                  )              [_thumbnail_id] => Array                 (                     [0] => 0                 )              [_virtual] => Array                 (                     [0] => yes                 )              [_downloadable] => Array                 (                     [0] => yes                 )              [_download_limit] => Array                 (                     [0] =>                  )              [_downloadable_files] => Array                 (                     [0] => 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] => Array                 (                     [0] => 3                 )              [_sale_price_dates_from] => Array                 (                     [0] =>                  )              [_sale_price_dates_to] => Array                 (                     [0] =>                  )              [_download_expiry] => Array                 (                     [0] =>                  )              [attribute_pa_audio-options] => Array                 (                     [0] => mp3-download                 )          )      [sku] => BT0109MP3     [downloadable_files] => 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] => yes     [virtual] => yes     [sale_price_dates_from] =>      [sale_price_dates_to] =>      [price] => 3     [regular_price] => 3     [sale_price] =>      [total_stock] => 0     [dimensions] =>  ) 

Potential Next Steps 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.

Update as of October 23,2014

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.

like image 240
Ian Avatar asked Jul 08 '14 18:07

Ian


People also ask

Why does my WooCommerce product say out of stock?

One of the checks WooCommerce does is check to see if a product has a price, if it does not, it is set as not purchasable. This is why your products are showing as unavailable.

How do I get rid of out of stock text in WooCommerce?

To change the WooCommerce "Out of Stock" text, add the following PHP snippet: function my_woo_outofstock_text( $text ) { $text = __( 'MY CUSTOM TEXT', 'oceanwp' ); return $text; } add_filter( 'ocean_woo_outofstock_text', 'my_woo_outofstock_text', 20 ); Replace MY CUSTOM TEXT with the text you want to display.

How do you remove this product is currently out of stock and unavailable from WooCommerce?

Step 1: Navigate to Product > Variations. Step 2: Click on the dropdown box that says Add Variation by default. Then click Go. Step 3: Click the blue Expand text and make sure to enter in Regular Price for each variation.

Why does WooCommerce not display out of stock products?

Go to WooCommerce -> Settings and navigate to the Products tab. Select Inventory. Check the 'Out Of Stock Visibility' option to hide out of stock items from your catalog.


2 Answers

I had this same problem and I think I figured it out. I used the CSV Import/Export suite to export all of my variations. You'll notice that stock is set to 0 when it should have a value of null.

You have two options here:

  1. Go into each individual product, click the variations tab and expand each variation - unchecking the "manage stock" checkbox:enter image description here
  2. You can do a find-and-replace on the database substituting the 0 value for null.
like image 81
Zach Russell Avatar answered Sep 20 '22 01:09

Zach Russell


I was getting this same issue with a product I had newly created. But for me the answer was more simple.

I needed to enter in a “Regular Price” for every variation.
https://wordpress.org/support/topic/this-product-is-currently-out-of-stock-and-unavailable-4/

I had created my attributes previously.

Under Variations, for my product, I had to make sure “Add variation” was selected. Then I clicked the “Go” button.

I needed to create a variation for each of the different choices the attribute could have.

So for my Color Options I had to make three different variations (one for each choice).
Then I needed to click the blue “Expand” text, and make sure each variation had a Regular price.

Then it worked. enter image description here

(This was helpful too: https://docs.woocommerce.com/document/variable-product/ )

like image 33
Joe Avatar answered Sep 22 '22 01:09

Joe