Home > other >  Make all products in woocommerce as "Out Of Stock" ( Remove all products quantity )
Make all products in woocommerce as "Out Of Stock" ( Remove all products quantity )

Time:11-04

I have a woocommerce store and I want to make all the products ( including variable products ) quantity to 0. So, all the products will be out of stock. I am not getting any plugin to do it. I have atleast 2100 products in the inventory. So, it is not feasible to do it manually. Is there any other way I can do this automatically ?

Thanks.

CodePudding user response:

Install PhpMyAdmin plugin and directly edit the quantities in the relevant database table.

CodePudding user response:

You can paste this code in your functions.php in your child theme.

$products = $wpdb->get_results("SELECT * FROM `".$wpdb->postmeta."`");
foreach($products as $product){
    if(get_post_type($product->post_id) == "product"){
        $product_id = $product->post_id;
        wc_update_product_stock($product_id, 0, 'set');
    }
}
  • Related