Make script to show hidden woocommerce products

Viewed 23

I have many categories where if i go to backend of wordpress i can see the numbers are different for example.

enter image description here

If i open this category in browser i can see many products are missing.

https://www.pottershouselimited.co.uk/tumblers-water-bottles/

enter image description here

this product even its in stock but not showing at front end.

If i do some steps like.

  1. edit product and change product visibility to hidden.
  2. make it fetured.
  3. update it.
  4. then revert back to normal from fetured and revert back to visible. 5 hit update then it will show up.

I am want to make a php script to do that for 4000 product inventory.

Kindly suggest.

I tried that one. loop up all products

        $product_id = (int)$product->ID;        
        $product = wc_get_product($product_id);
        $previous_visibility = $product->get_catalog_visibility();
        $product->set_catalog_visibility('hidden');
        $product->set_featured(true);
        $product->save();
        $product->set_catalog_visibility('visible');
        $product->set_featured(false);
        $product->save();

I am trying the above script which is not working out.. kindly suggest me

0 Answers
Related