How to Correctly Remove Woocommerce from WordPress (with product images)?

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 );
        }
    }
}

Useful Woocommerce tips

  • How to Customize Woocommerce Checkout page? 28 useful hacks

  • How to customize Woocommerce cart page? 21 useful Woocommerce Cart Page Hacks

  • Woocommerce – Disable Payment Methods Based on User Roles

  • How to sell tickets with Woocommerce?

  • How to add Woocommerce Quantity Selector in Archive/Loop pages?

  • How to sell tickets with Woocommerce?

  • 12 useful Woocommerce snippets & hacks

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top