Forked from woogist/woocommerce-customer-order-csv-export-add-additional-columns.php
Last active
March 31, 2020 03:53
-
-
Save tamarazuk/d48ca1e8cb3ed227a27d to your computer and use it in GitHub Desktop.
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( | |
'column_1' => 'Column 1', | |
'column_2' => 'Column 2', | |
// 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, $csv_generator ) { | |
$custom_data = array( | |
'column_1' => get_post_meta( $order->id, 'some_meta_key', true ), | |
'column_2' => get_post_meta( $order->id, 'some_other_meta_key', true ), | |
// add other row data here in the format column_key => data | |
); | |
$new_order_data = array(); | |
if ( isset( $csv_generator->order_format ) && ( 'default_one_row_per_item' == $csv_generator->order_format || 'legacy_one_row_per_item' == $csv_generator->order_format ) ) { | |
foreach ( $order_data as $data ) { | |
$new_order_data[] = array_merge( (array) $data, $custom_data ); | |
} | |
} else { | |
$new_order_data = array_merge( $order_data, $custom_data ); | |
} | |
return $new_order_data; | |
} | |
add_filter( 'wc_customer_order_csv_export_order_row', 'wc_csv_export_modify_row_data', 10, 3 ); |
Hello, how can I add the custom field with tax rate in percent? Could you help me?
Does this not work for Custom CSV export, with multiple lines per item?
I had to remove isset( $csv_generator->order_format ) &&
from line 26 to get this to work after version 4.0.3.
The new "Custom" option in version 4.0.3 is great; however, I'm pulling in some extra user meta data, so, this above function is still quite necessary. I substituted "get_post_meta" with "get_user_meta" and voila, it worked.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Can you advice how i can show a specific product custom attribute (the value is different for each product) as a column in the exported csv? and what is the code snippets to use please?