Background: I inherited a website with a tremendously bloated product database. There are around 260 actual products which are translated using WPML into English and French which should make it for a total of 520 posts (for each product there is one same SKU two different IDs). However the total count of products in published status is over 720.
I exported all my products and realized that there is a third instance of some products with the same SKU and yet another ID but they are not associated to any category i.e The 'Categories' field is empty. These are not variants are just ghost instances of the parent products.
Problem to solve:
Difference in Product Count that shows invalid products
Thanks!
I've solved the problem by using the CLI shell in WordPress.
By simply SSHing into the backend I used the following syntax
wp wc product delete <ID>
for trashing the product and you can add the --force to permanently delete it.
Having the list of offender IDs I just simply wrote a shell script that executed all the commands sequentially.