Last active
August 24, 2020 03:11
-
-
Save rynaldos-zz/0811544a7f185fece60f653c353dc0ec to your computer and use it in GitHub Desktop.
[WooCommerce] Add order export column for WooCommerce EU VAT number to Order / Customer CSV Exporter
This file contains hidden or 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
| // add custom column headers | |
| function wc_csv_export_modify_column_headers( $column_headers ) { | |
| $new_headers = array( | |
| 'column_1' => 'VAT Number', | |
| // 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, 'VAT Number', 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment