how to delete completed orders in woocommerce using a my sql query

后端 未结 5 840
慢半拍i
慢半拍i 2021-01-03 08:02

I want to delete completed all orders in woocommerce by using a single my sql query. Because, I\'m having a problem with my WordPress Dashboard

相关标签:
5条回答
  • 2021-01-03 08:25

    To delete orders with completed status, you should only use the following code.

    UPDATE wp_posts 
    SET post_status = 'trash' 
    WHERE post_type = 'shop_order'
    AND post_status = 'wc-completed'
    

    This code does not completely eliminate the system or base of Order data, send it to the trash.


    Do you want to permanently delete orders ?, you must go to:

    Woocommerce > Orders > Trash and click Empty Trash.


    If you want to eliminate other orders, you should only know the different status that exists in Woocommerce:

    1. wc-completed
    2. wc-pending
    3. wc-processing
    4. wc-on-hold
    5. wc-cancelled
    6. wc-refunded
    7. wc-failed

    And you are specifying them inside the clause IN ('status')

    UPDATE wp_posts 
    SET post_status = 'trash' 
    WHERE post_type = 'shop_order'
    AND post_status IN ('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-cancelled', 'wc-refunded', 'wc-failed')
    
    0 讨论(0)
  • 2021-01-03 08:42

    My solution would be just deleting all the orders(If you're moving from a shop with demo data to your new site). You can do this using following SQL-queries.

    DELETE FROM wp_woocommerce_order_itemmeta
    DELETE FROM wp_woocommerce_order_items
    DELETE FROM wp_comments WHERE comment_type = 'order_note'
    DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_order' )
    DELETE FROM wp_posts WHERE post_type = 'shop_order'
    
    0 讨论(0)
  • 2021-01-03 08:42

    I solved this by first setting all the relevant orders to trash:

    UPDATE wp_posts SET post_status = 'trash' WHERE post_type = 'shop_order';
    

    If you have too many posts to get through when pressing Empty Trash and you get a PHP error, you can run the following SQL to remove them instead:

    DELETE FROM wp_posts
    WHERE post_type = 'shop_order' 
    AND post_status = ‘trash’
    
    0 讨论(0)
  • 2021-01-03 08:45

    Woocommerce orders are stored in the post table, postmeta table, woocommerce_order_items, and woocommerce_order_itemmeta tables. Various parts of an order are stored in different tables. addition to that the order status is managed through the taxonomies which stores the order status list. Anyone who is/will be writing this query have to write at least 5-6 queries minimum or single large join query.

    So, my suggestion to you should uninstall WooCoommerce, if you don't have much larger product setup. To do this you can follow this link which will delete the data

    0 讨论(0)
  • 2021-01-03 08:45

    To use the native Woocommerce functionality by the maximum, you can do it following way. Move all orders to trash with SQL:

    UPDATE wp_posts SET post_status = 'trash' WHERE post_type = 'shop_order';
    

    And then go to Woocommerce -> Orders -> Trash and click Empty Trash.

    0 讨论(0)
提交回复
热议问题