I use online store on WooCommerce, there are a lot of products (20.000+). I would like to remove goods that are not available from the showcase, but they are displayed in the number of "0", however, unfortunately, I just can not figure out how to implement it.
It is worth the function "Manage remnants".
Naryl is such a code:
<?php /** * set the stock status for all products in your WooCommerce store * return void */ function woocommerce_update_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 ); } What to do with it and what is it for?