WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Remove all WooCommerce products (7 posts)

  1. LanceM
    Member
    Posted 1 year ago #

    Hi,

    I have added about 7000 products using the Woo Product Importer plugin but I made a mistake with one of the columns and now the products have incorrect data and wont be overwritten if i import the csv again.

    My question is; how do i delete all woocommerce products quickly, deleting them page by page will take too long, especially if it happens again. Perhaps some sort of SQL query that deletes all the post products and postmeta etc? thanks in advance :)

    http://wordpress.org/extend/plugins/woocommerce/

  2. LanceM
    Member
    Posted 1 year ago #

    Used this SQL query to remove the product posts and their meta data.

    DELETE FROM wp_postmeta
    WHERE post_id IN(SELECT ID FROM wp_posts WHERE post_type = 'product');
    
    DELETE FROM wp_posts WHERE post_type = 'product';

    Seemed to work for now but if anyone has a better solution please let me know :)

  3. bheadrick
    Member
    Posted 1 year ago #

    yeah, that's pretty much the best way to go about it. if you change your screen settings to display over 500 products at a time, you'll probably get a timeout error when deleting them.

    You should probably also delete the records in wp_term_relationships where object_id in (SELECT ID FROM wp_posts WHERE post_type = 'product')

  4. LanceM
    Member
    Posted 1 year ago #

    Thanks i'll do that aswell

  5. Ciprian Popescu
    Member
    Posted 1 year ago #

    So, execute @bheadrick's query before @LanceM's, like this:

    DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
    DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
    DELETE FROM wp_posts WHERE post_type = 'product';

    Don't forget to check your database prefix (wp_) and change it, if necessary.

  6. marcvanzee
    Member
    Posted 1 year ago #

    I think Ciprian Popescu his solution is incomplete because it does not remove custom attributes that are added to products. Such attributes are stored in two places in the database:

    1. As an attribute of the product, stored in wp_postmeta under the key '_produce_attributes'. Ciprian Popescu his solutions will remove these.

    2. As terms in taxonomies that are linked to your products. Ciprian Popescu his solution will not remove these occurrences but only the links with the taxonomies which are stored in wp_term_relationships. To remove the taxonomies (which store the name of the attribute) and the terms (which store the values) as well, you can use the following query:

    DELETE relations.*, taxes.*, terms.*
      FROM wp_term_relationships AS relations
      INNER JOIN wp_term_taxonomy AS taxes
        ON relations.term_taxonomy_id=taxes.term_taxonomy_id
      INNER JOIN wp_terms AS terms
        ON taxes.term_id=terms.term_id
      WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product')

    The idea is that you join the table that contains the relationships between posts and taxonomies (wp_term_relationships) with the table containing the taxonomies (wp_term_taxonomy). Then you join this with the table that contains the terms (wp_terms). This results in all terms and taxonomies that are used by posts. The WHERE clause makes sure that you will only remove the taxonomies and terms of products. Beware that this query might also remove taxonomies and terms that are used by pages that are not products as well, so if you want to filter this out you need an additional query.

  7. bradyso
    Member
    Posted 1 year ago #

    I have to do the same thing, except I didn't understand anything suggested in order to make it happen. Any chance someone could dumb it down for me? Sorry.......

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.