I'm trying to remove product image (one at a time) using WooCommerce API but I'm facing a strange problem.

I can remove all associated image at once by sending an empty array in images: { images:[] }

But I can't find a way to remove one image at a time.

  • Do you want to delete the images, or just remove them from the product? Sending an empty array probably only does the latter. Regardless, WooCommerce images are WordPress attachments, so you could delete them using the media endpoint, if you have their ID: developer.wordpress.org/rest-api/reference/media Jun 16 '19 at 10:27
  • I want to remove image from a product. Now, sending empty array removes all images, but I want to remove one specific image from the product while keeping others as they were. I have figured out one hack: Let's assume I want to delete this image: "id":123. I sent all other images in an array in the following manner: { "images": [ { "id": 209101 }, { "id": 209102 }, { "id": 209103 } ] } This is updating the array and removing the image "id":123, while keeping other images as they were. But I am looking for a cleaner solution. :)
    – Qumber
    Jun 17 '19 at 11:29
  • 1
    That’s not a hack. That seems like a perfectly reasonable approach. Jun 17 '19 at 11:32
  • Is there not a way where I can simply remove the image by calling it using its id or something rather than the other way around? Thanks, by the way. 😊
    – Qumber
    Jun 17 '19 at 11:57

The image array you are sending includes all images you want attached to the product. If you want to remove one image, you need to send all original image id's minus the one you want to remove,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.