====== How Woocommerce stores orders in the database? ====== WooCommerce stores order data in the WordPress database similarly to how it [[how_woocommerce_stores_products_in_the_database|stores product data]], utilizing the existing WordPress database structure along with custom tables and relationships. Here’s how WooCommerce organizes order data: ===== Database Tables ===== * Posts Table (`wp_posts`): Each order is saved as a custom post type called `shop_order` in the `wp_posts` table. This allows WooCommerce to manage orders using the built-in WordPress post management functionality. * Post Meta Table (`wp_postmeta`): Details about each order (such as order status, billing and shipping information, product details, payment methods, etc.) are stored in the `wp_postmeta` table. Each meta entry is associated with its corresponding order via the post ID. ===== Key Fields in the Posts Table ===== When an order is created, a new row is inserted in the `wp_posts` table with the following key fields: * `ID`: The unique identifier for the order. * `post_type`: Set to `shop_order`. * `post_status`: Indicates the status of the order (e.g., `wc-pending`, `wc-completed`, etc.). * `post_date` and `post_modified`: Timestamps for when the order was created and last modified. ===== Key Fields in the Post Meta Table ===== The `wp_postmeta` table stores various metadata associated with each order. Some key metadata fields include: * `_billing_first_name`: Customer's first name. * `_billing_last_name`: Customer's last name. * `_billing_address_1`: Primary billing address. * `_billing_city`: Billing city. * `_billing_state`: Billing state. * `_billing_postcode`: Billing postcode. * `_billing_country`: Billing country. * `_payment_method`: Method of payment (e.g., PayPal, Direct Bank Transfer). * `_order_total`: Total amount billed for the order. * `_line_items`: Details for each product in the order, typically serialized. * `_shipping_total`: Total shipping cost. * `_order_currency`: Currency of the order. ===== Additional Tables for Woocommerce ===== WooCommerce may also create additional tables or use relationships for certain features, such as: * Order Items Table (`wp_woocommerce_order_items`): This table stores the items purchased in each order, where each row represents an individual order item. * Order Item Meta Table (`wp_woocommerce_order_itemmeta`): This holds metadata for each order item, including product IDs and quantities. ===== Order Statuses ===== WooCommerce has a predefined set of order statuses (like `pending`, `processing`, `completed`, `cancelled`, etc.) which are stored as part of the post meta. These statuses help manage the order workflow. ===== Extensions, plugins and Customizations ===== As with product data, many WooCommerce extensions or plugins might introduce their own tables or post types to manage additional order-related information, such as customer feedback, order notes, or processing logs. ===== How to export WooCommerce orders? ===== You can use the software [[https://fblsoft.com/fblwpexport.html|FBL WP Export]] to export your orders.