1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use function foo\func; |
4
|
|
|
|
5
|
|
|
function requireWPPluginFunctions() |
6
|
|
|
{ |
7
|
|
|
if ( ! function_exists('is_plugin_active')) { |
8
|
|
|
require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
|
|
|
9
|
|
|
} |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
requireWPPluginFunctions(); |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get lowercase config value from WP DB |
17
|
|
|
* |
18
|
|
|
* @param string $configKey |
19
|
|
|
* |
20
|
|
|
* @return string |
21
|
|
|
* @global wpdb $wpdb WordPress database abstraction object. |
22
|
|
|
*/ |
23
|
|
|
function getConfigValue($configKey) |
24
|
|
|
{ |
25
|
|
|
global $wpdb; |
26
|
|
|
$tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME; |
27
|
|
|
$value = $wpdb->get_var($wpdb->prepare("SELECT value FROM $tableName WHERE config= %s ", $configKey)); |
28
|
|
|
|
29
|
|
|
return $value; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Check if table exists in WordPress DB |
34
|
|
|
* |
35
|
|
|
* @param string $tableToCheck |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
* @see wpdb::get_var() |
39
|
|
|
*/ |
40
|
|
|
function isPgTableCreated($tableToCheck) |
41
|
|
|
{ |
42
|
|
|
global $wpdb; |
43
|
|
|
$tableName = $wpdb->prefix . $tableToCheck; |
44
|
|
|
if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) { |
45
|
|
|
return true; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return false; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Check if orders table exists |
53
|
|
|
*/ |
54
|
|
|
function createPgCartTable() |
55
|
|
|
{ |
56
|
|
|
global $wpdb; |
57
|
|
|
$tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE; |
58
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
59
|
|
|
$sql = "CREATE TABLE $tableName ( id int, order_id varchar(50), wc_order_id varchar(50), |
60
|
|
|
UNIQUE KEY id (id)) $charset_collate"; |
61
|
|
|
|
62
|
|
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
|
|
|
63
|
|
|
dbDelta($sql); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function createLogsTable() |
67
|
|
|
{ |
68
|
|
|
global $wpdb; |
69
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
70
|
|
|
$LogsTableName = $wpdb->prefix . PG_LOGS_TABLE_NAME; |
71
|
|
|
$sqlQuery = "CREATE TABLE $LogsTableName ( |
72
|
|
|
id int NOT NULL AUTO_INCREMENT, |
73
|
|
|
log text NOT NULL, |
74
|
|
|
createdAt timestamp DEFAULT CURRENT_TIMESTAMP, |
75
|
|
|
UNIQUE KEY id (id)) |
76
|
|
|
$charset_collate"; |
77
|
|
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
|
|
|
78
|
|
|
dbDelta($sqlQuery); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param null $exception |
|
|
|
|
83
|
|
|
* @param null $message |
|
|
|
|
84
|
|
|
*/ |
85
|
|
|
function insertLogEntry($exception = null, $message = null) |
86
|
|
|
{ |
87
|
|
|
global $wpdb; |
88
|
|
|
if ( ! isPgTableCreated(PG_LOGS_TABLE_NAME)) { |
89
|
|
|
createLogsTable(); |
90
|
|
|
} |
91
|
|
|
$logEntry = new Pagantis\ModuleUtils\Model\Log\LogEntry(); |
92
|
|
|
if ($exception instanceof \Exception) { |
93
|
|
|
$logEntry = $logEntry->error($exception); |
94
|
|
|
} else { |
95
|
|
|
$logEntry = $logEntry->info($message); |
96
|
|
|
} |
97
|
|
|
$tableName = $wpdb->prefix . PG_LOGS_TABLE_NAME; |
98
|
|
|
$wpdb->insert($tableName, array('log' => $logEntry->toJson())); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
function areDecimalSeparatorEqual() |
105
|
|
|
{ |
106
|
|
|
$pgDecimalSeparator = getPgSimulatorDecimalSeparatorConfig(); |
107
|
|
|
$wc_decimal_sep = get_option('woocommerce_price_decimal_sep'); |
|
|
|
|
108
|
|
|
if (stripslashes($wc_decimal_sep) == stripslashes($pgDecimalSeparator)) { |
109
|
|
|
return true; |
110
|
|
|
} else { |
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
function areThousandsSeparatorEqual() |
120
|
|
|
{ |
121
|
|
|
$pgThousandSeparator = getPgSimulatorThousandsSeparator(); |
122
|
|
|
$wc_price_thousand = get_option('woocommerce_price_thousand_sep'); |
|
|
|
|
123
|
|
|
if (stripslashes($wc_price_thousand) == stripslashes($pgThousandSeparator)) { |
124
|
|
|
return true; |
125
|
|
|
} else { |
126
|
|
|
return false; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array|object|null |
132
|
|
|
*/ |
133
|
|
|
function getPgSimulatorThousandsSeparator() |
134
|
|
|
{ |
135
|
|
|
global $wpdb; |
136
|
|
|
$tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME; |
137
|
|
|
$query = "SELECT value FROM $tableName WHERE config='PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'"; |
138
|
|
|
$result = $wpdb->get_row($query, ARRAY_A); |
|
|
|
|
139
|
|
|
|
140
|
|
|
return $result['value']; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return array|object|null |
145
|
|
|
*/ |
146
|
|
|
function getPgSimulatorDecimalSeparatorConfig() |
147
|
|
|
{ |
148
|
|
|
global $wpdb; |
149
|
|
|
$tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME; |
150
|
|
|
$query = "SELECT value FROM $tableName WHERE config='PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'"; |
151
|
|
|
$result = $wpdb->get_row($query, ARRAY_A); |
|
|
|
|
152
|
|
|
|
153
|
|
|
return $result['value']; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
function updateThousandsSeparatorDbConfig() |
157
|
|
|
{ |
158
|
|
|
global $wpdb; |
159
|
|
|
if (areThousandsSeparatorEqual()) { |
160
|
|
|
return; |
161
|
|
|
} |
162
|
|
|
$tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME; |
163
|
|
|
$thousandSeparator = get_option('woocommerce_price_thousand_sep'); |
|
|
|
|
164
|
|
|
$wpdb->update($tableName, array('value' => $thousandSeparator), array('config' => 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'), |
165
|
|
|
array('%s'), array('%s')); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
function updateDecimalSeparatorDbConfig() |
169
|
|
|
{ |
170
|
|
|
global $wpdb; |
171
|
|
|
if (areDecimalSeparatorEqual()) { |
172
|
|
|
return; |
173
|
|
|
} |
174
|
|
|
$tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME; |
175
|
|
|
$decimalSeparator = get_option('woocommerce_price_decimal_sep'); |
|
|
|
|
176
|
|
|
$wpdb->update($tableName, array('value' => $decimalSeparator), array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'), |
177
|
|
|
array('%s'), array('%s')); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param $simulatorType |
183
|
|
|
* @param $validSimulatorTypes array |
184
|
|
|
* |
185
|
|
|
* @return bool |
186
|
|
|
*/ |
187
|
|
|
function isSimulatorTypeValid($simulatorType, $validSimulatorTypes) |
188
|
|
|
{ |
189
|
|
|
if ( ! in_array($simulatorType, $validSimulatorTypes)) { |
190
|
|
|
return false; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return true; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param $currentTemplateName |
198
|
|
|
* |
199
|
|
|
* @param $validTemplateNames array |
200
|
|
|
* |
201
|
|
|
* @return bool |
202
|
|
|
*/ |
203
|
|
|
function isTemplatePresent($currentTemplateName, $validTemplateNames) |
204
|
|
|
{ |
205
|
|
|
if (in_array($currentTemplateName, $validTemplateNames)) { |
206
|
|
|
return true; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
return false; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
function areMerchantKeysSet() |
214
|
|
|
{ |
215
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
216
|
|
|
$publicKey = ! empty($settings['pagantis_public_key']) ? $settings['pagantis_public_key'] : ''; |
217
|
|
|
$privateKey = ! empty($settings['pagantis_private_key']) ? $settings['pagantis_private_key'] : ''; |
218
|
|
|
if ((empty($publicKey) && empty($privateKey)) || (empty($publicKey) || empty($privateKey))) { |
219
|
|
|
return false; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return true; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
function areMerchantKeysSet4x() |
226
|
|
|
{ |
227
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
228
|
|
|
$publicKey = ! empty($settings['pagantis_public_key_4x']) ? $settings['pagantis_public_key_4x'] : ''; |
229
|
|
|
$privateKey = ! empty($settings['pagantis_private_key_4x']) ? $settings['pagantis_private_key_4x'] : ''; |
230
|
|
|
if ((empty($publicKey) && empty($privateKey)) || (empty($publicKey) || empty($privateKey))) { |
231
|
|
|
return false; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return true; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
function isSimulatorEnabled() |
238
|
|
|
{ |
239
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
240
|
|
|
if (( ! empty($settings['simulator']) && 'yes' === $settings['simulator']) ? true : false) { |
241
|
|
|
return true; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return false; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
function isPluginEnabled() |
248
|
|
|
{ |
249
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
250
|
|
|
|
251
|
|
|
return ( ! empty($settings['enabled']) && 'yes' === $settings['enabled']); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
function isPluginEnabled4x() |
255
|
|
|
{ |
256
|
|
|
$settings = get_option('woocommerce_pagantis_settings'); |
|
|
|
|
257
|
|
|
|
258
|
|
|
return ( ! empty($settings['enabled_4x']) && 'yes' === $settings['enabled_4x']); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
function isCountryShopContextValid() |
263
|
|
|
{ |
264
|
|
|
$locale = strtolower(strstr(get_locale(), '_', true)); |
|
|
|
|
265
|
|
|
$allowedCountries = maybe_unserialize(getConfigValue('PAGANTIS_ALLOWED_COUNTRIES')); |
|
|
|
|
266
|
|
|
if ( ! in_array(strtolower($locale), $allowedCountries)) { |
267
|
|
|
return false; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
return true; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @return bool |
275
|
|
|
*/ |
276
|
|
|
function isProductAmountValid() |
277
|
|
|
{ |
278
|
|
|
$minAmount = getConfigValue('PAGANTIS_DISPLAY_MIN_AMOUNT'); |
279
|
|
|
$maxAmount = getConfigValue('PAGANTIS_DISPLAY_MAX_AMOUNT'); |
280
|
|
|
global $product; |
281
|
|
|
if (method_exists($product, 'get_price')) { |
282
|
|
|
$productPrice = $product->get_price(); |
283
|
|
|
$validAmount = ($productPrice >= $minAmount && ($productPrice <= $maxAmount || $maxAmount == '0')); |
284
|
|
|
if ($validAmount) { |
285
|
|
|
return true; |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
return false; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @return bool |
294
|
|
|
*/ |
295
|
|
|
function isProductAmountValid4x() |
296
|
|
|
{ |
297
|
|
|
$minAmount = getConfigValue('PAGANTIS_DISPLAY_MIN_AMOUNT_4x'); |
298
|
|
|
$maxAmount = getConfigValue('PAGANTIS_DISPLAY_MAX_AMOUNT_4x'); |
299
|
|
|
global $product; |
300
|
|
|
if (method_exists($product, 'get_price')) { |
301
|
|
|
$productPrice = $product->get_price(); |
302
|
|
|
$validAmount = ($productPrice >= $minAmount && ($productPrice <= $maxAmount || $maxAmount == '0')); |
303
|
|
|
if ($validAmount) { |
304
|
|
|
return true; |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
return false; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
function getAllowedCurrencies() |
312
|
|
|
{ |
313
|
|
|
return array("EUR"); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @return array |
318
|
|
|
*/ |
319
|
|
|
function getExtraConfig() |
320
|
|
|
{ |
321
|
|
|
global $wpdb; |
322
|
|
|
$tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME; |
323
|
|
|
$response = array(); |
324
|
|
|
$dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A); |
|
|
|
|
325
|
|
|
foreach ($dbResult as $value) { |
326
|
|
|
$response[$value['config']] = $value['value']; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return $response; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
function getModuleVersion() |
333
|
|
|
{ |
334
|
|
|
$mainFile = plugin_dir_path(PG_WC_MAIN_FILE) . '/WC_Pagantis.php'; |
|
|
|
|
335
|
|
|
$version = get_file_data($mainFile, array('Version' => 'Version'), false); |
|
|
|
|
336
|
|
|
|
337
|
|
|
return $version['Version']; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @param $order |
342
|
|
|
* |
343
|
|
|
* @return null |
344
|
|
|
*/ |
345
|
|
|
function getNationalId($order) |
346
|
|
|
{ |
347
|
|
|
foreach ((array)$order->get_meta_data() as $mdObject) { |
348
|
|
|
$data = $mdObject->get_data(); |
349
|
|
|
if ($data['key'] == 'vat_number') { |
350
|
|
|
return $data['value']; |
351
|
|
|
} |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
return null; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @param $order |
359
|
|
|
* |
360
|
|
|
* @return mixed |
361
|
|
|
*/ |
362
|
|
|
function getTaxId($order) |
363
|
|
|
{ |
364
|
|
|
foreach ((array)$order->get_meta_data() as $mdObject) { |
365
|
|
|
$data = $mdObject->get_data(); |
366
|
|
|
if ($data['key'] == 'billing_cfpiva') { |
367
|
|
|
return $data['value']; |
368
|
|
|
} |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @param $product_id |
375
|
|
|
* |
376
|
|
|
* @return string |
377
|
|
|
*/ |
378
|
|
|
function isProductPromoted($product_id) |
379
|
|
|
{ |
380
|
|
|
$metaProduct = get_post_meta($product_id); |
|
|
|
|
381
|
|
|
|
382
|
|
|
return (array_key_exists('custom_product_pagantis_promoted', $metaProduct) |
383
|
|
|
&& $metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false'; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return int |
388
|
|
|
*/ |
389
|
|
|
function getPromotedAmount() |
390
|
|
|
{ |
391
|
|
|
$promotedAmount = 0; |
392
|
|
|
foreach (WC()->cart->get_cart() as $key => $item) { |
|
|
|
|
393
|
|
|
$promotedProduct = isProductPromoted($item['product_id']); |
394
|
|
|
if ($promotedProduct == 'true') { |
395
|
|
|
$promotedAmount += $item['line_total'] + $item['line_tax']; |
396
|
|
|
} |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
return $promotedAmount; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @param $cartHash |
404
|
|
|
* @param $pagantisOrderId |
405
|
|
|
* |
406
|
|
|
* @param $wcOrderID |
407
|
|
|
* @param $origin |
408
|
|
|
* @param $token |
409
|
|
|
*/ |
410
|
|
|
function addOrderToCartProcessingQueue($cartHash, $pagantisOrderId, $wcOrderID, $origin, $token) |
411
|
|
|
{ |
412
|
|
|
global $wpdb; |
413
|
|
|
$tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE; |
414
|
|
|
$wpdb->insert($tableName, array( |
415
|
|
|
'id' => $cartHash, |
416
|
|
|
'order_id' => $pagantisOrderId, |
417
|
|
|
'wc_order_id' => $wcOrderID, |
418
|
|
|
'origin' => $origin, |
419
|
|
|
'token' => $token |
420
|
|
|
), array('%d', '%s', '%s', '%s', '%s')); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
function alterCartProcessingTable(){ |
424
|
|
|
global $wpdb; |
425
|
|
|
$tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE; |
426
|
|
|
$wpdb->query( "ALTER TABLE $tableName ADD COLUMN token VARCHAR(32) NOT NULL AFTER wc_order_id"); |
427
|
|
|
$wpdb->query( "ALTER TABLE $tableName DROP PRIMARY KEY, ADD PRIMARY KEY(`id`, `token`)" ); |
428
|
|
|
wp_cache_flush(); |
|
|
|
|
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Check if orders table exists |
433
|
|
|
*/ |
434
|
|
|
function createCartProcessingTable() |
435
|
|
|
{ |
436
|
|
|
global $wpdb; |
437
|
|
|
$tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE; |
438
|
|
|
|
439
|
|
|
if ( ! isPgTableCreated(PG_CART_PROCESS_TABLE)) { |
440
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
441
|
|
|
$sql = "CREATE TABLE $tableName id VARCHAR(60) NOT NULL, order_id VARCHAR(60) NOT NULL, wc_order_id VARCHAR(50) NOT NULL, token VARCHAR(32) NOT NULL PRIMARY KEY('id' , 'token')) $charset_collate"; |
442
|
|
|
|
443
|
|
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
|
|
|
444
|
|
|
dbDelta($sql); |
|
|
|
|
445
|
|
|
} |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Get the orders of a customer |
450
|
|
|
* |
451
|
|
|
* @param WP_User $current_user |
|
|
|
|
452
|
|
|
* @param $billingEmail |
453
|
|
|
* |
454
|
|
|
* @return mixed |
455
|
|
|
* @uses Wordpress Core Post API |
456
|
|
|
*/ |
457
|
|
|
function getOrders($current_user, $billingEmail) |
458
|
|
|
{ |
459
|
|
|
$sign_up = ''; |
460
|
|
|
$total_orders = 0; |
|
|
|
|
461
|
|
|
$total_amt = 0; |
|
|
|
|
462
|
|
|
$refund_amt = 0; |
|
|
|
|
463
|
|
|
$total_refunds = 0; |
|
|
|
|
464
|
|
|
$partial_refunds = 0; |
|
|
|
|
465
|
|
|
if ($current_user->user_login) { |
466
|
|
|
$is_guest = "false"; |
|
|
|
|
467
|
|
|
$sign_up = substr($current_user->user_registered, 0, 10); |
|
|
|
|
468
|
|
|
$customer_orders = get_posts(array( |
|
|
|
|
469
|
|
|
'numberposts' => -1, |
470
|
|
|
'meta_key' => '_customer_user', |
471
|
|
|
'meta_value' => $current_user->ID, |
472
|
|
|
'post_type' => array('shop_order'), |
473
|
|
|
'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'), |
474
|
|
|
)); |
475
|
|
|
} else { |
476
|
|
|
$is_guest = "true"; |
477
|
|
|
$customer_orders = get_posts(array( |
478
|
|
|
'numberposts' => -1, |
479
|
|
|
'meta_key' => '_billing_email', |
480
|
|
|
'meta_value' => $billingEmail, |
481
|
|
|
'post_type' => array('shop_order'), |
482
|
|
|
'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'), |
483
|
|
|
)); |
484
|
|
|
foreach ($customer_orders as $customer_order) { |
485
|
|
|
if (trim($sign_up) == '' || strtotime(substr($customer_order->post_date, 0, 10)) <= strtotime($sign_up)) { |
486
|
|
|
$sign_up = substr($customer_order->post_date, 0, 10); |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
return $customer_orders; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
|
495
|
|
|
function updateCartProcessingTable() |
496
|
|
|
{ |
497
|
|
|
global $wpdb; |
498
|
|
|
$tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE; |
499
|
|
|
|
500
|
|
|
if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) { |
501
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
502
|
|
|
$sql = "CREATE TABLE $tableName ( id int, order_id varchar(50), wc_order_id varchar(50), token varchar(32) |
503
|
|
|
UNIQUE KEY id (id)) $charset_collate"; |
504
|
|
|
|
505
|
|
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
|
|
|
506
|
|
|
dbDelta($sql); |
|
|
|
|
507
|
|
|
} |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
function createToken() |
511
|
|
|
{ |
512
|
|
|
return strtoupper(md5(uniqid(rand(), true))); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
function isPagePaymentPage() |
516
|
|
|
{ |
517
|
|
|
return (is_checkout() && ! is_order_received_page()) || is_checkout_pay_page(); |
|
|
|
|
518
|
|
|
} |
519
|
|
|
|