Here is a solution but this is not considered a bug by the WooCommerce team as it works as they think is ok.
Diagnosis of the problem
The problem occurs when the actions below happen in this exact order:
- A simple product is created
- The product has "manage stock" option enabled
- The product has a stock quantity greater than 0
- The product is later changed to variable product
- The variable product has separate stock value for each variant
- Option "manage stock at product level" is still enabled when people purchase products
Why the problem occurs
Let's start from the begining.
Technically, when product options in the product's edit page are changed, some fields in the product settings get hidden and other show up. The important thing to remember is that hiding a field doesn't mean that the data is removed from the database (in most cases) and so some functions that use this data still work.
Now, when a single product doesn't have the manage stock option enabled, a store manager can set "stock status" to "in stock", "out of stock" or "available on backorder". Now, when the manager enables "manage stock", the field with stock status gets hidden, but it doesn't stop holding a value and the connected functions don't stop working.
In other words when a single product has the "manage stock at product level" enabled and someone purchases a product, than 1 is removed from stock quantity field and when this number reaches 0 the invisible field "stock status" is set up to "Out of Stock".
But it doesn't cause a problem because when the manager increases the stock quantity, the "Out of stock" is changed back to "in stock".
The problem is that it doesnt happen with variable products. But I will get to it later.
So far we have our single product and everything works. When we try turning on and off "manage stock" option, we toggle the visibility of the "Stock status" field.
The problem starts when the product is changed to variable.
In this case toggling the section "manage stock" (in the inventory tab) doesn't show the "stock status" field. If it did then diagnosing the problem would be so much easier, because this particular field holds the stock status that is displayed in category pages in store!
How do I know?
Because fortunately, there is a way to view what value this field holds - in the "quick edit" panel of the product list.
If you uncheck there "manage stock" than you will see the stock status. And this is exactly the same statusthat is shown in category pages and in "all products" list in the admin panel.
And this value is the problem (and the fact that it cannot be manually updated - try it if you like)
How to check if the problem will happen to you in the future and prevent it from happening
The quickest way to check if a problem will happen to you is to look at the "Stock status" column in "All products" admin page.
When next to a variable product you see stock status and stock quantity, than there is a big chance that this product will have problems in the future. If you find one like that, edit the product and see if it manages stock at product level or variable level. If in both of them, than disable the product level stock management and update the product. You should be safe now.
How to remove the "out of stock" label from variable products that are in stock
First of all I will tell you what doesn't work.
If you try to manually change the "stock status" in quick edit panel, you will fail. It won't update.
You have to:
- Duplicate the product you are having problems with. Please notice that the clone will have a proper stock status!
- Copy the URL of the original product
- Remove the original product
- Uncheck in the cloned copy "manage stock at product level"
- Remove the "-copy" suffix from the URL and from the title of the clone
- Publish the cloned product
If you did everything correctly, the new product should have exactly the same URL as the previous one and should give you no trouble in the future.
This solution involves deleting and recreating variable products so it is only useful when you don't have many and/or when the ID of the product needs to remain the same.
- Change product type to "simple"
- Switch off "manage product options at product level" (in the Inventory tab)
- Update product
- Change product type back to "variable"
- Recreate the variable products