1

The stock statuses from my woocommerce installation were uploaded by another plugin (square) and so all goods are in stock even if they have quantity 0. Is there a way to get the statuses to reset somehow, so that products with 0 stock, have the stock status "out of stock".

I have looked for this and found the following function

function jolie_theme_child_reset_stock_status(){
global $wpdb;
// set all status for products with 0 or less stocked quantity
$sql = "UPDATE $wpdb->postmeta stock, (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_stock' AND meta_value < 1 ) id SET stock.meta_value = 'outofstock' WHERE stock.post_id = id.post_id AND stock.meta_key = '_stock_status';";
// set all status for products with stock.
$sql .= "UPDATE $wpdb->postmeta stock, (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_stock' AND meta_value > 0 ) id SET stock.meta_value = 'outofstock' WHERE stock.post_id = id.post_id AND stock.meta_key = '_stock_status';";
// run queries
$wpdb->query( $sql );
}

But if I run this it causes a server 500 error. What is a simple way to reset the stock statuses with or without using the above code?

2 Answers 2

1

You can add the following sql command in your database using PHP my admin or anyother DB editor

Update wp_postmeta Set meta_value = 'instock' Where meta_value = 'outofstock' And meta_key = '_stock_status'
-1

Use below query for update Woo-commerce product status change manually.

Query:- Update wp_postmeta Set meta_value = 'instock' Where meta_value = 'outofstock' And meta_key = '_stock_status'

Note:- First check your table name before run this query. If your table name prefix not default then change it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.