In this article, we’re going to use the WP All Export plugin for our order export examples. To follow along, use our convenient sandbox feature and select WooCommerce Store as the demo type.

Advanced Order Exports

This article describes advanced order exports for WooCommerce and assumes that you are already familiar with WP All Export. If you are not, please see one of these articles:

WooCommerce Export Orders to CSV
WooCommerce Export Orders to Excel

Our advanced topics include:

Create Custom Order Export Columns Using PHP

In our articles on exporting WooCommerce orders to CSV or Excel, we demonstrated how to create custom columns by combining two fields such as merging a customer’s first and last names into a single column. Here’s a quick refresher...

In the Drag & Drop interface, click the Add Field button:

Advanced Order Export Drag and Drop

This opens a form that allows you to create a new order export field using these steps:

  1. Select the Custom export field option.
  2. In the text box below this option, drag and drop the “Billing First Name” and “Billing Last Name” fields from Available Data Customer. Put a space between them.
  3. In the Column name box at the top, enter “Name”.

Your form should look like this:

WooCommerce Order Export Add Field

If you click the green Preview button on the bottom, you will see that the Name field does indeed combine the first and last names. However, sometimes you need more advanced capabilities.

Dismiss the preview (if open), then click the blue Save button on the bottom right.

Let’s say that you want to add a shipping method to your orders based on their weight. If the weight is less than 10lbs, the order should be sent using 'USPS'. If the weight is between 10-30lbs, 'DHL' should be used. Finally, if the weight is more than 30lbs, then 'Knight-Swift Freight' will be used. 

Here’s how to do this:

  1. Click the Add Field button to re-open the Add Field to Export form.
  2. Select the Custom export field option.
  3. In the text box below this option, enter “[output_shipping({Weight})]” without the quotes. This is known as a function call. Note the reference to the field inside the curly brackets.
  4. In the Function Editor, enter the following PHP function:
function output_shipping($weight){
	if($weight <= 10) {
		return "USPS";
	} else if ($weight > 10 && $weight < 30) {
		return "DHL";
	} else if ($weight >= 30) {
		return "Knight-Swift Freight";
	}
}
  1. Click the Save Functions button near the bottom of the form.
  2. Enter “Shipping Method” in the Column name box near the top of the form.

The form should appear as follows:

WooCommerce Advanced Order Export Field

Click the Save button to save the field and close the form.

Back in the Drag & Drop interface, drag the Items -> Advanced -> Weight field from the Available Data panel into the column selection area, then click the Preview button:

Order Export Drag & Drop Preview

As you can see in the Shipping Method column, the output_shipping function appears to be working correctly.

For more information on using PHP during an export, please see https://www.wpallimport.com/documentation/custom-wordpress-export-php/.

You can also learn more about custom export fields here: https://www.wpallimport.com/documentation/custom-export-fields/.

XML Feeds for WooCommerce Order Exports

Simple Order Export Feeds

Creating a simple XML export is just as easy as generating a CSV or Excel export file. In the Export Type panel of the Drag & Drop interface, choose Feed instead of Spreadsheet, and then just specify Simple XML Feed, as shown here:

WooCommerce Advanced Order Export Type

If you proceed to export the orders, the resulting export file will contain the default XML structure. For example, here is the output for three orders containing the three columns of OrderID, OrderKey, and Title:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <post>
    <OrderID>223</OrderID>
    <OrderKey>wc_order_5e7596fb60908</OrderKey>
    <Title>Order - March 21, 2020 @ 04:24 AM</Title>
  </post>
  <post>
    <OrderID>224</OrderID>
    <OrderKey>wc_order_5e7596fbcaa06</OrderKey>
    <Title>Order - March 21, 2020 @ 04:24 AM</Title>
  </post>
  <post>
    <OrderID>225</OrderID>
    <OrderKey>wc_order_5e7596fc3c740</OrderKey>
    <Title>Order - March 21, 2020 @ 04:24 AM</Title>
  </post>
</data>

If one of the fields you are exporting has multiple elements in the same field, those elements will be separated by a pipe delimiter (I). For example, here is what an image field looks like when it contains multiple images:

XML imageURL

You have only a few options to change the output of a simple feed. The main way to do this is simply to add, delete, rename, and/or reorder the columns in the column selection editor, just as you would for a CSV or Excel export. When you do this, the resulting feed structure will change to match your column selection.

Advanced XML Feeds for Order Exports

