Passed
Pull Request — master (#83)
by
unknown
03:23
created

alterCartProcessTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
c 4
b 1
f 0
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
function requireWPPluginFunctions()
4
{
5
    if (! function_exists('is_plugin_active')) {
6
        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...
7
    }
8
}
9
10
requireWPPluginFunctions();
11
12
13
/**
14
 * Get lowercase config value from WP DB
15
 *
16
 * @param string $configKey
17
 *
18
 * @return string
19
 * @global wpdb  $wpdb WordPress database abstraction object.
20
 */
21
function getConfigValue($configKey)
22
{
23
    global $wpdb;
24
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
25
    $value     = $wpdb->get_var($wpdb->prepare("SELECT value FROM $tableName WHERE config= %s ", $configKey));
26
27
    return $value;
28
}
29
30
/**
31
 * Check if table exists in WordPress DB
32
 *
33
 * @param string $tableToCheck
34
 *
35
 * @return bool
36
 * @see wpdb::get_var()
37
 */
38
function isPgTableCreated($tableToCheck)
39
{
40
    global $wpdb;
41
    $tableName = $wpdb->prefix . $tableToCheck;
42
    if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
43
        return true;
44
    }
45
46
    return false;
47
}
48
49
/**
50
 * Check if orders table exists
51
 */
52
function createPgCartTable()
53
{
54
    global $wpdb;
55
    $tableName       = $wpdb->prefix . PG_CART_PROCESS_TABLE;
56
    $charset_collate = $wpdb->get_charset_collate();
57
    $sql             = "CREATE TABLE $tableName ( id int, order_id varchar(50), wc_order_id varchar(50),  
58
                  UNIQUE KEY id (id)) $charset_collate";
59
60
    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...
61
    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

61
    /** @scrutinizer ignore-call */ 
62
    dbDelta($sql);
Loading history...
62
}
63
64
function createLogsTable()
65
{
66
    global $wpdb;
67
    $charset_collate = $wpdb->get_charset_collate();
68
    $LogsTableName   = $wpdb->prefix . PG_LOGS_TABLE_NAME;
69
    $sqlQuery        = "CREATE TABLE $LogsTableName ( 
70
    id int NOT NULL AUTO_INCREMENT,
71
    log text NOT NULL, 
72
    createdAt timestamp DEFAULT CURRENT_TIMESTAMP,
73
    UNIQUE KEY id (id)) 
74
    $charset_collate";
75
    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...
76
    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

76
    /** @scrutinizer ignore-call */ 
77
    dbDelta($sqlQuery);
Loading history...
77
}
78
79
/**
80
 * @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...
81
 * @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...
82
 */
83
function insertLogEntry($exception = null, $message = null)
84
{
85
    global $wpdb;
86
    if (! isPgTableCreated(PG_LOGS_TABLE_NAME)) {
87
        createLogsTable();
88
    }
89
    $logEntry = new Pagantis\ModuleUtils\Model\Log\LogEntry();
90
    if ($exception instanceof \Exception) {
91
        $logEntry = $logEntry->error($exception);
92
    } else {
93
        $logEntry = $logEntry->info($message);
94
    }
95
    $tableName = $wpdb->prefix . PG_LOGS_TABLE_NAME;
96
    $wpdb->insert($tableName, array('log' => $logEntry->toJson()));
97
}
98
99
/**
100
 * @return bool
101
 */
102
function areDecimalSeparatorEqual()
103
{
104
    $pgDecimalSeparator = getPgSimulatorDecimalSeparatorConfig();
105
    $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

105
    $wc_decimal_sep     = /** @scrutinizer ignore-call */ get_option('woocommerce_price_decimal_sep');
Loading history...
106
    if (stripslashes($wc_decimal_sep) == stripslashes($pgDecimalSeparator)) {
107
        return true;
108
    } else {
109
        return false;
110
    }
111
}
112
113
114
/**
115
 * @return bool
116
 */
117
function areThousandsSeparatorEqual()
118
{
119
    $pgThousandSeparator = getPgSimulatorThousandsSeparator();
120
    $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

120
    $wc_price_thousand   = /** @scrutinizer ignore-call */ get_option('woocommerce_price_thousand_sep');
Loading history...
121
    if (stripslashes($wc_price_thousand) == stripslashes($pgThousandSeparator)) {
122
        return true;
123
    } else {
124
        return false;
125
    }
126
}
127
128
/**
129
 * @return array|object|null
130
 */
