I need a query that returns me all the users with orders with payment approved.
I'm having a hard time finding where in the db this is stored. I found only post_status 'wc-complete', but I don't think this is the right info.
SELECT a.post_status, b.meta_value FROM wp_posts a, wp_postmeta b
WHERE a.ID = b.post_id
AND a.post_type = 'shop_order'
AND a.post_status = 'wc-completed'
Here is a custom function with a SQL query, that will output an formatted array of User IDs with their completed orders (paid / accepted):
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.
EXAMPLE USAGE just for test to see the raw outputted data
You will get something like:
Using that others listed meta keys, you can make your SQL query (that can replace our first query in the function):
Tested and works too…