• Resolved delanthear

    (@delanthear)


    We’ve been working with some one who wanted to remove all their old orders and customer records from their woocommerce website. They’ve deleted their customers and orders, but their customer screen still has 5 accounts in, complete with email addresses and postcodes

    Only one of these links back to a user account, none of the others link anywhere. All of them have a negative total spend, so I’m assuming this is some data mess caused by refunds.

    How do we remove this data? Do we need to fish around in the database?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @delanthear,

    Good catch noticing the negative totals, that’s a useful clue. What you’re seeing is a side effect of how WooCommerce stores customer data: the Customers screen pulls from a separate analytics lookup table built for reporting performance, not directly from your live orders or users. When orders get deleted outside WooCommerce’s normal flow, the corresponding analytics rows (including refund records) can get left behind with nothing to reconcile against, which is likely why these 5 show negative spend, they’re probably refund entries whose original orders are already gone.

    The fix shouldn’t require touching the database directly: go to Analytics → Settings, and under “Import Historical Data,” use “Delete previously imported data.” That clears and rebuilds the analytics tables from what currently exists in the store, which should remove these orphaned records since they no longer have any order backing them: https://woocommerce.com/document/woocommerce-analytics/#resetting-analytics.

    One thing to flag before you run it: this affects all analytics/reporting data on the site, not just these 5 records, so it’s worth re-running the import afterward to repopulate everything accurately, and if there’s a lot of order history, the resync can take a bit to finish in the background.

    Let us know how that goes!

    Thread Starter delanthear

    (@delanthear)

    Ah ha!

    However, there is no option to delete previously imported data, just a greyed out start button (presumably because there is nothing to import now)

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @delanthear,

    Thanks for sharing the follow-up! The behaviour is intended due to this:

    For new store owners, you’ll need to import data before the ‘Delete Previously Imported Data’ button will be available. To import existing historical data, disable ‘Skip previously imported customers and orders’ then start the import. Once the existing data has been imported, it can be deleted with the ‘Delete Previously Imported Data’ button.

    https://woocommerce.com/document/woocommerce-analytics/#resetting-analytics

    Since the “Delete previously imported data” button only appears after an import has been run, you can trigger it like this:

    1. Go to WooCommerce → Analytics → Settings → Import Historical Data
    2. Uncheck “Skip previously imported customers and orders”
    3. Click Start to run the import (note: depending on how many orders are on the site, this may take a while)
    4. Once complete, the “Delete previously imported data” button should appear — use that to clear the analytics tables, which will remove those orphaned customer records along with everything else
    5. You can then re-run the import to repopulate accurate data from the current orders

    If that doesn’t work,

    you can trigger the same deletion directly from the command line via WP-CLI. Run this from your site’s root directory:

    wp --user=1 eval 'Automattic\WooCommerce\Admin\ReportsSync::delete_report_data();'

    I would strongly recommend creating a backup of your database first.

    I hope that helps. Let us know if you need anything else.

    Thread Starter delanthear

    (@delanthear)

    Hi, the ‘Skip previously imported customers and orders’ option still doesn’t let you run the import, because there is no data to import I’m guessing. Like I said, we deleted customers and previous data, so it’s kinda like a new site, even though it’s been going for years.

    I’ll try the wp cli command, but you should put this as an admin option. You don’t always have CLI access to do these things. (I never use wp cli for this reason!)

    Thread Starter delanthear

    (@delanthear)

    Hi, the command via wp cli seemed to be successful (i.e. it gave me no error, or output at all…) but the phantom customers are still in the customers screen.

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @delanthear,

    Actually, unchecking that option does enable the import to run. Here’s a quick screencast showing it: https://streamable.com/dn96c0. Could you confirm whether yours still doesn’t allow it after unchecking?

    On the WP-CLI point, that’s completely fair feedback and we’ll pass it along. Not everyone has CLI access and this should be manageable from the UI. However, it’s more efficient and you can go with it if you do have it, or contact your hosting provider. In the meantime, the command from my previous reply remains the most direct option if you do have access to give it a try.

    If it doesn’t work, try:

    wp wc analytics reset

    I hope that helps. Let us know if you need anything else.

    Thread Starter delanthear

    (@delanthear)

    Hi, thanks for the fast responses 🙂

    Yeah, unchecking the box shows a brief pause as an ajax call fires. Then 0 of 0 populates for both customers and orders and the button stays grey because there is nothing to import.

    That command doesn’t work either:

    wp wc analytics reset
    Error: 'analytics' is not a registered subcommand of 'wc'. See 'wp help wc' for available subcommands.

    running wp wc gives me a list of commands, but analytics isn’t one of them.

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @delanthear,

    Thanks for the update!

    Could you share a screenshot of it via snipboard.io? Be sure to blur any personal information.

    Thread Starter delanthear

    (@delanthear)

    UPDATE! The data has now gone. I wonder if there was some caching meaning the delete_report_data call didn’t immediately work!

    Just for reference, here is the screen showing the disabled start button https://snipboard.io/UYTv2F.jpg

    FWIW, I’ve just had another customer report this same issue, where they’ve cleared out their customers and order data but the customers screen holds old bad data (these are records from 2020!) which they are unable to remove themselves. (We’ve just sent an updated “clean up your websites” email to remind people to clear our data they no longer need, hence getting a few requests like this.

    Seems like you’ve a process which isn’t cleaning up after itself here, and don’t have a way to force it in the admin panel. (Means we get work, but probably should be fixed 🙂 )

    Thread Starter delanthear

    (@delanthear)

    Re-importing the data from settings in analytics was possible on the second customer because they still had a few orders in. This didn’t clear the bad data though, meaning there is still PI in there they want to remove.

    I’ll try and do it via CLI later, but that’s quite a bit of hassle as I have to generate and set up keys to do it, so yeah, would be good to get this something which can be cleared out from the admin panel!

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @delanthear,

    Thanks for the update, and glad to hear things are moving in the right direction! It sounds like the first command did the trick, which is great.

    It looks like Delete Previously Imported Data option under Analytics → Settings doesn’t seem to clear those orphaned records. I’m going to dig into that a bit more and check with the team to understand exactly why it doesn’t catch them, and whether there’s a cleaner built-in route for this scenario. I’ll report back once I have something concrete.

    In the meantime, please do let us know once you’ve run through it on the second site. That’ll help confirm the approach is solid before we document it as the go-to fix.

    Appreciate your patience with this one, especially across two sites. I know it’s a bit of a hassle!

    Thread Starter delanthear

    (@delanthear)

    Running the ReportsSync::delete_report_data(); didn’t work.

    However! What did work was reimporting the data again but ONLY importing back 365 days. As the erroneous data was from ages ago, it wasn’t reimported again. Great!

    I’ve a question though, where was that data? It has PI so we need to be sure! Deleting everything via that command, OR using import historical data didn’t nuke it, unless I specified to only use recent data.

    That kinda suggests the data is still there somewhere? (It might just be a quirk of edge cases of course!)

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @delanthear,

    Thanks for digging into this and sharing what worked. That’s a really useful finding.

    To answer your PII question: that data was likely living exclusively in wp_wc_customer_lookup, which is WooCommerce’s analytics reporting table, essentially a derived cache built from order data. It’s not primary storage; it gets populated and repopulated from your orders. Once you ran the delete and reimported with the 365-day scope, the table was rebuilt from only your recent orders, and the older orphaned records weren’t included, so they’re gone from the active database.

    The reason it didn’t feel fully cleared before is possibly that a full reimport would have repopulated the table from all existing historical data, but the 365-day limit drew a line that excluded the orphaned records entirely.

    So to directly answer your concern: the data is not lurking elsewhere in the database. The orders backing it were already deleted, and now the analytics cache has been rebuilt without them.

    One caveat worth flagging: any database backups taken before this cleanup was run will still contain those records. If GDPR compliance is a consideration, those backups should be handled according to your data retention policy.

    Thanks again for the thorough testing!

    Thread Starter delanthear

    (@delanthear)

    Great support. Thanks,

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    @delanthear you’re welcome!

    Do not hesitate to reach out if you need anything else.

    If you found our support helpful, it would be nice if you write us a review: https://wordpress.org/support/plugin/woocommerce/reviews/. It would mean a lot to the team.

Viewing 15 replies - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.