woocommerce通过sql导出订单信息

it不难
2022-08-11 / 0 评论 / 13 阅读 / 正在检测是否收录...

说明

导出订单信息

select
        ID as '订单ID',
        post_date as '创建时间',
        post_date_gmt as '支付时间',
        post_excerpt as '物流单号',
        (select meta_value from wp_postmeta where post_id = ID and  meta_key = '_order_total') as '支付金额',
        (select meta_value from wp_postmeta where post_id = ID and  meta_key = '_order_currency') as '币种',
        (select replace(meta_value, ',', ' ') from wp_postmeta where post_id = ID and  meta_key = '_shipping_address_index') as '通讯地址',
        (select meta_value from wp_postmeta where post_id = ID and  meta_key = '_shipping_phone') as '电话'
from
        wp_posts
where
        post_type='shop_order'
and
        post_status in ('wc-completed', 'wc-processing')
order by
        ID
into outfile "order.csv" fields terminated by ','  escaped by '' lines terminated by "\r\n";

导出商品名称和价格

select 
  post_title as '商品名', 
  (select meta_value from wp_postmeta where post_id = ID and meta_key = '_price') as '金额'  
from wp_posts  
where  
  post_type = 'product' 
and 
  comment_status = 'open' 
into outfile "order.csv" fields terminated by ','  escaped by '' lines terminated by "\r\n";
0

评论 (0)

取消