• Hello,

    I am wondering if there is an easy way to delete all images attached to a custom post type (in this case woocommerce products) that are under a certain width?

    We migrated a site from Bigcommerce, and some of the images are under the image thumbnail threshold to be resized. So we just want to show the placeholder image until we can get around to generating good images for these.

    So not only would the images need to be deleted, we need them to be unassociated with the posts so that they aren’t just 404ing.

    Any ideas would be much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator t-p

    (@t-p)

    I recommend asking at https://www.ads-software.com/support/plugin/woocommerce so the plugin’s developers

    Moderator bcworkz

    (@bcworkz)

    If you did that, how would you know what and where to place replacement images? I think I would write a script or alter a template to simply add a class attribute to such img tags. The class style could be opacity 0 with a background set as the placeholder. Or simply style with display none. Then it’ll be easier to have another script replace the image files and remove the class later on.

    Regardless of what you decide to do, unless it can be managed by a plugin like Regenerate Thumbnails, it likely involves running a one time custom script. This is probably not what you would consider “easy”, but it may be your only alternative. To execute such a script, make it part of a custom page template. There are other ways to run a custom script, this is as good as any IMO. Include some mechanism to prevent the script from immediately running when someone just views the page. If there are a lot of products or attachments to sift through, the task should be executed in chunks and you should increase the default PHP execution time. Use post meta or taxonomy terms to keep track of which have been processed.

    The script itself would query n number of products or attachments that do not have the attribute indicating the object has been processed. Include any other criteria in the query that may be applicable. When no further objects are found, output a message to that effect. You can then essentially reload the same page to process another chunk. Continue until the nothing found message appears.

    Precisely how to query and process the objects depends on the exact nature of the images. If they are solely featured images, the process would be different than gallery images or images in descriptions. Whatever the nature, loop through the returned objects and make adjustments as necessary, including adding the indicator attribute after each successful change.

    If you need specifics of how to handle certain types of product images, it may be best to inquire in the dedicated forum as t-p suggests. If further questions are not specific to WooCommerce, you may continue asking here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Delete all images under a certain width?’ is closed to new replies.