I have many categories where if i go to backend of wordpress i can see the numbers are different for example.
If i open this category in browser i can see many products are missing.
https://www.pottershouselimited.co.uk/tumblers-water-bottles/
this product even its in stock but not showing at front end.
If i do some steps like.
- edit product and change product visibility to hidden.
- make it fetured.
- update it.
- 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

