Managing a WooCommerce store often involves complex data operations such as product imports, customer updates, or bulk order processing. One of the more delicate areas during these operations is maintaining the integrity of order-related data, especially order notes. These notes often contain crucial communication logs, tracking updates, and special customer instructions. Imagine the panic when, after an extensive bulk import of orders, these notes seemingly vanish into thin air. That’s exactly what happened in a recent case study we’ll dive into: missing order notes due to a bulk import misstep, and how an understanding of the WordPress post meta structure helped recover all that lost data.
TL;DR
After performing a bulk import of WooCommerce orders, store managers discovered that all associated order notes were missing. This was due to the import tool overwriting or not merging the existing post meta data correctly. A deep dive into the WordPress database revealed that the order notes still existed but had become orphaned. By carefully merging the post meta entries back into the correct orders, the notes were successfully restored.
The Problem Emerges: Missing Order Notes
It started like any routine update. A WooCommerce store selling custom electronics gear was undergoing maintenance, part of which included importing a batch of completed order data to ensure consistency with a central inventory system. The operation appeared successful—orders imported, statuses updated, no error messages encountered.
However, soon after the import, the customer service team raised a red flag:
- No internal notes on orders regarding previous communications
- Missing tracking numbers that had been logged in order notes
- Order note history visible to customers had vanished
All of this pointed toward a serious issue: the WooCommerce order notes were gone.
Understanding How WooCommerce Stores Order Notes
WooCommerce utilizes the WordPress custom post type system for its orders. Each order is a post of type shop_order. Order notes, meanwhile, are stored as comments in the WordPress database with the comment_type set to order_note. These notes are attached to the order via the comment_post_ID field, which corresponds to the WooCommerce order’s post ID.
When an import tool creates or updates orders, it needs to either maintain or correctly assign these relationships. If it creates a brand new order rather than updating an existing order, any previous comments (aka order notes) attached to the original post ID are effectively “orphaned.”
That’s exactly what happened in this case.
The Culprit: Improper Post Meta Handling
The import process used a plugin that allowed orders to be imported via CSV. However, it did not fully support order note mapping. Even worse, for matching orders by ID, it was configured to replace post meta data entirely without checking for existing content. As a result:
- The imported orders received new or overwritten post meta
- Existing
_order_notesor user comments were no longer attached - Post IDs sometimes changed if the importer didn’t reuse them
With all of this happening under the hood, the system ended up with a dozen “orphan” comment entries in the database—order notes with no associated order. Anyone looking at the WooCommerce dashboard saw a ghost town where order histories used to be.
Post Meta and Comment Recovery Strategy
When the development team began to investigate, they realized the original notes weren’t truly deleted. They were hiding in plain sight in the wp_comments table. The key problem was that their comment_post_ID no longer mapped to an existing order.
Here’s how the team recovered those notes:
Step 1: Identify Orphaned Comments
Using a SQL query, the team filtered the wp_comments table for comment types labeled order_note and checked for missing or invalid comment_post_ID references:
SELECT * FROM wp_comments
WHERE comment_type = 'order_note'
AND comment_post_ID NOT IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order');
This produced a list of order notes not currently linked to any valid order.
Step 2: Match by Other Metadata
Many order notes contained identifying information in their content, such as customer emails, names, or shipping info. By correlating that data manually or programmatically with existing orders, it was possible to determine the correct order for each note.
Step 3: Update Comment Post IDs
Once the correct orders were identified, a simple update query reattached the order notes:
UPDATE wp_comments SET comment_post_ID = [correct_order_id] WHERE comment_ID = [orphaned_note_id];
With this, the notes began to reappear in the WooCommerce Admin under their respective orders.
A Second Layer: Fixing Post Meta Relationships
Some notes appeared back in the order details, but others remained stubbornly missing. That’s when the team realized that although the comment_post_ID was now correct, the post meta relationship still had issues.
WooCommerce often stores comment-related metadata such as _order_notes in the wp_postmeta table. If the meta entries are scoped to the old post ID, they won’t show up even if the comment is valid again.
The team then performed a two-part recovery here:
- Updated the meta entries to reference the correct post ID (order ID)
- Regenerated the WooCommerce order data cache to ensure consistent display
It was a painstaking process initially done manually for about 20 critical orders, and later automated via a PHP script to resolve the rest.
Lessons Learned
This recovery effort wasn’t just about database fixes. It highlighted some core principles every WooCommerce store admin or developer should consider:
- Never bulk import into live environments without a backup
- Understand the full data structure of WooCommerce—especially orders and comments
- Test import settings to see how they affect custom post meta and associated data
- Create rollback scripts or snapshots before any bulk operation
Preventing Future Occurrences
To prevent this issue in the future, the team made several adjustments:
- Switched to a more robust order import plugin that supports custom meta fields and order notes
- Used a staging environment for all import operations and performed QA before merging with live
- Implemented automated backups and snapshot-based recovery with WP-CLI
- Created custom PHP scripts to validate imported orders against expected data
Final Thoughts
The case of the missing WooCommerce order notes was a stressful but eye-opening episode. It demonstrated the power and complexity of how WordPress stores relationships between orders, comments, and metadata. More importantly, it showed that with a solid understanding of the underlying system—and a little SQL knowledge—you can recover from even the most frustrating of data glitches.
Don’t let a bulk import become a bulk disaster. Know your tools, know your database, and always be ready with a backup plan.