Attach Woo Media to Product (AWMP) goes through all WooCommerce products with featured images and/or gallery images and if they are unattached, attaches them to their parent product. The parent product is determined as the product in which they are found listed as featured or gallery image*.
AWMP would be helpful if you or your client has been uploading media to the global Wordpress media library instead of individual product media libraries, and needs media sorted and organized retrospectively. AWMP was initially built to help a client who complained that Wordpress didn’t seem to have a file folder system for each post or product. Upon looking closer, I discovered that he was not uploading his images to his product media “folders,” but instead to the overall Wordpress media folder. None of his attachments were attached, so nothing showed when he used the “Uploaded to this product” filter. There aren’t really folders in Wordpress, per se, but having your images attached to your posts can help keep things organized if you’ve got a large site. Quick image edits can be made without hunting through the media catalog for your image. Obviously, on a smaller site, one could just visit the media library and attach any unattached files to products. However, AWMP is very helpful to run on sites with many products and images.
This plugin could be modified to run on regular Wordpress posts, or custom post types such as events or portfolio items. As it is, it only processes the WooCommerce product custom post type. It skips images which are already attached to a product. AWMP will also attach variable product images to the parent product so those can be seen in the list of attached media as well.
*Take note: if one image (uploaded once) is used for multiple products, it will end up attached to only one. You would need to upload/attach it to each product in which it should appear if you wish it to show as “uploaded to this product,” and then you would have duplicate images in your Media Library (which isn’t necessarily a bad thing unless you’re using the repeating image a lot).
As always suggested when making sweeping changes to your Wordpress database, make backups first!