To gain complete control over your XML output for order exports, start by choosing Custom XML Feed as the Feed type:

Order Export Custom XML Feed

WP All Export responds by opening its XML Editor:

Advanced Order Export XML Editor

This editor allows you to manually create your XML structure. You typically start this process by dragging fields from the Available Data panel between the <!-- BEGIN LOOP --> and <!-- END LOOP --> comments, which mark the beginning and end of the loop that will process all the orders that match your filters.

The <post> and </post> elements are the default way to mark the start and end of each record, but you don’t have to use them. For example, in the screenshot below, we have changed these record elements to <order> and </order> while including the order ID as an attribute named “id”. Using the Available Data panel, we also dragged over the Billing First Name, Billing Last Name, and Weight fields into the XML Editor:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <!-- BEGIN LOOP -->
  <order id="{Order ID}">
    <BillingFirstName>{Billing First Name}</BillingFirstName>
    <BillingLastName>{Billing Last Name}</BillingLastName>
    <Weight>{Weight}</Weight>
  </order>
  <!-- END LOOP -->
</data>

When we do this, note that WP All Export wraps each field in its own corresponding XML element, i.e. the Billing First Name field is automatically embedded between the <BillingFirstName> and </BillingFirstName> tags. 

These element names are not set in stone. Just as we changed the record element to <order>, we can also remove the word “Billing” from our name elements. 

We can also modify this schema in other ways. For example, by adding the quantity as an attribute to the Weight element in the XML Editor:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <!-- BEGIN LOOP -->
  <order id="{Order ID}">
    <FirstName>{Billing First Name}</FirstName>
    <LastName>{Billing Last Name}</LastName>
    <Weight quantity="{Quantity}">{Weight}</Weight>
  </order>
  <!-- END LOOP -->
</data>

This will result in the following XML output:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <order id="223">
    <FirstName>Abdel</FirstName>
    <LastName>Wolfendale</LastName>
    <Weight quantity="5"/>
  </order>
  <order id="224">
    <FirstName>Elonore</FirstName>
    <LastName>Goreisr</LastName>
    <Weight quantity="12"/>
  </order>
  <order id="225">
    <FirstName>Mike</FirstName>
    <LastName>Jones</LastName>
    <Weight quantity="6"/>
  </order>
</data>

…and so on through the rest of the orders.

Our ability to control a custom order feed doesn’t stop there, either. Remember the output_shipping function that we created in the Custom Export Columns Using PHP section of this article?

We can embed that same function in our custom XML template:

XML Editor
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <!-- BEGIN LOOP -->
  <order id="{Order ID}">
    <FirstName>{Billing First Name}</FirstName>
    <LastName>{Billing Last Name}</LastName>
    <Weight quantity="{Quantity}">{Weight}</Weight>
    <ShippingMethod>[output_shipping({Weight})]</ShippingMethod>
  </order>
  <!-- END LOOP -->
</data>

Here is the XML output:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <order id="223">
    <FirstName>Abdel</FirstName>
    <LastName>Wolfendale</LastName>
    <Weight quantity="5"/>
    <ShippingMethod>USPS</ShippingMethod>
  </order>
  <order id="224">
    <FirstName>Elonore</FirstName>
    <LastName>Goreisr</LastName>
    <Weight quantity="12"/>
    <ShippingMethod>FedEx</ShippingMethod>
  </order>
  <order id="225">
    <FirstName>Mike</FirstName>
    <LastName>Jones</LastName>
    <Weight quantity="6"/>
    <ShippingMethod>USPS</ShippingMethod>
  </order>
</data>

The flexibility doesn’t end there, either. You can edit the XML header to define a specific schema. In fact, you can create any kind of custom XML feed that you want with these features. That’s the power of WP All Export!

Advanced Order Export Filters

Nesting Order Export Filters

In our articles on exporting WooCommerce orders to CSV or Excel, we demonstrated how to create filters involving one or more conditions. For example, this filter selects orders with an Order Total between $25 and $50 and an Order Status of “wc-pending”:

WooCommerce Advanced Order Export Filtering Options

Note that each of these conditions is joined with an AND operator, meaning that orders must meet all of the conditions to pass the filter.

But what if we want a more advanced filter, one that selects orders with an Order Total between $25 and $50, or an Order Status of “wc-pending” and an Order Total > 50?

This is how we would write this by hand:

Order Total >= 25 AND Order Total <= 50 OR (Order Status = “wc-pending AND Order Total > 50)

