Passed
Pull Request — master (#82)
by
unknown
03:14
created

updateCartProcessingTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 12
rs 10
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');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
    dbDelta($sqlQuery);
0 ignored issues
show
Bug introduced by
The function dbDelta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
    /** @scrutinizer ignore-call */ 
65
    dbDelta($sqlQuery);
Loading history...
65
}
66
67
/**
68
 * @param null $exception
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $exception is correct as it would always require null to be passed?
Loading history...
69
 * @param null $message
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $message is correct as it would always require null to be passed?
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
    $wc_decimal_sep     = /** @scrutinizer ignore-call */ get_option('woocommerce_price_decimal_sep');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
    $wc_price_thousand   = /** @scrutinizer ignore-call */ get_option('woocommerce_price_thousand_sep');
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

149
    $thousandSeparator = /** @scrutinizer ignore-call */ get_option('woocommerce_price_thousand_sep');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

161
    $decimalSeparator = /** @scrutinizer ignore-call */ get_option('woocommerce_price_decimal_sep');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

201
    $settings   = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

213
    $settings   = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

225
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

235
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
236
237
    return ( ! empty($settings['enabled']) && 'yes' === $settings['enabled']);
238
}
239
240
function isPluginEnabled4x()
241
{
242
    $settings = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

242
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
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));
0 ignored issues
show
Bug introduced by
The function get_locale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

250
    $locale           = strtolower(strstr(/** @scrutinizer ignore-call */ get_locale(), '_', true));
Loading history...
251
    $allowedCountries = maybe_unserialize(getConfigValue('PAGANTIS_ALLOWED_COUNTRIES'));
0 ignored issues
show
Bug introduced by
The function maybe_unserialize was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

251
    $allowedCountries = /** @scrutinizer ignore-call */ maybe_unserialize(getConfigValue('PAGANTIS_ALLOWED_COUNTRIES'));
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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';
0 ignored issues
show
Bug introduced by
The function plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

320
    $mainFile = /** @scrutinizer ignore-call */ plugin_dir_path(PG_WC_MAIN_FILE) . '/WC_Pagantis.php';
Loading history...
321
    $version  = get_file_data($mainFile, array('Version' => 'Version'), false);
0 ignored issues
show
Bug introduced by
The function get_file_data was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

321
    $version  = /** @scrutinizer ignore-call */ get_file_data($mainFile, array('Version' => 'Version'), false);
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

366
    $metaProduct = /** @scrutinizer ignore-call */ get_post_meta($product_id);
Loading history...
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) {
0 ignored issues
show
Bug introduced by
The function WC was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

378
    foreach (/** @scrutinizer ignore-call */ WC()->cart->get_cart() as $key => $item) {
Loading history...
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();
0 ignored issues
show
Bug introduced by
The function wp_cache_flush was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

426
    /** @scrutinizer ignore-call */ 
427
    wp_cache_flush();
Loading history...
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');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
449
        dbDelta($sql);
0 ignored issues
show
Bug introduced by
The function dbDelta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

449
        /** @scrutinizer ignore-call */ 
450
        dbDelta($sql);
Loading history...
450
    }
451
}
452
453
/**
454
 * Get the orders of a customer
455
 *
456
 * @param WP_User $current_user
0 ignored issues
show
Bug introduced by
The type WP_User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_orders is dead and can be removed.
Loading history...
466
    $total_amt       = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_amt is dead and can be removed.
Loading history...
467
    $refund_amt      = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $refund_amt is dead and can be removed.
Loading history...
468
    $total_refunds   = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_refunds is dead and can be removed.
Loading history...
469
    $partial_refunds = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $partial_refunds is dead and can be removed.
Loading history...
470
    if ($current_user->user_login) {
471
        $is_guest        = "false";
0 ignored issues
show
Unused Code introduced by
The assignment to $is_guest is dead and can be removed.
Loading history...
472
        $sign_up         = substr($current_user->user_registered, 0, 10);
0 ignored issues
show
Unused Code introduced by
The assignment to $sign_up is dead and can be removed.
Loading history...
473
        $customer_orders = get_posts(array(
0 ignored issues
show
Bug introduced by
The function get_posts was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

473
        $customer_orders = /** @scrutinizer ignore-call */ get_posts(array(
Loading history...
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');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
511
        dbDelta($sql);
0 ignored issues
show
Bug introduced by
The function dbDelta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

511
        /** @scrutinizer ignore-call */ 
512
        dbDelta($sql);
Loading history...
512
    }
513
}
514
515
516
function isPagePaymentPage()
517
{
518
    return (is_checkout() && ! is_order_received_page()) || is_checkout_pay_page();
0 ignored issues
show
Bug introduced by
The function is_checkout was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

518
    return (/** @scrutinizer ignore-call */ is_checkout() && ! is_order_received_page()) || is_checkout_pay_page();
Loading history...
Bug introduced by
The function is_checkout_pay_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

518
    return (is_checkout() && ! is_order_received_page()) || /** @scrutinizer ignore-call */ is_checkout_pay_page();
Loading history...
Bug introduced by
The function is_order_received_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

518
    return (is_checkout() && ! /** @scrutinizer ignore-call */ is_order_received_page()) || is_checkout_pay_page();
Loading history...
519
}
520