131
function getPgSimulatorThousandsSeparator()
132
{
133
    global $wpdb;
134
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
135
    $query     = "SELECT value FROM $tableName WHERE config='PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'";
136
    $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...
137
138
    return $result['value'];
139
}
140
141
/**
142
 * @return array|object|null
143
 */
144
function getPgSimulatorDecimalSeparatorConfig()
145
{
146
    global $wpdb;
147
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
148
    $query     = "SELECT value FROM $tableName WHERE config='PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'";
149
    $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...
150
151
    return $result['value'];
152
}
153
154
function updateThousandsSeparatorDbConfig()
155
{
156
    global $wpdb;
157
    if (areThousandsSeparatorEqual()) {
158
        return;
159
    }
160
    $tableName         = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
161
    $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

161
    $thousandSeparator = /** @scrutinizer ignore-call */ get_option('woocommerce_price_thousand_sep');
Loading history...
162
    $wpdb->update(
163
        $tableName,
164
        array('value' => $thousandSeparator),
165
        array('config' => 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'),
166
        array('%s'),
167
        array('%s')
168
    );
169
}
170
171
function updateDecimalSeparatorDbConfig()
172
{
173
    global $wpdb;
174
    if (areDecimalSeparatorEqual()) {
175
        return;
176
    }
177
    $tableName        = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
178
    $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

178
    $decimalSeparator = /** @scrutinizer ignore-call */ get_option('woocommerce_price_decimal_sep');
Loading history...
179
    $wpdb->update(
180
        $tableName,
181
        array('value' => $decimalSeparator),
182
        array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'),
183
        array('%s'),
184
        array('%s')
185
    );
186
}
187
188
189
/**
190
 * @param $simulatorType
191
 * @param $validSimulatorTypes array
192
 *
193
 * @return bool
194
 */
195
function isSimulatorTypeValid($simulatorType, $validSimulatorTypes)
196
{
197
    if (! in_array($simulatorType, $validSimulatorTypes)) {
198
        return false;
199
    }
200
201
    return true;
202
}
203
204
/**
205
 * @param $currentTemplateName
206
 *
207
 * @param $validTemplateNames array
208
 *
209
 * @return bool
210
 */
211
function isTemplatePresent($currentTemplateName, $validTemplateNames)
212
{
213
    if (in_array($currentTemplateName, $validTemplateNames)) {
214
        return true;
215
    }
216
217
    return false;
218
}
219
220
221
function areMerchantKeysSet()
222
{
223
    $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

223
    $settings   = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
224
    $publicKey  = ! empty($settings['pagantis_public_key']) ? $settings['pagantis_public_key'] : '';
225
    $privateKey = ! empty($settings['pagantis_private_key']) ? $settings['pagantis_private_key'] : '';
226
    if ((empty($publicKey) && empty($privateKey)) || (empty($publicKey) || empty($privateKey))) {
227
        return false;
228
    }
229
230
    return true;
231
}
232
233
function areMerchantKeysSet4x()
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
    $publicKey  = ! empty($settings['pagantis_public_key_4x']) ? $settings['pagantis_public_key_4x'] : '';
237
    $privateKey = ! empty($settings['pagantis_private_key_4x']) ? $settings['pagantis_private_key_4x'] : '';
238
    if ((empty($publicKey) && empty($privateKey)) || (empty($publicKey) || empty($privateKey))) {
239
        return false;
240
    }
241
242
    return true;
243
}
244
245
function isSimulatorEnabled()
246
{
247
    $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

247
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
248
    if ((! empty($settings['simulator']) && 'yes' === $settings['simulator']) ? true : false) {
249
        return true;
250
    }
251
252
    return false;
253
}
254
255
function isPluginEnabled()
256
{
257
    $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

257
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
258
259
    return (! empty($settings['enabled']) && 'yes' === $settings['enabled']);
260
}
261
262
function isPluginEnabled4x()
263
{
264
    $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

264
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
265
    return (! empty($settings['enabled_4x']) && 'yes' === $settings['enabled_4x']);
266
}
267
268
269
function isCountryShopContextValid()
270
{
271
    $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

271
    $locale           = strtolower(strstr(/** @scrutinizer ignore-call */ get_locale(), '_', true));
Loading history...
272
    $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

272
    $allowedCountries = /** @scrutinizer ignore-call */ maybe_unserialize(getConfigValue('PAGANTIS_ALLOWED_COUNTRIES'));
Loading history...
273
    if (! in_array(strtolower($locale), $allowedCountries)) {
274
        return false;
275
    }
276
277
    return true;
278
}
279
280
/**
281
 * @return bool
282
 */
