Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save maxrice/8762962 to your computer and use it in GitHub Desktop.

Select an option

Save maxrice/8762962 to your computer and use it in GitHub Desktop.
WooCommerce Customer/Order CSV Export - Add additional data to exports
<?php
// add custom column headers
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'lll_group' => 'LLL Group',
'registrant_type' => 'Registrant Type',
'partner_spouse' => 'Partner/Spouse',
// add other column headers here in the format column_key => Column Name
);
return array_merge( $column_headers, $new_headers );
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_modify_column_headers' );
// set the data for each for custom columns
function wc_csv_export_modify_row_data( $order_data, $order ) {
$custom_data = array(
'lll_group' => get_post_meta( $order->id, '_lll_group', true ),
'registrant_type' => get_post_meta( $order->id, 'Registrant Type', true ),
'partner_spouse' => get_post_meta( $order->id, 'Partner/Spouse', true ),
// add other row data here in the format column_key => data
);
return array_merge( $order_data, $custom_data );
}
add_filter( 'wc_customer_order_csv_export_order_row', 'wc_csv_export_modify_row_data', 10, 2 );
@Kelowna

Kelowna commented Mar 16, 2014

Copy link
Copy Markdown

What do we use if we want to export as Legacy? This doesn't work for that and the old code doesn't work for that.

@justincone

Copy link
Copy Markdown

I have the same issue as Kelowna. I'm using Legacy (one item per row), and this code doesn't appear to work for that.

@torrecapistran

Copy link
Copy Markdown

This worked great, thanks. Is there a way to do this without editing the core plugin file? Perhaps a way to just add to a child theme functions.php or other sub file? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment