Great question — answering as the UphillTech team:
The SQL queries you've suggested are generally correct for setting the product visibility to "Hidden" by manipulating the wp_term_relationships and wp_term_taxonomy tables. Here's a refined version of your queries: exclude-from-search: INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) SELECT ID, (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE taxonomy = 'product_visibility' AND term_id = (SELECT term_id FROM wp_terms WHERE slug = 'exclude-from-search')) FROM wp_posts WHERE post_type = 'product' AND post_status = 'publish'; **exclude-from-catalog:** **INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) SELECT ID, (SELECT term_taxonomy_id FROM wp_term_taxonomy...
Full answer by Rafael Minuesa: https://stackoverflow.stackexchange.com/a/78408778 (CC BY-SA 4.0).
Need it done for your business? UphillTech.