283
function isProductAmountValid()
284
{
285
    $minAmount = getConfigValue('PAGANTIS_DISPLAY_MIN_AMOUNT');
286
    $maxAmount = getConfigValue('PAGANTIS_DISPLAY_MAX_AMOUNT');
287
    global $product;
288
    if (method_exists($product, 'get_price')) {
289
        $productPrice = $product->get_price();
290
        $validAmount  = ($productPrice >= $minAmount && ($productPrice <= $maxAmount || $maxAmount == '0'));
291
        if ($validAmount) {
292
            return true;
293
        }
294
    }
295
296
    return false;
297
}
298
299
/**
300
 * @return bool
301
 */
302
function isProductAmountValid4x()
303
{
304
    $minAmount = getConfigValue('PAGANTIS_DISPLAY_MIN_AMOUNT_4x');
305
    $maxAmount = getConfigValue('PAGANTIS_DISPLAY_MAX_AMOUNT_4x');
306
    global $product;
307
    if (method_exists($product, 'get_price')) {
308
        $productPrice = $product->get_price();
309
        $validAmount  = ($productPrice >= $minAmount && ($productPrice <= $maxAmount || $maxAmount == '0'));
310
        if ($validAmount) {
311
            return true;
312
        }
313
    }
314
315
    return false;
316
}
317
function getAllowedCurrencies()
318
{
319
    return array("EUR");
320
}
321
322
/**
323
 * @return array
324
 */
325
function getExtraConfig()
326
{
327
    global $wpdb;
328
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
329
    $response  = array();
330
    $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...
331
    foreach ($dbResult as $value) {
332
        $response[$value['config']] = $value['value'];
333
    }
334
335
    return $response;
336
}
337
338
function getModuleVersion()
339
{
340
341
    $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

341
    $mainFile = /** @scrutinizer ignore-call */ plugin_dir_path(PG_WC_MAIN_FILE). '/WC_Pagantis.php';
Loading history...
342
    $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

342
    $version = /** @scrutinizer ignore-call */ get_file_data($mainFile, array('Version' => 'Version'), false);
Loading history...
343
    return $version['Version'];
344
}
345
346
/**
347
 * @param $order
348
 *
349
 * @return null
350
 */
351
function getNationalId($order)
352
{
353
    foreach ((array)$order->get_meta_data() as $mdObject) {
354
        $data = $mdObject->get_data();
355
        if ($data['key'] == 'vat_number') {
356
            return $data['value'];
357
        }
358
    }
359
360
    return null;
361
}
362
363
/**
364
 * @param $order
365
 *
366
 * @return mixed
367
 */
368
function getTaxId($order)
369
{
370
    foreach ((array)$order->get_meta_data() as $mdObject) {
371
        $data = $mdObject->get_data();
372
        if ($data['key'] == 'billing_cfpiva') {
373
            return $data['value'];
374
        }
375
    }
376
}
377
378
379
/**
380
 * @param $product_id
381
 *
382
 * @return string
383
 */
