Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Posts
    21
    Plugin Contributions
    0

    Default Delete old orders (before specific date)

    Dear Zenners,

    Ik have a shop with a large amount of orders, I want to remove all old orders (not customers) before 01-01-2016. I am able to go into PHP Myadmin but I am not sure what SQL command I must use, hope someone has an example for me?

    Kind regards,

    Raymond

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,311
    Plugin Contributions
    125

    Default Re: Delete old orders (before specific date)

    Take a backup first!

    If the last order you want is 163137 and the table prefix is zen_ do:

    DELETE FROM zen_orders WHERE orders_id < 163137;
    DELETE FROM zen_orders_products_attributes WHERE orders_id < 163137;
    DELETE FROM zen_orders_products WHERE orders_id < 163137;
    DELETE FROM zen_orders_products_download WHERE orders_id < 163137;
    DELETE FROM zen_orders_status_history WHERE orders_id < 163137;
    DELETE FROM zen_orders_total WHERE orders_id < 163137;
    DELETE FROM zen_paypal WHERE order_id < 163137;

    If you have another payment method that has its own table, do that one too.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  3. #3
    Join Date
    Jul 2012
    Posts
    16,799
    Plugin Contributions
    17

    Default Re: Delete old orders (before specific date)

    Don't forget that in order to maintain PCI compliance that an amount of history must be maintained and that keeping a back up of the database would support meeting that requirement. Also, would want a backup just in case something goes wrong.

    Suggest reviewing the related threads below, at least specifically this one: https://www.zen-cart.com/showthread....ounter-history

    As DrByte said, there are a number of tables and data related to things, but also understand that the individuals posting were wanting to remove orders AND customers.

    Also, for "sanity's" sake, before executing a delete query, I would recommend using a select query to validate that the results to be deleted are the ones expected.

    So instead of:
    Code:
    DELETE FROM orders where orders_id = 5;
    For example, would want to use something like:
    Code:
    SELECT date_purchased FROM orders where orders_id = 5;
    Then review the results. If that order or set of orders is the one desired, then change the select (parameter) to just DELETE.

    Note: instead of a specific field such as date_purchased, you could use * to get all fields.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v150 Remove ALL customers and ALL orders before a certain date and reset counter history.
    By hawkwynd in forum Managing Customers and Orders
    Replies: 4
    Last Post: 10 Dec 2013, 03:22 AM
  2. How to delete uploaded files from old orders?
    By benwilliamson in forum General Questions
    Replies: 0
    Last Post: 6 Oct 2009, 05:57 PM
  3. How to delete old orders from order history?
    By David Bo in forum Managing Customers and Orders
    Replies: 3
    Last Post: 17 Jan 2008, 06:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR