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