Last modified by Safiye A. Duman - 4 years ago
1 min read

How to get all order ids of a customer in WooCommerce

If you want to find the orders of a WooCommerce customer , since orders are a custom post type in WooCommerce you could use get_posts.

Important parts to remember in your query:

  • For post type don't hardcode to "shop_order" but use wc_get_order_types() which will get all order types
  • For order_status use wc_get_order_statuses(), which will get all the WooCommerce order statuses
  • I added fields=>'ids' to only get the order ids since that was what I needed but you could remove this to get all order data
  • For numberposts I used -1 to get all the orders of this customer , but you could put a count such as 10
  • I used orderby date and order to get the recent orders first
  • I also check with is_user_logged_in function to see if this is a logged in user and not a visitor, before creating the query

Was this information helpful?