Reputation: 673
I have inherited a site built on Woo-Commerce that I'm helping out a non-profit with. It has a few problems that I've been fixing, but seeing some odd bugs when they edit the orders.
It seems like all the order billing meta data tags appear twice, once with underscore and once without, like:
_billing_first_name
billing_first_name
They both contain the value enter by the customer when they made the order, however the underscore version is what gets edited if you use the Admin dashboard to edit the billing info, and the NON underscore version appears under custom fields.
This is causing some confusion, and I have done a fair bit of searching and not figured out the why.
Thanks in advance if anybody has any hints, otherwise I'll be poking into the code.
Upvotes: 1
Views: 1503
Reputation: 254493
This is completely normal (and is not a bug).
As woocommerce is a Wordpress plugin, it use the classic User data tables. But Orders are a custom post type that store they own user data.
In woocommerce as you can buy optionally without being registered, in that case the user data is only located on the Order postmeta data.
When non registered user make his first purchase (registering at the same time) the data is saved in both wp_usermeta
and wp_postmeta
tables.
When user register before purchasing anything, the data will be registered only in wp_usermeta
table.
For all of that reasons there is 2 locations for user data:
1) billing_first_name
- The user data is stored on wp_usermeta
table and it's editable from the user my account pages (or on backend from users edit pages).
2) _billing_first_name
(start always with an underscore) - The order customer data stored in wp_postmeta
table and it's only editable through backend Order edit pages by admins and shop managers. This data is displayed on orders everywhere and on email notifications...
The underscore at the beginning is avoid this data to be displayed in custom fields Meta BOX (in Order edit pages).
So an Order can have different billing or shipping fields than in usermeta data, as a customer can have different billing/shipping data if he want to.
Woocommerce needs both of them.
You should not make any change related to this, because it will be a real nightmare for you…
Upvotes: 1