fgc-modify-export-csv.php
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
Plugin Name: Modify export csv
Plugin URI: http://fgc.com
Description: Modify export csv
Version: 1.0
Author: Phuong An <phuongantt.na@gmail.com>
Author URI: http://fgc.com
*/
// Add and modify column headers
function fgc_modify_headers_data($column_headers) {
$custom_column_headers = array(
'OrderQuantity' => 'TransactionNumber',
'CustomerName' => 'CustomerName',
'order_id' => 'ReferenceNumber',
'order_number' => 'PurchaseOrderNumber',
'ShipperAccount' => 'ShipperAccount',
'ShipCarrier' => 'ShipCarrier',
'ShipService' => 'ShipService',
'ShipBilling' => 'ShipBilling',
'ShipAccount' => 'ShipAccount',
'ShipToName' => 'ShipToName',
'ShipToCompany' => 'ShipToCompany',
'shipping_address_1' => 'ShipToAddress1',
'shipping_address_2' => 'ShipToAddress2',
'shipping_city' => 'ShipToCity',
'shipping_state' => 'ShipToState',
'shipping_postcode' => 'ShipToZip',
'shipping_country' => 'ShipToCountry',
'ShipToPhone' => 'ShipToPhone',
'ShipToFax' => 'ShipToFax',
'billing_email' => 'ShipToEmail',
'customer_note' => 'CarrierNotes',
'ShipToDeptNumber' => 'ShipToDeptNumber',
'RetailerID' => 'RetailerID',
'TotalCartons' => 'TotalCartons',
'TotalPallets' => 'TotalPallets',
'TotalWeight' => 'TotalWeight',
'TotalVolume' => 'TotalVolume',
'BOLNum' => 'BOLNum',
'TrackingNum' => 'TrackingNum',
'TrailerNum' => 'TrailerNum',
'SealNum' => 'SealNum',
'ShipDate' => 'ShipDate',
'billing_company' => 'BillToCompany',
'billing_address_1' => 'BillToAddress1',
'billing_address_2' => 'BillToAddress2',
'billing_city' => 'BillToCity',
'billing_state' => 'BillToState',
'billing_postcode' => 'BillToZip',
'billing_country' => 'BillToCountry',
'billing_phone' => 'BillToPhone',
'PickupDate' => 'PickupDate',
'RequiresDeliveryConf' => 'RequiresDeliveryConf',
'RequiresReturnReceipt' => 'RequiresReturnReceipt',
);
foreach ($column_headers as $key => $value) {
if (!array_key_exists($key, $custom_column_headers)) {
$custom_column_headers[$key] = $value;
}
}
return $custom_column_headers;
}
add_filter('wc_customer_order_csv_export_order_headers', 'fgc_modify_headers_data');
// set the data for each for custom columns
function fgc_modify_rows_data($order_data, $order) {
foreach ($order->get_items() as $key => $value) {
if ($value['variation_id'] > 0) {
foreach ($value['item_meta_array'] as $_key => $_value) {
if ($_value->key == 'drinks') {
$pack = (int) $_value->value / 6;
}
}
} else {
$pack = (int) str_replace(' drinks', '', $value['name']) / 6;
}
}
$order_data['OrderQuantity'] = $pack;
$order_data['CustomerName'] = "REIZE ENERGY DRINK";
// $order_data['CustomerName'] = $order->billing_first_name . ' ' . $order->billing_last_name;
$order_data['ShipToName'] = $order->shipping_first_name . ' ' . $order->shipping_last_name;
$order_data['ShipToCompany'] = $order->shipping_first_name . ' ' . $order->shipping_last_name;
$order_data['billing_email'] = $order->billing_email . ';contact@uncleanduncle.com';
if (get_post_meta($order->id, 'authorise', true) == 1) {
$customNote = $order->customer_note;
if ($customNote === '') {
$order_data['customer_note'] = 'ATL - Authorised to Leave';
} else {
$order_data['customer_note'] = $customNote . ' - ATL - Authorised to Leave';
}
}
$order_data['ShipToPhone'] = $order_data['billing_phone'];
return $order_data;
}
add_filter('wc_customer_order_csv_export_order_row', 'fgc_modify_rows_data', 10, 2);
function fgc_mark_12_drinks_as_csv_exported($order_id) {
$order = new WC_Order($order_id);
$drinks = 0;
foreach ($order->get_items() as $key => $value) {
if ($value['variation_id'] > 0) {
foreach ($value['item_meta_array'] as $_key => $_value) {
if ($_value->key == 'drinks') {
$drinks = (int) $_value->value;
}
}
} else {
$drinks = (int) str_replace(' drinks', '', $value['name']);
}
}
if ($drinks == 12) {
update_post_meta($order_id, '_wc_customer_order_csv_export_is_exported', 1);
}
}
add_action('woocommerce_payment_complete', 'fgc_mark_12_drinks_as_csv_exported', 10);