In this video I’m going to show you how to correctly remove Woocommerce from WordPress in a way that it will not leave any mess behind. It means that all the product images will be removed along with it.
So, first I would suggest you to take a look at the video here below, and then you know exactly what to do.
Video: How to Correctly Remove Woocommerce from WordPress?
Code snippet for option 1
define( 'WC_REMOVE_ALL_DATA', true );
Code snippet for option 3
// Automatically Delete Woocommerce Images After Deleting a Product
add_action( 'before_delete_post', 'delete_product_images', 10, 1 );
function delete_product_images( $post_id )
{
$product = wc_get_product( $post_id );
if ( !$product ) {
return;
}
$featured_image_id = $product->get_image_id();
$image_galleries_id = $product->get_gallery_image_ids();
if( !empty( $featured_image_id ) ) {
wp_delete_post( $featured_image_id );
}
if( !empty( $image_galleries_id ) ) {
foreach( $image_galleries_id as $single_image_id ) {
wp_delete_post( $single_image_id );
}
}
}