Note the round brackets after the OR condition.

How do we represent this pair of brackets in the interface? We simply drag the last Order Total filter rule inside the Order Status filter rule:

Advanced Order Export for WooCommerce Nested Filters 02

Relative Date Filters for Order Exports

In many export situations, especially for recurring scheduled exports, we don’t want to have to specify exact date filters because these might have to change each time an export is run.

Instead, we want to specify relative dates. For example, this filter selects only those orders with an Order Date newer than two years ago:

Advanced Order Export Relative Date Filters

This filter returns orders with an order date that equals last month:

Relative Date Filters Version 2

Note, this won’t return any records for the sandbox data because it is too old for that, but terms like “last month” or “this month” are very common in export scenarios.

The accepted relative data formats can be found here: https://www.php.net/manual/en/datetime.formats.relative.php.

Filtering Order Exports With PHP

If you need even more advanced order filter capabilities, WP All Export allows you to create any filter imaginable using its API, which is a large set of WordPress hooks that you can find here: https://www.wpallimport.com/documentation/advanced/action-reference/.

Using these hooks requires PHP programming skills. For example, here is a filter that you might use to export only product variations whose parents are not set to 'draft'. This is especially useful for Google Merchant Center exports as they apply Status filters directly to variations by default:

function exclude_drafts_from_gmc_export($articles, $options, $export_id) {

    // Only filter GMC exports.
    if ($options["xml_template_type"] == "XmlGoogleMerchants") {

        // Process every exported product.
        foreach ($articles as $key => $article) {

            // If IDs aren't set to be exported, do nothing.
            if ( ! empty($article['id']) ) {
                $post_id = $article['id'];
                $parent_id = wp_get_post_parent_id($post_id);

                // Check the parent's Status.
                if ( get_post_status($parent_id) == "draft" ) {

                    // Don't export variation if parent is 'draft'.
                    unset($articles[$key]);

                }
            }
        }
    }

    return $articles;
}
add_filter('wp_all_export_csv_rows', 'exclude_drafts_from_gmc_export', 10, 3);

Walking you through this code is beyond the scope of this article. The point is, WP All Export offers this kind of advanced capability. And, of course, the support team is always available should you need help! 

Large WooCommerce Order Exports

Large order exports can cause two types of problems:

  1. Servers limit the amount of time a process can run. If a process exceeds this time limit, it is said to “time out”, meaning it will fail. This is necessary because long-running processes might consume all of a server’s resources, causing it to stop working. To avoid this problem, large WooCommerce order exports are typically broken down into batches. But if the batch size is too big, timeouts will still occur.
  2. Each server typically imposes a size limit for the creation of files. Otherwise, a file might use all the available disk space. If the WooCommerce store is big enough, a large order export might exceed the allowable size limit.

Fortunately, WP All Export makes it easy to solve both of these problems.

The Export Settings interface has an Advanced Options panel that contains the options you need to manage large WooCommerce order exports:

Advanced Order Export for WooCommerce Settings

The first option manages the batch size used to process the order export. If your export process fails due to a timeout, lower this number and try again. Just be aware that there is typically a sweet spot for batch size. Set it too small and you will greatly increase the number of batches required to complete the export, which may increase the amount of time required to process the export. Set it too big and you’ll get the timeout error.

To avoid exceeding file-size limits, the second option lets you split your export file into multiple files consisting of a maximum record count. The sweet spot rule applies here, too. Set this number too low and you’ll end up with too many files. Set it too high and you may trigger the maximum file size limit.

Other Advanced Order Export Features

WPML Plugin Image

WP ALL Export takes pride in the fact that it can handle all simple export tasks quickly and easily, yet still has the tools to handle the most complex export tasks imaginable.

In addition to the topics described in this article, other advanced features include:

  • The ability to use WP_Query to perform order queries that can’t be performed any other way, at least not efficiently
  • Export your WooCommerce orders in different languages using WPML
  • Full developer support including an Add-on API and WP-CLI

Related Information

WooCommerce Export Orders to CSV

WooCommerce Export Orders to Excel

Best WooCommerce Themes

Best Host for WooCommerce

Best Plugins for WooCommerce

Best WooCommerce Shipping Plugins

8 Best Photography Plugins for WooCommerce

Best WooCommerce Multilingual Plugins

WooCommerce How to Add Products

Advanced Order Export for WooCommerce

Related Videos