Using WP_Query
you can do: (new WP_Query($arguments))->request
to get the raw SQL code that was executed.
But how can you do this with WooCommerces WC_Order_Query
or wc_get_orders
?
Using WP_Query
you can do: (new WP_Query($arguments))->request
to get the raw SQL code that was executed.
But how can you do this with WooCommerces WC_Order_Query
or wc_get_orders
?
1 Answer
Reset to default 2WC_Order_Query
does not store a record of the SQL it generated, or the WP_Query
that it used internally. So it's not possible to get the information you need from WC_Order_Query
directly.
You could try using $wpdb->last_query
immediately after using the class or function, but the last query more than likely isn't the one you're actually looking for:
global $wpdb;
$orders = wc_get_orders();
$query = $wpdb->last_query;
Your best bet is to use a tool like Query Monitor, which will allow you to see all the SQL queries run during a page load. You could use this to inspect your query.