Last active
July 20, 2023 05:24
-
-
Save webtoffee-git/a081185398546c3b074c74696e8a5ec6 to your computer and use it in GitHub Desktop.
Add additional meta and role to export CSV - Order Export Import Plugin For WooCommerce (https://www.webtoffee.com/product/order-import-export-plugin-for-woocommerce/)
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 // do not copy this line | |
/ here 'meta:meta_key_1' is the key used for the internal use. | |
// meta key 1 is used as the header in csv. | |
// meta_key_1 is the meta key present in the database | |
add_filter('hf_alter_csv_header', 'hf_csv_order_add_more_columns', 10, 1); | |
function hf_csv_order_add_more_columns($csv_columns) { | |
$csv_columns['meta:meta_key_1'] = 'meta key 1'; | |
$csv_columns['meta:meta_key_2'] = 'meta key 2'; | |
$csv_columns['meta:meta_key_3'] = 'meta key 3'; | |
$csv_columns['role'] = 'role'; | |
return $csv_columns; | |
} | |
add_filter('hf_alter_csv_order_data', 'hf_csv_order_add_more_data', 10, 1); | |
function hf_csv_order_add_more_data($order_data) { | |
$additional_meta['meta:meta_key_1'] = 'meta_key_1'; | |
$additional_meta['meta:meta_key_2'] = 'meta_key_2'; | |
$additional_meta['meta:meta_key_3'] = 'meta_key_3'; | |
foreach ($additional_meta as $key => $val) { | |
$order_data[$key] = get_post_meta($order_data['order_id'], $val, TRUE); | |
} | |
if ($order_data['customer_id'] === 0) { | |
$order_data['role'] = 'Guest'; | |
} else { | |
$user_info = get_userdata($order_data['customer_id']); | |
$roles = implode(', ', $user_info->roles) . " "; | |
$order_data['role'] = $roles; | |
} | |
return $order_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment