Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxrice/8762962 to your computer and use it in GitHub Desktop.
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 );
@torrecapistran
Copy link

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