Instead of tediously browsing through all your products, run a fast script to list any product that doesn't have any categories assigned.
On the Advanced WooCommerce Facebook group, Dimitris asked how to show which WooCommerce products do not have any categories assigned to them. He has 7000 products so browsing through the products in the admin area would be very inefficient.
I suggested a standalone script to examine each product. Then I had some free time so I wrote the script.
A little research
I rarely work with taxonomies so I didn’t know how to get a product’s categories. I remembered reading on BusinessBloomer.com about checking for a category in the cart. I quickly found the relevant post and noted the ‘product_cat‘ taxonomy name and the has_term() function. The ‘Related‘ section of that page led me to wp_get_post_terms() to retrieve the terms/categories of a single post.
I did a two quick experiments, hard coding the ID of two products, and got the results I expected. Then it was a simple WP_Query loop to examine each product and display those products without any categories.
Although it isn’t very important for a standalone script that is not executed regularly, I decided to make the query as fast as possible by only requesting the IDs. The query results are retrieved in one line instead of the usual loop.
There isn’t much beyond the query and loop – it’s primarily code to do a security check (to limit who can run the script) and html tags to make a simple html page. The results are links to edit the products to make it very easy to fix them and assign categories.