SELECT DATE_FORMAT( a.meta_value, '%Y-%m-%d' ) as Completed_Date, /* 2015-01-01 date format */
b.meta_value as Email,
wp_woocommerce_order_items.order_item_name as Product,
c.meta_key as Variation_Type,
c.meta_value as Variation_Name
FROM wp_woocommerce_order_items
left join wp_postmeta a ON wp_woocommerce_order_items.order_id = a.post_id AND a.meta_key = '_completed_date'
left join wp_postmeta b ON wp_woocommerce_order_items.order_id = b.post_id AND b.meta_key = '_billing_email'
left join wp_woocommerce_order_itemmeta c ON wp_woocommerce_order_items.order_item_id = c.order_item_id AND c.meta_key NOT LIKE '\_%' /* escape the underscore wildcard character -- get keys not starting with underscore */
WHERE wp_woocommerce_order_items.order_item_id IN (
SELECT order_item_id FROM wp_woocommerce_order_itemmeta WHERE meta_key='_product_id' and meta_value IN (
SELECT ID from wp_posts where post_type = 'product' and post_author = 33050 /* CHANGE AUTHOR ID */
)
)
OR
wp_woocommerce_order_items.order_item_id IN (
SELECT order_item_id FROM wp_woocommerce_order_itemmeta WHERE meta_key='_variation_id' and meta_value IN (
SELECT ID from wp_posts where post_type = 'product' and post_author = 33050 /* CHANGE AUTHOR ID */
)
)