The EDD Payment Export & Reports plugin allows you to export details of your customers orders to a CSV. The plugin contains support for most of the standard Easy Digital Download payment fields out of the box, as well as supporting information from well-known EDD extensions such as Software Licensing.

Sometimes however, you may have custom checkout fields that you want to export alongside the standard fields. In this case, you can alter the behaviour of the plugin to include your fields via a set of WordPress filters. These will let you register additional fields, and specify how they the output for those fields should be gathered / calculated. Simply drop these into your theme’s functions.php file or a functionality plugin, then you’ll be free to keep updating the main plugin without fear of losing your changes.

In the example below we’re going to create a “Full name” field that will simply concatenate the first, and last name of the purchases.

There are two functions you’ll need to define. The first registers the field with the plugin, making it available to choose for export. This function also tells the plugin what function it should call to generate the output for this field.

public function lw_edd_dash_export_fields( $fields ) {
    // Make the key here unique.
    $fields['my_custom_field'] = array(
        // This is the field name, displayed on the export screen.
        'title' => __( 'Customer Full Name', 'edd_dash' ),
        // Specify whether the field is available on order summary and / or order line exports.
        'display_on' => array( 'order_summaries', 'order_lines' ),
        // A function that outputs the data for this field for an individual payment record.
        'generator' => 'lw_render_my_field' ),
    );
}
add_filter( 'edd_dash_export_fields', ‘lw_edd_dash_export_fields' );

Here – we’ve defined a new field that will show up as “Customer Full Name” on the export screen, and in the heading of the column in the CSV. When the plugin generates the CSV, it will call the function lw_render_my_field() to generate the output for our field.

/**
 * This function will be called for each line to produce the output for this field.
 */
function lw_render_my_field( $payment ) {
    // Return the output for this field for $payment
    // Put your logic here.
    return $payment->user_info['first_name'] . ' ' . $payment->user_info['last_name'];
}

Our “rendering” function will be passed a $payment variable which will contain the basic information about the payment already. Here we’re picking up the first and last name, and returning them as a single string. Of course – you could load up a custom value here, and return that if you have something specific you want to grab.


This entry was posted in .
Bookmark the permalink.