I was trying the following:
when a product page gets deleted (permanently), it should also delete the:
product gallery and product image which are attached to the post.
I tried the solution i found on:
https://wordpress.stackexchange.com/questions/109793/delete-associated-media-upon-page-deletion
But it didn’t work out for me.
Although this is an old question, I will leave it here in case someone will be looking for it in the future.
Since you want to delete product images, you may try these neat and handy woocommerce functions to get attachments ids.
Something like this:
Works fine for me.
you can try the following:
This will delete images when product is permanently deleted.
Step 1: Login to Your PhpMyAdmin | If you have more than one database, make sure you click on the correct database. If youâre not sure because you have more than one WordPress installation on the same domain, open a table and look for âwp_optionsâ, youâll be able to see the URL of the website youâre making changes to.
Step 2: Run the SQL Statement ==> in WP_POST
If you are on the correct database, click on the SQL tab on the top right. It might be empty or have an SQL statement there from a previous command.
i used this code and it works. But I’m trying to add more code to create a function that when I delete a product definitively, this in addition to being deleted from the wordpress “media” folder, is deleted from another folder in my ftp, where the same images are present with the same names. so I simply need to know the name of the file, delete it from the “media” folder and then delete it from another folder where there is a copy of that file. How can I do?
}
}