'How to export WooCommerce order

I have one scenario , in which I only have a database dump.

I have to write SQL query in PHPMyAdmin to get ALL the WooCommerce orders , and then EXPORT CSV from PHPMyAdmin only.

Here , I have found the minimum required CSV column for ORDER IMPORT : https://docs.google.com/spreadsheets/d/16ub-_xEJD9V5UL6d_rTQ4LLu0PT9jXJ0Ti-iirlKyuU/edit#gid=956100262

The First 2 columns in SAMPLE CSV , I can get via the following SQL query.

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 = '_order_total' and p.ID = pm.post_id THEN pm.meta_value END ) as order_total
FROM
    wp_posts p 
    join wp_postmeta pm on p.ID = pm.post_id

WHERE
    post_type = 'shop_order'

GROUP BY
    p.ID

how do I get the last 3 columns ?

For IMPORT , I will write a PHP script , so in which table do I need to insert data ?

PS : From here I get a sample CSV link : https://docs.woocommerce.com/document/customer-order-csv-import-suite/



Solution 1:[1]

Tested importing the sample CSV provided in the OP. I was able to import the CSV successfully using this free WooCommerce order import plugin ( Version 2.2.2 ). Saved the file as UTF-8 CSV and uploaded it. Tested on the below environment

WooCommerce 6.4
WordPress 5.9.3

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mujuonly