woocommerce query

select
p.ID as order_id,
p.post_date,
max( CASE WHEN pm.meta_key = ‘_billing_email’ and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = ‘_billing_phone’ and p.ID = pm.post_id THEN pm.meta_value END ) as billing_phone,
max( CASE WHEN pm.meta_key = ‘_billing_first_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = ‘_billing_last_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = ‘_order_total’ and p.ID = pm.post_id THEN pm.meta_value END ) as order_total,
max( CASE WHEN pm.meta_key = ‘_order_tax’ and p.ID = pm.post_id THEN pm.meta_value END ) as order_tax,
max( CASE WHEN pm.meta_key = ‘_paid_date’ and p.ID = pm.post_id THEN pm.meta_value END ) as paid_date,
max( CASE WHEN pm.meta_key = ‘_billing_field_597’ and p.ID = pm.post_id THEN pm.meta_value END ) as partita_iva,
max( CASE WHEN pm.meta_key = ‘_billing_field_757’ and p.ID = pm.post_id THEN pm.meta_value END ) as codiceUnivoco,
max( CASE WHEN pm.meta_key = ‘_billing_field_846’ and p.ID = pm.post_id THEN pm.meta_value END ) as codice_fiscale,

max( CASE WHEN p.ID = wptr.object_id THEN wptr.term_taxonomy_id END ) as status
from
fum_posts as p,
fum_postmeta as pm,
fum_term_relationships as wptr
where
post_type = ‘shop_order’ and
p.ID = pm.post_id
group by
p.ID

You must be logged in to post a comment.