Exporting WooCommerce orders in CSV or XML format is essential for order management, reporting, or integrating with third-party platforms like accounting software. While many plugins provide this functionality, it’s also possible to export orders manually using custom code. In this guide, we’ll walk you through how to export WooCommerce orders in CSV or XML format without relying on a plugin.
Why Export WooCommerce Orders in CSV or XML?
Exporting orders can help you:
- Manage Orders Offline: Use spreadsheets to analyse and track orders.
- Integration with Accounting Software: Export data in CSV or XML for use with external platforms.
- Generate Custom Reports: Create order summaries, revenue reports, and more.
Step 1: Export Orders as CSV
The following code generates a CSV file containing WooCommerce orders. Add it to your theme’s functions.php file or in a child theme.
/*
* Snippet: How to Export WooCommerce Orders in CSV or XML Format Without a Plugin – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1595
* Tested with WooCommerce 10.7.0
* "This function exports WooCommerce orders to a CSV file"
*/
function wcsuccess_export_orders_to_csv() {
if ( isset( $_GET['export_orders'] ) ) {
$orders = wc_get_orders( array( 'limit' => -1 ) );
header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment;filename=orders.csv' );
$output = fopen( 'php://output', 'w' );
fputcsv( $output, array( 'Order ID', 'Customer', 'Total', 'Date', 'Status' ) );
foreach ( $orders as $order ) {
fputcsv( $output, array(
$order->get_id(),
$order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
$order->get_total(),
$order->get_date_created()->date( 'Y-m-d H:i:s' ),
$order->get_status(),
));
}
fclose( $output );
exit;
}
}
add_action( 'admin_init', 'wcsuccess_export_orders_to_csv' );
How This Works
- Admin Hook: The code hooks into
admin_initto detect when the export is requested via a query parameter (?export_orders). - CSV Output: The orders are retrieved, and their details are written to a CSV file, which is then downloaded.
To trigger the export, go to your WordPress admin and navigate to:https://yourwebsite.com/wp-admin/?export_orders
Step 2: Export Orders as XML
If you need to export orders in XML format, use the following code:
/*
* Snippet: How to Export WooCommerce Orders in CSV or XML Format Without a Plugin – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1595
* Tested with WooCommerce 10.7.0
* "This function exports WooCommerce orders to an XML file"
*/
function wcsuccess_export_orders_to_xml() {
if ( isset( $_GET['export_orders_xml'] ) ) {
$orders = wc_get_orders( array( 'limit' => -1 ) );
header( 'Content-Type: text/xml' );
header( 'Content-Disposition: attachment;filename=orders.xml' );
$xml = new SimpleXMLElement( '<Orders/>' );
foreach ( $orders as $order ) {
$order_xml = $xml->addChild( 'Order' );
$order_xml->addChild( 'OrderID', $order->get_id() );
$order_xml->addChild( 'Customer', $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() );
$order_xml->addChild( 'Total', $order->get_total() );
$order_xml->addChild( 'Date', $order->get_date_created()->date( 'Y-m-d H:i:s' ) );
$order_xml->addChild( 'Status', $order->get_status() );
}
echo $xml->asXML();
exit;
}
}
add_action( 'admin_init', 'wcsuccess_export_orders_to_xml' );
How This Works
- XML Generation: The code creates an XML structure and fills it with order details.
- Admin Hook: The export is triggered through a URL query parameter (
?export_orders_xml).
To trigger the export, go to:https://yourwebsite.com/wp-admin/?export_orders_xml
Step 3: Add Export Links to Admin Dashboard
For convenience, you can add export links directly to your WooCommerce admin dashboard.
/*
* Snippet: How to Export WooCommerce Orders in CSV or XML Format Without a Plugin – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1595
* Tested with WooCommerce 10.7.0
* "This function adds export links to the WooCommerce dashboard"
*/
function wcsuccess_add_export_links() {
echo '<a href="' . admin_url( '?export_orders' ) . '" class="button">Export Orders (CSV)</a>';
echo '<a href="' . admin_url( '?export_orders_xml' ) . '" class="button" style="margin-left: 10px;">Export Orders (XML)</a>';
}
add_action( 'woocommerce_reports_sidebar', 'wcsuccess_add_export_links' );
Best Use Cases for Exporting Orders
- Financial Reporting: Export orders for accounting or tax purposes.
- Data Backup: Keep an offline backup of order data in CSV or XML format.
- Third-Party Integration: Use exported files to integrate with fulfilment or accounting software.
Conclusion
Exporting WooCommerce orders as CSV or XML without a plugin gives you control over your data and reduces the need for extra tools. Whether you need an export for reporting, backup, or integration purposes, these methods offer a lightweight and efficient solution.
Remember to test your changes in a staging environment before applying them to your live site. Use a child theme to ensure your modifications are protected. For additional customisation, explore our wp-config generator to streamline your setup.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

