Users-Total-orders-list
get_results(“select p.ID as order_id, 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 = ‘_shipping_first_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as first_name, max( CASE WHEN pm.meta_key = ‘_shipping_last_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as last_name, max( CASE WHEN pm.meta_key = ‘_shipping_address_1’ and p.ID = pm.post_id THEN pm.meta_value END ) as shipping_address_1, max( CASE WHEN pm.meta_key = ‘_shipping_city’ and p.ID = pm.post_id THEN pm.meta_value END ) as city, max( CASE WHEN pm.meta_key = ‘_shipping_postcode’ and p.ID = pm.post_id THEN pm.meta_value END ) as postcode, max( CASE WHEN pm.meta_key = ‘_shipping_state’ and p.ID = pm.post_id THEN pm.meta_value END ) as shipping_state, 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 = ‘_paid_date’ and p.ID = pm.post_id THEN pm.meta_value END ) as paid_date, ( select group_concat( order_item_name separator ‘, ‘ ) from wp_woocommerce_order_items where order_id = p.ID ) as order_items from wp_posts p join wp_postmeta pm on p.ID = pm.post_id join wp_woocommerce_order_items oi on p.ID = oi.order_id where post_type = ‘shop_order’ and post_date BETWEEN ‘2022-10-01’ AND ‘2029-12-31’ and post_status = ‘wc-completed’ group by p.ID ORDER BY `first_name` ASC, `paid_date` ASC “); echo “Order id | Name | Order_total | Paid date | |
“.$wp_posts->order_id.” | “; echo ““.$wp_posts->first_name.” “.$wp_posts->last_name.” | “; echo ““.$wp_posts->billing_email.” | “; echo ““.$wp_posts->order_total.” | “; echo ““.$dateVal.” | “; echo “
“.$wp_posts->order_items.” | “; $count++; } echo “
Users-Total-orders-list-2023
get_results(“select p.ID as order_id, 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 = ‘_shipping_first_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as first_name, max( CASE WHEN pm.meta_key = ‘_shipping_last_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as last_name, max( CASE WHEN pm.meta_key = ‘_shipping_address_1’ and p.ID = pm.post_id THEN pm.meta_value END ) as shipping_address_1, max( CASE WHEN pm.meta_key = ‘_shipping_city’ and p.ID = pm.post_id THEN pm.meta_value END ) as city, max( CASE WHEN pm.meta_key = ‘_shipping_postcode’ and p.ID = pm.post_id THEN pm.meta_value END ) as postcode, max( CASE WHEN pm.meta_key = ‘_shipping_state’ and p.ID = pm.post_id THEN pm.meta_value END ) as shipping_state, 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 = ‘_paid_date’ and p.ID = pm.post_id THEN pm.meta_value END ) as paid_date, ( select group_concat( order_item_name separator ‘, ‘ ) from wp_woocommerce_order_items where order_id = p.ID ) as order_items from wp_posts p join wp_postmeta pm on p.ID = pm.post_id join wp_woocommerce_order_items oi on p.ID = oi.order_id where post_type = ‘shop_order’ and post_date BETWEEN ‘2023-01-01’ AND ‘2023-12-31’ and post_status = ‘wc-completed’ group by p.ID ORDER BY `first_name` ASC, `paid_date` ASC “); echo “Order id | Name | Order_total | Paid date | |
“.$wp_posts->order_id.” | “; echo ““.$wp_posts->first_name.” “.$wp_posts->last_name.” | “; echo ““.$wp_posts->billing_email.” | “; echo ““.$wp_posts->order_total.” | “; echo ““.$dateVal.” | “; echo “
“.$wp_posts->order_items.” | “; $count++; } echo “
Users-Total-orders-list-2024
get_results(“select p.ID as order_id, 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 = ‘_shipping_first_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as first_name, max( CASE WHEN pm.meta_key = ‘_shipping_last_name’ and p.ID = pm.post_id THEN pm.meta_value END ) as last_name, max( CASE WHEN pm.meta_key = ‘_shipping_address_1’ and p.ID = pm.post_id THEN pm.meta_value END ) as shipping_address_1, max( CASE WHEN pm.meta_key = ‘_shipping_city’ and p.ID = pm.post_id THEN pm.meta_value END ) as city, max( CASE WHEN pm.meta_key = ‘_shipping_postcode’ and p.ID = pm.post_id THEN pm.meta_value END ) as postcode, max( CASE WHEN pm.meta_key = ‘_shipping_state’ and p.ID = pm.post_id THEN pm.meta_value END ) as shipping_state, 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 = ‘_paid_date’ and p.ID = pm.post_id THEN pm.meta_value END ) as paid_date, ( select group_concat( order_item_name separator ‘, ‘ ) from wp_woocommerce_order_items where order_id = p.ID ) as order_items from wp_posts p join wp_postmeta pm on p.ID = pm.post_id join wp_woocommerce_order_items oi on p.ID = oi.order_id where post_type = ‘shop_order’ and post_date BETWEEN ‘2024-01-01’ AND ‘2024-12-31’ and post_status = ‘wc-completed’ group by p.ID ORDER BY `first_name` ASC, `paid_date` ASC “); echo “Order id | Name | Order_total | Paid date | |
“.$wp_posts->order_id.” | “; echo ““.$wp_posts->first_name.” “.$wp_posts->last_name.” | “; echo ““.$wp_posts->billing_email.” | “; echo ““.$wp_posts->order_total.” | “; echo ““.$dateVal.” | “; echo “
“.$wp_posts->order_items.” | “; $count++; } echo “