Created
February 6, 2014 03:46
-
-
Save woogist/8838110 to your computer and use it in GitHub Desktop.
WooCommerce Customer/Order CSV Export: Renaming / Removing / Reordering Columns
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 | |
// 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' ); |
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".
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
For removing columns, how would you do so far multiple columns?