Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Support LovingBro (woo-hc)

    (@lovingbro)

    Hi @arfoul,

    I understand you’d like to clear out the old product stock analytics data that’s being displayed in WooCommerce → Analytics → Stock. Those numbers (like total, in stock, out of stock, and low stock) aren’t stored as separate “logs” — they’re dynamically generated from your products’ current stock data. However, if the counts look outdated or include products you’ve since deleted, it likely means WooCommerce Analytics hasn’t fully reimported or cleared its cached data.

    Here’s how you can refresh and clean it up:

    1. Go to WooCommerce → Status → Tools.
    2. Scroll down to the Analytics section.
    3. Click Clear analytics cache.
    4. Next, click Reimport data under “Import historical data”.
    5. Once the import finishes, revisit Analytics → Stock to confirm the counts reflect your current inventory.

    If you’d prefer to reset all Analytics data completely, you can also remove analytics lookup tables using a database tool like phpMyAdmin (tables start with wp_wc_analytics_…) — but this should only be done if you’re comfortable with SQL and after taking a full database backup.

    Let’s see how it goes after clearing and reimporting your Analytics data!

    Thread Starter arfoul

    (@arfoul)

    Thank you for the reply.

    I need a full reset, I have already tried to clear analytics cache from tools page.

    I am comfortable with SQL but I would prefer if there was a relative safe way to do it so that I don’t mess anything up. If not I am guessing running something like this would do?

    TRUNCATE TABLE wp_wc_analytics_products;

    Plugin Support LovingBro (woo-hc)

    (@lovingbro)

    Hi @arfoul,

    Got it — if you need a full reset rather than just clearing the cache, there’s a safe way to rebuild what the Stock report uses without risking product data.

    First, the safest (no-SQL) route:

    1. Back up your database (always good practice).
    2. Go to WooCommerce → Status → Tools:
      • Run Clear analytics cache.
      • Run Delete previously imported data (under Analytics).
      • Run Regenerate product lookup tables (this rebuilds wc_product_meta_lookup, which powers stock status/counts).
    3. Go to WooCommerce → Status → Scheduled Actions and run any pending/import tasks related to analytics (e.g., wc_admin_import*) until the queue is clear.
    4. Revisit Analytics → Settings → Import Historical Data and start a fresh import if you want orders/customers rebuilt too.

    If you prefer SQL (advanced, with a backup):
    WooCommerce Analytics data lives in these lookup tables (prefix varies, e.g., wp_):

    • {prefix}wc_order_stats
    • {prefix}wc_order_product_lookup
    • {prefix}wc_order_tax_lookup
    • {prefix}wc_order_coupon_lookup
    • {prefix}wc_customer_lookup

    You can reset them with:

    TRUNCATE TABLE {prefix}wc_order_stats;
    TRUNCATE TABLE {prefix}wc_order_product_lookup;
    TRUNCATE TABLE {prefix}wc_order_tax_lookup;
    TRUNCATE TABLE {prefix}wc_order_coupon_lookup;
    TRUNCATE TABLE {prefix}wc_customer_lookup;

    Then, in Status → Tools, run Regenerate product lookup tables, and finally re-import via Analytics → Settings → Import Historical Data.

    A couple of important notes:

    • There isn’t a core table named wp_wc_analytics_products; truncating that won’t help and may indicate a custom table from another plugin.
    • Truncating the tables above does not delete your actual orders/products; it only clears the analytics/lookup layer so WooCommerce can rebuild counts and reports from current data.
    • If you use WP-CLI, I can share exact commands to run the tools and monitor the Action Scheduler queue.

    Feel free to let us know how it goes.

    Thread Starter arfoul

    (@arfoul)

    Thank you your message again.

    Yes I would prefer WP CLI if it’s not trouble, that would be much easier.

    Plugin Support LovingBro (woo-hc)

    (@lovingbro)

    Hi @arfoul,

    Absolutely, using WP-CLI is a great way to handle this cleanly and safely — glad to hear you’re comfortable working with it. Here’s the sequence you can use to completely reset and rebuild your WooCommerce Analytics data:

    # Always good to start with a backup first
    wp db export backup-before-analytics-reset.sql
    
    # Clear existing Analytics data
    wp wc tool run delete-previously-imported-data --user=1
    
    # Clear Analytics cache
    wp wc tool run clear-analytics-cache --user=1
    
    # Regenerate product lookup tables
    wp wc tool run regenerate-product-lookup-tables --user=1

    After that, trigger a fresh import of your historical data so WooCommerce can rebuild everything:

    wp wc analytics regenerate --all

    If you’d like to keep an eye on the progress, you can check the Action Scheduler queue with:

    wp action-scheduler list --status=pending

    Once the tasks finish running, head back to Analytics → Stock, and the counts should reflect your current inventory only.

    That’s the cleanest approach — no direct SQL edits needed, and it keeps your database structure intact. Let me know once you’ve tried it, and we’ll double-check the results together.

    Thread Starter arfoul

    (@arfoul)

    mywpuser@d001:~/webapps/mywpuser$ wp db export backup-before-analytics-reset.sql
    Success: Exported to 'backup-before-analytics-reset.sql'.
    mywpuser@d001:~/webapps/mywpuser$ wp wc tool run delete-previously-imported-data --user=1
    Error: Sorry, you are unable to update the resource. {"status":403}
    mywpuser@d001:~/webapps/mywpuser$ wp wc tool run clear-analytics-cache --user=1
    Error: Sorry, you are unable to update the resource. {"status":403}
    mywpuser@d001:~/webapps/mywpuser$ wp wc tool run regenerate-product-lookup-tables --user=1
    Error: Sorry, you are unable to update the resource. {"status":403}
    mywpuser@d001:~/webapps/mywpuser$ wp wc analytics regenerate --all
    Error: 'analytics' is not a registered subcommand of 'wc'. See 'wp help wc' for available subcommands.
    Plugin Support LovingBro (woo-hc)

    (@lovingbro)

    Hi @arfoul,

    Thanks for running those commands and sharing the output — that helps a ton. The 403s you’re seeing mean WP-CLI isn’t actually running the WooCommerce tools as an authenticated admin, and that’s why the requests are being rejected. Also, the wp wc analytics regenerate subcommand isn’t part of WooCommerce’s CLI, so that one will always fail.

    Here’s the quickest way to fix it and get the reset done via WP-CLI:

    1) Make sure you’re acting as a real admin user

    # Find an administrator you can impersonate
    wp user list --role=administrator --fields=ID,user_login,display_name

    Pick the user_login of a real admin (don’t assume –user=1 is an admin on your site).

    2) Re-run the WooCommerce tool commands as that admin

    Substitute <admin_login> and your real site URL:

    # (Optional but recommended if you have multiple installs on the server)
    wp --url="https://your-site.com" wc tool run delete-previously-imported-data --user=<admin_login>
    
    wp --url="https://your-site.com" wc tool run clear-analytics-cache --user=<admin_login>
    
    wp --url="https://your-site.com" wc tool run regenerate-product-lookup-tables --user=<admin_login>

    Why this helps

    • –user=<admin_login> ensures the call has the manage_woocommerce capability, avoiding the {“status”:403}.
    • Adding –url=… makes sure WP-CLI is targeting the exact site (handy on servers with multiple WP installs or custom docroots).

    3) Kick tasks and watch progress (optional)

    # If Action Scheduler CLI is available on your install:
    wp action-scheduler run --due-now
    wp action-scheduler list --status=pending

    4) About the missing subcommand

    • wp wc analytics regenerate isn’t a WooCommerce CLI command, so you can ignore that error. Once you’ve cleared “previously imported data” and cache, the historical import can be started from Analytics → Settings → Import Historical Data in the wp-admin UI (that’s the supported trigger).

    If you still hit 403 after using a confirmed admin login, let me know:

    • The site URL you’re passing (if any)
    • The exact wp help wc tool output (so we can confirm the subcommand is registered)
    • Whether your host/WAF is blocking loopback/REST from CLI
    Thread Starter arfoul

    (@arfoul)

    ah sorry my bad.
    I have run this with my user id and I am geting status 404.
    I tried this wp –url=”https://mywebsite.com&#8221; wc tool list –user=7
    and this is what i got:
    +-----------------------------------------------+-------------------------------+---------------------+
    clear_transients
    clear_expired_transients
    delete_orphaned_variations
    clear_expired_download_permissions
    regenerate_product_lookup_tables
    repair_coupons_lookup_table
    recount_terms
    reset_roles
    clear_sessions
    clear_template_cache
    clear_system_status_theme_info_cache
    install_pages
    delete_taxes
    regenerate_thumbnails
    db_update_routine
    recreate_order_address_fts_index
    verify_db_tables
    regenerate_product_attributes_lookup_table
    sv_wc_background_job_test
    clear_woocommerce_analytics_cache
    refresh_remote_inbox_notifications
    delete_inbox_notification
    hpos_legacy_cleanup
    delete_custom_orders_table
    schedule_expired_transient_files_cleanup

    • This reply was modified 7 months, 2 weeks ago by arfoul.
    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there! 👋

    Thanks for the update and for sharing the details. The 404 status usually indicates that the REST API endpoint you’re trying to access isn’t available for that specific user ID or the user doesn’t have the required permissions.

    From the output you shared, the wc tool list command itself seems to be working correctly since it’s returning the list of available WooCommerce tools.

    Please note that we only provide support for issues related to WooCommerce core features. The problem you’re experiencing with running a query and receiving a 404 error falls outside the scope of our support.

    If you need more in-depth support or want to consider professional assistance for customization, I can recommend WooExperts and Codeable.io as options for getting professional help.

    Alternatively, you can also ask your development questions in the  WooCommerce Community Slack as custom code falls outside our usual scope of support.

    Thread Starter arfoul

    (@arfoul)

    Well, I am the only administrator and there is no one else. I tried following the steps manually without the cli and I do not see the Delete previously imported data (under Analytics). Maybe that is the issue?

    View post on imgur.com

    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    I understand your concern. You’ll need to import data first before the “Delete Previously Imported Data” button becomes available.

    To import existing historical data:

    1. Disable the “Skip previously imported customers and orders” option.
    2. Start the import process.
    3. Once the data has been successfully imported, the “Delete Previously Imported Data” button should appear, allowing you to delete the imported data if needed.

    Please try importing the existing historical data and then check if the button appears. If it does, click it to delete the data and see if that resolves the issue.

    For more details, you can follow this guide:
    🔗 https://woocommerce.com/document/woocommerce-analytics/#resetting-analytics

    Thread Starter arfoul

    (@arfoul)

    I have tried what you said. Imported all orders and then deleted them.

    wp cli commands that worked for me (latest woo version)

    wp wc tool run clear_woocommerce_analytics_cache --user=7
    wp wc tool run db_update_routine --user=7

    I have also waited for a few hours, and still nothing changed.

    Hi @arfoul,

    Thank you for getting back and for the update.

    Hi, in Analytics > Stock there is a count of all the products added to the store. How can I remove these logs. Regards.

    I need a full reset, I have already tried to clear analytics cache from tools page.

    I understand you’d like to clear the stock counts showing under Analytics → Stock.

    It’s important to note that the Stock report isn’t a stored log — it’s a real-time snapshot of your current inventory. The figures you see (like total products, in stock, out of stock, or low stock) are calculated directly from your existing products.

    Unlike reports such as Orders, Revenue, or Customers, which record historical data that can be imported or deleted, the Stock view simply reflects:

    • The products currently in your store
    • Their real-time stock status

    There isn’t a separate “stock analytics” dataset to clear. To change the numbers shown, you’d need to either:

    • Delete the actual products, or
    • Turn off stock management for them

    Could you please share a bit more about what you’re hoping to achieve? For example:

    • Do you want to reset product counts after a migration or import?
    • Are you still seeing products listed even after deleting them?
    • Or are you just trying to start with a clean reporting slate?

    Understanding your exact goal will help me guide you more effectively.

    Thread Starter arfoul

    (@arfoul)

    I know what I am asking is a little weird and I honestly didn’t think this would be such an issue.

    As I said in first post, I would like to reset these counters to 0 if possible. I would like keep all the current product stock untouched obviously. I only have around 5800 products, and the stats show more than 23.000. I guess there is no easy way to delete all these records?

    Regards,
    Arthur.

    Hi @arfoul,

    Thank you for the clarification. The reason you’re seeing 23,000 products instead of 5,800 is that some of your products are variable products. The data in Analytics → Stock counts each variation separately — for example, if a product has 10 variations, it will appear as 10 separate entries since each variation has its own stock quantity. That’s why the total number appears higher than your actual product count.

    As for resetting stock, the only way to do this is by manually adjusting the stock quantity for each product and variation which will then reflect in analytics > stock, or by disabling stock management entirely if you don’t want stock levels to be tracked.

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

The topic ‘Remove old stock analytics counts’ is closed to new replies.