WooCommerce Customer / Order XML Export: Developer Documentation

This extension was designed to be as flexible as possible. To that end, filters are used to allow you to customize the generated XML or replace it entirely.

Please be aware that this document is meant for developers to use as a reference, and some of these code samples are structural samples rather than working snippets. We do not support or do plugin customizations as per our support policy. You can get in touch with an expert for help with customizations.

Settings Filters

↑ Back to top

Add / Remove Settings

apply_filters( 'wc_customer_order_xml_export_suite_settings', $settings, $section_id );
Use this filter to add or remove settings from the XML export pages. The $settings array is the array of settings for the given tab, identified by the current $section_id.

File Name / Format Filters

↑ Back to top
You can modify the filename or format for either the order or customer export using these filters.

File Name

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_filename', $post_replace_file_name, $pre_replace_file_name, $ids );
Use this filter to change the generated file name for the XML export. This affects the file name for both downloads and uploads, but not HTTP POST (which has no file name). The $ids parameter is an array of order or customer IDs being exported. Here’s some sample code for changing the date/time format of the %%timestamp%% variable: You can also add merge variables for the file name.
apply_filters( 'wc_customer_order_xml_export_suite_filename_variables', $variables, $ids, $export_type );
Use this filter to add variables into the array of accepted merge tag variables. Here’s a sample that adds %%order_numbers%% as a placeholder / merge variable:

Output Format

↑ Back to top
The format of the XML generated is filterable, so that you can completely change the format of the XML generated or generate an entirely different kind of file.
apply_filters( 'wc_customer_order_xml_export_suite_format_definition', $definition, $export_type, $format );
Use this filter to change the format definitions for the outputted XML. Useful if, for example, you require special character support and must change the character encoding. See this example snippet as a starting point. You can also use more specific filters to globally change definitions.

XML Version

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_xml_version', $xml_version );
Use this filter to change the XML version specified in the generated XML. This is 1.0 by default.

XML Encoding

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_xml_encoding', $xml_encoding );
Use this filter to change the XML encoding specified in the generated XML. This is UTF-8 by default. Here’s some sample code for changing to ISO-8859-1:
<?php
function wc_sample_xml_change_xml_encoding() {
return 'ISO-8859-1';
}
add_filter( 'wc_customer_order_xml_export_suite_xml_encoding', 'wc_sample_xml_change_xml_encoding' );

Query Args

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_query_args', $query_args, $export_type );
Use this filter to change the WP_Query args used for selecting orders to export. The $query_args array provides the WP_Query arguments, while $export_type should be either ‘customers’ or ‘orders’. For example, here’s a snippet that will adjust the orders query to only include orders that have at least one associated refund.

Root Element Format

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_orders_xml_data', array( 'Order' => $orders ), $orders );
This defines the root level element, Orders and passes in an array of WC_Order order objects that are used when generating the individual XML for each order.

Order Element Format

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_order_data', array(
    'OrderId'            => $order->id,
    'OrderNumber'        => $order->get_order_number(),
    // ...etc
), $order );
This defines the format for each individual order element and passes in an WC_Order order object for each order being exported. You can view view this example snippet to add VAT Numbers per order.

Line Item Element Format

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_order_line_item', array(
    'SKU'       => $product->get_sku(),
    'Quantity'  => $item['qty'],
    'Price'     => $product->get_price(),
    'LineTotal' => $item['line_total'],
    'Meta'      => $item_meta
), $order, $item );
This defines the format for each individual line item within an order, and passes in the WC_Order order object for the line item’s order, and the $item array which contains the information about the line item. Here’s an example of adding Product Add-ons in a nested format to the LineItems tag:

Order Note Element format

↑ Back to top
// @since 1.7.0
$order_note[] = apply_filters( 'wc_customer_order_xml_export_suite_order_note', array(
    'Date'    => $note->comment_date,
    'Author'  => $note->comment_author,
    'Content' => str_replace( array( "\r", "\n" ), ' ', $note->comment_content ),
), $note, $order );
This defines the format for each order note within an order, and passes in the $note object, which contains order note comment object, along with the WC_Order order object for the order.

Entire Output

↑ Back to top
apply_filters( 'wc_customer_order_xml_export_suite_orders_xml', $generated_xml, $xml_array, $orders, $ids, $export_format );
After the XML has been generated, this filter is applied before returning the XML for each order, and provides access to the WC_Customer_Order_XML_Export_Suite_Handler class instance. Here you can replace the entire output with something custom, such as a CSV. This will not provide the entire XML file, but rather, the XML for each order.

Sample Code

↑ Back to top
While you can use these filters for doing basic customizations within your theme’s functions.php file, we strongly recommend creating a custom plugin so that if you switch themes you don’t lose your customizations. For more information on creating a custom plugin for your WooCommerce store, read this article.

HTTP POST Filters

↑ Back to top
If you’re using the automatic export over HTTP POST, there is a filter available to change the arguments used for wp_remote_post().
apply_filters( 'wc_customer_order_xml_export_suite_http_post_args', array(
    'timeout'     => 60,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking'    => true,
    'headers'     => array(
        'accept'       => 'application/xml',
        'content-type' => 'application/xml' ),
    'body'        => $xml,
    'cookies'     => array(),
    'user-agent'  => "PHP " . PHP_VERSION
) );
For example, if the web service you’re posting to requires authentication, you could use this filter to add HTTP basic auth to the headers:
function wc_xml_export_suite_add_http_post_basic_auth( $args ) {

    $args['headers']['Authorization'] = 'Basic ' . base64_encode( 'your_username:your_password' );
    
    return $args;
}
add_filter( 'wc_customer_order_xml_export_suite_http_post_args', 'wc_xml_export_suite_add_http_post_basic_auth' );

Exporting each order individually

↑ Back to top
If you’d like to export each order individually (instead of exporting a batch of orders at some time interval), you can use the built-in setting for auto-exports to do so. However, if you want to do so for only certain export types, you could use something like this:
function wc_xml_export_suite_export_order_on_payment( $order_id ) {

    $export = new WC_Customer_Order_XML_Export_Suite_Handler( $order_id );
    
    // for FTP
    $export->upload();
    
    // uncomment for HTTP POST
    // $export->http_post();
}
add_action( 'woocommerce_payment_complete', 'wc_xml_export_suite_export_order_on_payment' );

User Documentation

↑ Back to top
Return to user documentation →
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.