Where do order and everything in it is stored in the database after it is placed from a WordPress woo-commerce website? To be more precise, how can I get my shipping address without using woocommerce classes like WC_Order class? I mean I need to get that data manually through my custom database queries, but I can’t find the order and everything associated with it in my database? I know order is stored in the database as post in the wp-posts table but where is the rest of it i.e shipping address billing address etc etc?
Leave a Reply
You must be logged in to post a comment.
Orders are a Custom Post Type (CPT), so they are stored in the wp_posts table. If you search the post_type field for ‘shop_order’, SQL will retrieve all orders.
Then, you must search the wp_postmeta table for all the records with post_id matching the id of the order post. Among the fields you will then find in the wp_postmeta table will be the entire shipping and billing addresses.
Source here.
Also the order data will be stored in the woocommerce_order_items and woocommerce_order_itemmeta tables (for WooCommerce > 2.5 I believe) These tables contain things pertaining to the actual product the customer bought.
The shop_order post entries have the post_id which matches order_id in woocommerce_order_items. The order_item_id in woocommerce_order_items matches the order_item_id in woocommerce.order_itemmeta.
I can confirm that woocommerce orders are a custom post type so they are stored in wp_posts.
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.
This query should be able to help you. You just need to change the DB prefix for your own DB:
I just wrote it and I can see email, billing address, name, purchase amount, etc. I didn’t see the exact items and the amount, maybe additional querying is necessary.