a8cteam51 / safety-net

Scrub options, deactivate denylisted plugins, and delete user data on development sites.
17 stars 1 forks source link

Delete WC customers and Analytics #109

Closed NickGreen closed 3 months ago

NickGreen commented 11 months ago

Customers: /wp-admin/admin.php?page=wc-admin&path=%2Fcustomers

Analytics: /wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2Foverview

NickGreen commented 11 months ago

Tables to purge:

wp_woocommerce_payment_tokenmeta
wp_woocommerce_payment_tokens
wp_woocommerce_log
wp_wc_webhooks
wp_wc_customer_lookup

Maybe also delete all the WC log files in the /wp-content/uploads/wc-logs folder

Could invalidate teh analytics cache by running this: \WC_Cache_Helper::get_transient_version( 'woocommerce_reports', true );

NickGreen commented 11 months ago

Struggling to figure out how to clear the Analytics page. Have tried re-importing all the orders after deleting them, have tried clearing the analytics cache, but no luck. Stepping away for now.

NickGreen commented 11 months ago

ChatGPT cleared this up for me:

However, with the advent of the WooCommerce Admin feature (which is now a part of WooCommerce core), a new set of tables were introduced to store analytics data for better performance. These tables have names like wp_wc_order_stats, wp_wc_order_product_lookup, wp_wc_customer_lookup, etc. They are populated using data from the tables mentioned earlier and are designed to make querying faster and more efficient.
Here is a breakdown of these specialized tables:
1. *wp_wc_order_stats*: Contains summarized information about orders.
2. *wp_wc_order_product_lookup*: Contains information about products in orders.
3. *wp_wc_customer_lookup*: Contains customer data for easier lookup.
jonesch commented 9 months ago

Tables to purge:

@NickGreen - I went through some steps today and wanted to document my process and outcome here.

We cloned https://www.earlymedical.com/ over to https://early-medical-lms-showcase-woo-payments.mystagingwebsite.com via the CLI, which ran all the SafetyNet love.

From there, I still saw customers in WP Amin > WooCommerce > Customers. Though all of the orders were gone, and when I clicked on a customer from this view, it took me back to the wp-admin/user-edit.php?user_id= page in WP Admin with an error message saying this User ID was invalid.

I then took the following steps:

  1. truncated the data in wp_wc_customer_lookup table via PHPMyAdmin
  2. truncated the data in wp_woocommerce_payment_tokenmeta table via PHPMyAdmin
  3. truncated the data in wp_woocommerce_payment_tokens table via PHPMyAdmin
  4. cleared the transient in WP Admin > WooCommerce > Status > Tools

That has cleared up all of the Customers and is allowing me to get back to adding test transactions to the site.

The site previously used the Stripe extension for payment processing. Our goal with this site is to install WooPayments and add a good bit of test transactions so we can showcase WooPayments to a partner.