Clean Up Product Images for WooCommerce
Automatically delete a product's attached images when the product is deleted in WooCommerce.
by Gorilla DevOps · github.com/wpspeedexpert/clean-up-product-images-for-woocommerce
★ 1stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/wpspeedexpert/clean-up-product-images-for-woocommerce/archive/refs/heads/main.zipDeclares an update source (https://github.com/WPSpeedExpert/clean-up-product-images-for-woocommerce), so updates arrive through the plugin's own updater.
From the readme
Clean Up Product Images for WooCommerce
Automatically delete a product's attached images when the product is deleted in WooCommerce — while never removing an image that is still used by another product or post.
✅ Features
- Deletes images attached to a WooCommerce product when that product is permanently deleted.
- Shared-image safe: before deleting any image, it checks whether the image is still referenced elsewhere — as a featured image (thumbnailid), in a product gallery (productimagegallery), or embedded in another post's content — and skips it if so.
- Runs automatically on the beforedeletepost hook. No configuration required.
- Lightweight — uses native WordPress / WooCommerce functions only.
- Protects both manual product deletions and automated cleanups (e.g. Delete Old Out-of-Stock Products), since both trigger the same hook.
🧠 Why shared-image safety matters
Stores often reuse one image across many products — open-box / condition-variant listings, or distributor-synced catalogues. Deleting a shared image would strip the cover image from every product using it, because WordPress removes the thumbnailid reference from all posts when an attachment is deleted. This plugin