• 1000 *
p.ID AS 'Order ID',
p.post_date AS 'Order Created Date',
MAX( CASE WHEN pm.meta_key = '_billing_email' AND pm.post_id = p.ID THEN pm.meta_value END ) AS 'Email Address',
CASE p.post_status
WHEN 'wc-pending' THEN 'Pending Payments'
WHEN 'wc-processing' THEN 'Processing'
WHEN 'wc-on-hold' THEN 'On Hold'
WHEN 'wc-completed' THEN 'Completed'
WHEN 'wc-cancelled' THEN 'Cancelled'
WHEN 'wc-refunded' THEN 'Refunded'
WHEN 'wc-failed' THEN 'Failed'
END AS 'Order Status',
MAX( CASE WHEN pm.meta_key = '_order_total' AND pm.post_id = p.ID THEN pm.meta_value END ) AS 'Order Total',
MAX( CASE WHEN pm.meta_key = '_completed_date' AND pm.post_id = p.ID THEN pm.meta_value END ) AS 'Order Completed Date',
MAX( CASE WHEN pm.meta_key = '_payment_method_title' AND pm.post_id = p.ID THEN pm.meta_value END ) AS 'Order Payment Method',
MAX( CASE WHEN pm.meta_key = '_created_via' AND pm.post_id = p.ID THEN pm.meta_value END ) AS 'Order Created Via',
( SELECT GROUP_CONCAT(CONCAT(m.meta_value, ' x ', i.order_item_name) separator '</br>' )
FROM wp_woocommerce_order_items i
JOIN wp_woocommerce_order_itemmeta m ON m.order_item_id = i.order_item_id AND meta_key = '_qty'
WHERE i.order_id = p.ID AND i.order_item_type = 'line_item') AS 'Order Type'
FROM wp_posts AS p
LEFT JOIN wp_postmeta AS pm ON pm.post_id = p.ID
LEFt JOIN wp_woocommerce_order_items AS oi ON oi.order_id = p.ID
WHERE post_type = 'shop_order'
GROUP BY p.ID```