I have around 5k products in my store and I wonder if there is a way via PhpMyAdmin or any other plugin you might know to set all my stock levels from variables products to 0 due to the fact I upload every day a new CSV.
Is it possible via PhpMyAdmin to reset the entire to 0 of every product and the stock status to ‘out of stock’ so I can import my new CSV and update only the products are in.
2
Answers
As your question is not very clear regarding the type of products that you want to alter. In the code below, the 2 SQL queries will (for all the products):
Always before, be sure to make a backup of the database.
The query to set the stock quantity to 0:
The query to set the stock status "Out of stock":
Tested, works.
I’m further elaborating on LoicTheAztec’s answer, adding the changes to
wp_term_relationships
.Step 1: Set Stock Quantity to 0.
Step 2: Set Stock Status to "Out of Stock".
Step 3: Update Term Relationships.
WooCommerce might use terms to manage stock status. To make sure the products are marked as ‘out of stock’ in terms as well, you can run:
The
INSERT IGNORE
in the third SQL statement is used to skip any duplicate entries. In the wp_term_relationships table, the combination of object_id and term_taxonomy_id is usually a primary key. If a product is already marked as ‘out of stock’ (i.e., it already has a relationship with the term ‘outofstock’), attempting to insert a duplicate entry for that product would result in a ‘Duplicate entry’ error.After running these queries your products should all be set to a stock qty of 0 and marked as ‘out of stock’. You can then import your new CSV to update only the products that are in stock or do it in the admin panel.