20

I'm looking in the sql db and I can see something that resembles orders inside wp_posts . However, I would expect them to be inside the tables beginning with wp_woocommerce.

Can anyone shed some light on this phenomenon?

Cheers

Matt M
  • 348
  • 2
  • 8
Ke.
  • 2,484
  • 8
  • 40
  • 78

6 Answers6

22

In woocommerce orders are modelled as a custom post type so they are stored in wp_posts as you found. See WooCommerce taxonomies and post types for a list of the custom post types that woocommerce uses. Orders are stored as the type shop_order

Separate items within an Order are stored as separate records in the custom table woocommerce_order_items

Adrian
  • 2,233
  • 1
  • 22
  • 33
jacks
  • 4,614
  • 24
  • 34
  • I was looking for _billing_address and fields like this, but I can see these references in the code are actually functions that are drawing data from several tables :/ – Ke. Jul 31 '15 at 12:47
  • 2
    `_billing_address` is in `wp_postmeta` as it is simply meta for the `order` post. – helgatheviking Jul 31 '15 at 14:31
  • Omg, thank you, but wp dev is so tricky... Architecture? No, did not hear... – Oleg Reym Sep 07 '21 at 14:06
18

Updated plug-in version information 8/10/2018

Orders are a custom post type. From WooCommerce Post Types:

  • Shop Order (shop_order)

Orders live in the wp_posts table (post_type = 'shop_order'). More data is available by looking up the order's post_id in the wp_postmeta table.

In addition, from the WooCommerce GitHub Wiki Database Description

  • woocommerce_order_items – Stores line items which are associated with orders.
  • woocommerce_order_itemmeta – Stores meta data about order line items.

Currently the WordPress WooCommerce plug-in version is 3.4.x

Adrian
  • 2,233
  • 1
  • 22
  • 33
Matt M
  • 348
  • 2
  • 8
5

WooCommerce orders are "custom post" they are stored in "wp_posts" under "post_type" -> ""shop_order"

if you want to select shop orders with sql query you can do something like below.

global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'shop_order'", ARRAY_A );
Aamer Shahzad
  • 2,617
  • 1
  • 27
  • 25
3

You can find them inside wp_posts table.

In PhpMyAdmin:

Click wp_posts table, then click SQL Tab and run the following query, assuming wp_posts is your table name:

Select * from wp_posts where post_type='shop_order'

Then you have all the data regarding woocommerce orders

click "Show all" checkbox

Search for "completed" for completed orders

csandreas1
  • 2,026
  • 1
  • 26
  • 48
0
wp_woocommerce_order_itemmeta
wp_woocommerce_order_items
wp_posts

Depending on the kind of data your looking for you have to look in diffrent places. If you have PHPMyAdmin try and find the data your looking for.

Dylan Wijnen
  • 219
  • 3
  • 13
0

I recently restored the orders data manually and here is the table I found.

wp_posts //post_type = shop_order
wp_postmeta 
wp_woocommerce_order_items
wp_woocommerce_order_itemmeta

Make sure your order_id/order_item_id reference is correct on postmeta and itemmeta.

user918475
  • 27
  • 4