Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save woogist/8838110 to your computer and use it in GitHub Desktop.
Save woogist/8838110 to your computer and use it in GitHub Desktop.
WooCommerce Customer/Order CSV Export: Renaming / Removing / Reordering Columns
<?php
// rename a column
function wc_csv_export_rename_column( $column_headers ) {
// rename the order_notes column to notes
// make sure to not change the key (`order_notes`) in this case
// as this matches the column to the relevant data
// simply change the value of the array to change the column header that's exported
$column_headers['order_notes'] = 'Notes';
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_rename_column' );
// remove a column
function wc_csv_export_remove_column( $column_headers ) {
// the list of column keys can be found in class-wc-customer-order-csv-export-generator.php
unset( $column_headers['coupon_items'] );
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_remove_column' );
// reorder columns
function wc_csv_export_reorder_columns( $column_headers ) {
$new_column_headers = array();
foreach ( $column_headers as $column_key => $column_name ) {
$new_column_headers[ $column_key ] = $column_name;
if ( 'order_number' == $column_key ) {
// add order total immediately after order_number
$new_column_headers['order_total'] = 'order_total';
// remove order total from the original set of column headers, otherwise it will be duplicated
unset( $column_headers['order_total'] );
}
}
return $new_column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_reorder_columns' );
@tnog
Copy link

tnog commented Jul 22, 2014

For removing columns, how would you do so far multiple columns?

@Riply
Copy link

Riply commented Aug 20, 2014

Hey buddy.

Within this loop:
// remove a column
function wc_csv_export_remove_column( $column_headers ) {
// the list of column keys can be found in class-wc-customer-order-csv-export-generator.php
unset( $column_headers['coupon_items'] );
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_remove_column' );

You need to repeat "unset( $column_headers['coupon_items'] );" per column that you want to remove. Namely "coupon_items".

@s011420
Copy link

s011420 commented Aug 15, 2015

where should i put these code in ?

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