384
function isProductPromoted($product_id)
385
{
386
    $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

386
    $metaProduct = /** @scrutinizer ignore-call */ get_post_meta($product_id);
Loading history...
387
388
    return (array_key_exists('custom_product_pagantis_promoted', $metaProduct)
389
            && $metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false';
390
}
391
392
/**
393
 * @return int
394
 */
395
function getPromotedAmount()
396
{
397
    $promotedAmount = 0;
398
    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

398
    foreach (/** @scrutinizer ignore-call */ WC()->cart->get_cart() as $key => $item) {
Loading history...
399
        $promotedProduct = isProductPromoted($item['product_id']);
400
        if ($promotedProduct == 'true') {
401
            $promotedAmount += $item['line_total'] + $item['line_tax'];
402
        }
403
    }
404
405
    return $promotedAmount;
406
}
407
408
/**
409
 * @param $orderId
410
 * @param $pagantisOrderId
411
 *
412
 * @param $wcOrderID
413
 * @param $paymentProcessingToken
414
 */
415
function addOrderToProcessingQueue($pagantisOrderId, $wcOrderID, $paymentProcessingToken)
416
{
417
    global $wpdb;
418
    checkCartProcessTable();
419
    $tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE;
420
421
    //Check if id exists
422
    $resultsSelect = $wpdb->get_results("SELECT * FROM $tableName WHERE id='$pagantisOrderId'");
423
    $countResults  = count($resultsSelect);
424
425
    if ($countResults == 0) {
426
        $wpdb->insert($tableName, array(
427
            'order_id' => $pagantisOrderId,
428
            'wc_order_id' => $wcOrderID,
429
            'token'       => $paymentProcessingToken
430
        ), array('%s', '%s', '%s'));
431
    } else {
432
        $wpdb->update($tableName, array('order_id' => $pagantisOrderId,'token' => $paymentProcessingToken), array('wc_order_id' => $wcOrderID), array('%s,%s'), array('%s'));
433
    }
434
}
435
436
function alterCartProcessTable()
437
{
438
    global $wpdb;
439
    $tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE;
440
    if (! $wpdb->get_var( "SHOW COLUMNS FROM `{$tableName}` LIKE 'token';" ) ) {
441
        $wpdb->query("ALTER TABLE $tableName ADD COLUMN `token` VARCHAR(32) NOT NULL AFTER `order_id`");
442
        // OLDER VERSIONS OF MODULE USE UNIQUE KEY ON `id` MEANING THIS VALUE WAS NULLABLE
443
        $wpdb->query("ALTER TABLE $tableName  DROP PRIMARY KEY, ADD PRIMARY KEY(id, order_id)");
444
    }
445
}
446
447
/**
448
 * Check if cart processing table exists
449
 */
450
function checkCartProcessTable()
451
{
452
    global $wpdb;
453
    $tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE;
454
455
    if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
456
457
        $charset_collate = $wpdb->get_charset_collate();
458
        $sql = "CREATE TABLE IF NOT EXISTS $tableName(
459
            `id` INT AUTO_INCREMENT, 
460
            `order_id` varchar(60),
461
            `wc_order_id` varchar(60),
462
            `token` varchar(32) NOT NULL,
463
             PRIMARY KEY (`id`, `order_id`)
464
            )$charset_collate";
465
466
        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...
467
        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

467
        /** @scrutinizer ignore-call */ 
468
        dbDelta($sql);
Loading history...
468
    }
469
}
470
471
472
/**
473
 * Get the orders of a customer
474
 *
475
 * @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...
476
 * @param $billingEmail
477
 *
478
 * @return mixed
479
 * @uses Wordpress Core Post API
480
 */
481
function getOrders($current_user, $billingEmail)
482
{
483
    $sign_up         = '';
484
    $total_orders    = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_orders is dead and can be removed.
Loading history...
485
    $total_amt       = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_amt is dead and can be removed.
Loading history...
486
    $refund_amt      = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $refund_amt is dead and can be removed.
Loading history...
487
    $total_refunds   = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_refunds is dead and can be removed.
Loading history...
488
    $partial_refunds = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $partial_refunds is dead and can be removed.
Loading history...
489
    if ($current_user->user_login) {
490
        $is_guest        = "false";
0 ignored issues
show
Unused Code introduced by
The assignment to $is_guest is dead and can be removed.
Loading history...
491
        $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...
492
        $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

492
        $customer_orders = /** @scrutinizer ignore-call */ get_posts(array(
Loading history...
493
            'numberposts' => -1,
494
            'meta_key'    => '_customer_user',
495
            'meta_value'  => $current_user->ID,
496
            'post_type'   => array('shop_order'),
497
            'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
498
        ));
499
    } else {
500
        $is_guest        = "true";
501
        $customer_orders = get_posts(array(
502
            'numberposts' => -1,
503
            'meta_key'    => '_billing_email',
504
            'meta_value'  => $billingEmail,
505
            'post_type'   => array('shop_order'),
506
            'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
507
        ));
508
        foreach ($customer_orders as $customer_order) {
509
            if (trim($sign_up) == '' || strtotime(substr($customer_order->post_date, 0, 10)) <= strtotime($sign_up)) {
510
                $sign_up = substr($customer_order->post_date, 0, 10);
511
            }
512
        }
513
    }
514
515
    return $customer_orders;
516
}
517