woocommerce通过sql导出订单信息

行云流水
2022-08-11 / 0 评论 / 280 阅读 / 正在检测是否收录...

说明

需要将订单信息导出来,记录sql语句。

导出订单信息

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)

取消
只有登录/注册用户才可评论