How to Automatically Delete images after updating product images using woocommerce rest API #220
Unanswered
Kennypurnomo
asked this question in
Q&A
Replies: 1 comment
-
Well a few things come to mind:
Make sure you have deleting turned on in Cloud Storage Settings.
If you have Queue Deletes turned on look at the task manager and make sure the delete task is running
I'd change your code to make sure that wp_delete_attachment() is not returning false or an error
Turn on media cloud debugging and see what the logs tell you.
The fact you have files on your server at all tells me that either 1 or 2 is true. If you have deleting enabled, than you shouldn't have any files on the server to begin with, let alone at this late of a stage.
… On Sep 7, 2023, at 11:20 AM, Kennypurnomo ***@***.***> wrote:
i tried using below code:
`function delete_old_images_when_product_image_updated($product_id, $data) {
// Check if the request includes new images
if (isset($data['images'])) {
// Get the current product attachments
$product_attachments = get_post_meta($product_id, '_product_image_gallery', true);
// Check if there are any old attachments
if (!empty($product_attachments)) {
// Get the current product gallery attachments
$product_gallery_attachments = explode(',', $product_attachments);
// Delete the old attachments
foreach ($product_gallery_attachments as $attachment_id) {
// Delete the old attachment
wp_delete_attachment($attachment_id, true);
}
}
}
}
// Hook into WooCommerce when a product is updated via API
add_action('woocommerce_api_edit_product', 'delete_old_images_when_product_image_updated', 10, 2);
`
But i failed, the images are still inside my wordpress media and even they are still attached!
Please help, i have dynamics images so i expect to update product images every 1 month
—
Reply to this email directly, view it on GitHub <#220>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAK3ILATDBJEG4AFZTZWHLXZFDQ7ANCNFSM6AAAAAA4OIXZ5I>.
You are receiving this because you are subscribed to this thread.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i tried using below code:
`function delete_old_images_when_product_image_updated($product_id, $data) {
// Check if the request includes new images
if (isset($data['images'])) {
// Get the current product attachments
$product_attachments = get_post_meta($product_id, '_product_image_gallery', true);
}
// Hook into WooCommerce when a product is updated via API
add_action('woocommerce_api_edit_product', 'delete_old_images_when_product_image_updated', 10, 2);
`
But i failed, the images are still inside my wordpress media and even they are still attached!
Please help, i have dynamics images so i expect to update product images every 1 month
Beta Was this translation helpful? Give feedback.
All reactions