Created
February 2, 2014 04:11
-
-
Save maxrice/8762962 to your computer and use it in GitHub Desktop.
WooCommerce Customer/Order CSV Export - Add additional data to exports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
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.
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
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.