Created
December 7, 2015 22:05
-
-
Save maxrice/d7fc4dd82238275437b9 to your computer and use it in GitHub Desktop.
WooCommerce Customer/Order CSV Export - add order customer IP column
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 customer IP column header | |
function wc_csv_export_add_customer_ip_column_header( $column_headers ) { | |
$new_headers = array( | |
'customer_ip' => 'customer_ip', | |
); | |
return array_merge( $column_headers, $new_headers ); | |
} | |
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_add_customer_ip_column_header' ); | |
// add customer IP column data | |
function wc_csv_export_add_customer_ip_column_data( $order_data, $order, $csv_generator ) { | |
$custom_data = array( | |
'customer_ip' => $order->customer_ip_address, | |
); | |
$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_add_customer_ip_column_data', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment