Passed
Pull Request — master (#37)
by Kiran
03:38
created
includes/wpinv-address-functions.php 1 patch
Spacing   +979 added lines, -979 removed lines patch added patch discarded remove patch
@@ -7,67 +7,67 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21
-function wpinv_is_base_country( $country ) {
21
+function wpinv_is_base_country($country) {
22 22
     $base_country = wpinv_get_default_country();
23 23
     
24
-    if ( $base_country === 'UK' ) {
24
+    if ($base_country === 'UK') {
25 25
         $base_country = 'GB';
26 26
     }
27
-    if ( $country == 'UK' ) {
27
+    if ($country == 'UK') {
28 28
         $country = 'GB';
29 29
     }
30 30
 
31
-    return ( $country && $country === $base_country ) ? true : false;
31
+    return ($country && $country === $base_country) ? true : false;
32 32
 }
33 33
 
34
-function wpinv_country_name( $country_code = '' ) { 
34
+function wpinv_country_name($country_code = '') { 
35 35
     $countries = wpinv_get_country_list();
36 36
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
37
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
37
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
38 38
 
39
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
39
+    return apply_filters('wpinv_country_name', $country, $country_code);
40 40
 }
41 41
 
42 42
 function wpinv_get_default_state() {
43
-	$state = wpinv_get_option( 'default_state', false );
43
+	$state = wpinv_get_option('default_state', false);
44 44
 
45
-	return apply_filters( 'wpinv_default_state', $state );
45
+	return apply_filters('wpinv_default_state', $state);
46 46
 }
47 47
 
48
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
48
+function wpinv_state_name($state_code = '', $country_code = '') {
49 49
     $state = $state_code;
50 50
     
51
-    if ( !empty( $country_code ) ) {
52
-        $states = wpinv_get_country_states( $country_code );
51
+    if (!empty($country_code)) {
52
+        $states = wpinv_get_country_states($country_code);
53 53
         
54
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
54
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
55 55
     }
56 56
 
57
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
57
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
58 58
 }
59 59
 
60 60
 function wpinv_store_address() {
61
-    $address = wpinv_get_option( 'store_address', '' );
61
+    $address = wpinv_get_option('store_address', '');
62 62
 
63
-    return apply_filters( 'wpinv_store_address', $address );
63
+    return apply_filters('wpinv_store_address', $address);
64 64
 }
65 65
 
66
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
66
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
67 67
     global $wpi_userID;
68 68
     
69
-    if( empty( $user_id ) ) {
70
-        $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id();
69
+    if (empty($user_id)) {
70
+        $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id();
71 71
     }
72 72
     
73 73
     $address_fields = array(
@@ -85,36 +85,36 @@  discard block
 block discarded – undo
85 85
         'zip',
86 86
     );
87 87
     
88
-    $user_info = get_userdata( $user_id );
88
+    $user_info = get_userdata($user_id);
89 89
     
90 90
     $address = array();
91 91
     $address['user_id'] = $user_id;
92
-    $address['email'] = !empty( $user_info ) ? $user_info->user_email : '';
93
-    foreach ( $address_fields as $field ) {
94
-        $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true );
92
+    $address['email'] = !empty($user_info) ? $user_info->user_email : '';
93
+    foreach ($address_fields as $field) {
94
+        $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true);
95 95
     }
96 96
 
97
-    if ( !empty( $user_info ) ) {
98
-        if( empty( $address['first_name'] ) )
97
+    if (!empty($user_info)) {
98
+        if (empty($address['first_name']))
99 99
             $address['first_name'] = $user_info->first_name;
100 100
         
101
-        if( empty( $address['last_name'] ) )
101
+        if (empty($address['last_name']))
102 102
             $address['last_name'] = $user_info->last_name;
103 103
     }
104 104
     
105
-    $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
105
+    $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ",");
106 106
     
107
-    if( empty( $address['state'] ) && $with_default )
107
+    if (empty($address['state']) && $with_default)
108 108
         $address['state'] = wpinv_get_default_state();
109 109
 
110
-    if( empty( $address['country'] ) && $with_default )
110
+    if (empty($address['country']) && $with_default)
111 111
         $address['country'] = wpinv_get_default_country();
112 112
 
113 113
 
114 114
     return $address;
115 115
 }
116 116
 
117
-function wpinv_get_country_list( $first_empty = false ) {
117
+function wpinv_get_country_list($first_empty = false) {
118 118
 	$countries = array(
119 119
 		'US' => __('United States', 'invoicing'),
120 120
 		'CA' => __('Canada', 'invoicing'),
@@ -370,23 +370,23 @@  discard block
 block discarded – undo
370 370
 		'ZW' => __('Zimbabwe', 'invoicing'),
371 371
 	);
372 372
     
373
-    if ( $first_empty ) {
374
-        $countries = array_merge( array( '' => '' ), $countries );
373
+    if ($first_empty) {
374
+        $countries = array_merge(array('' => ''), $countries);
375 375
     }
376 376
     
377
-    $countries = apply_filters( 'wpinv_countries', $countries );
377
+    $countries = apply_filters('wpinv_countries', $countries);
378 378
     
379 379
     asort($countries);
380 380
 
381 381
     return $countries;
382 382
 }
383 383
 
384
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
385
-    if ( empty( $country ) ) {
384
+function wpinv_get_country_states($country = null, $first_empty = false) {
385
+    if (empty($country)) {
386 386
         $country = wpinv_get_default_country();
387 387
     }
388 388
 
389
-    switch( $country ) {
389
+    switch ($country) {
390 390
         case 'US' :
391 391
             $states = wpinv_get_us_states_list();
392 392
             break;
@@ -461,11 +461,11 @@  discard block
 block discarded – undo
461 461
             break;
462 462
     }
463 463
     
464
-    if ( !empty( $states ) && $first_empty ) {
465
-        $states = array_merge( array( '' => '' ), $states );
464
+    if (!empty($states) && $first_empty) {
465
+        $states = array_merge(array('' => ''), $states);
466 466
     }
467 467
     
468
-    $states = apply_filters( 'wpinv_country_states', $states, $country );
468
+    $states = apply_filters('wpinv_country_states', $states, $country);
469 469
     
470 470
     asort($states);
471 471
 
@@ -474,1087 +474,1087 @@  discard block
 block discarded – undo
474 474
 
475 475
 function wpinv_get_us_states_list() {
476 476
     $states = array(
477
-        'AL' => __( 'Alabama', 'invoicing' ),
478
-        'AK' => __( 'Alaska', 'invoicing' ),
479
-        'AZ' => __( 'Arizona', 'invoicing' ),
480
-        'AR' => __( 'Arkansas', 'invoicing' ),
481
-        'CA' => __( 'California', 'invoicing' ),
482
-        'CO' => __( 'Colorado', 'invoicing' ),
483
-        'CT' => __( 'Connecticut', 'invoicing' ),
484
-        'DE' => __( 'Delaware', 'invoicing' ),
485
-        'DC' => __( 'District of Columbia', 'invoicing' ),
486
-        'FL' => __( 'Florida', 'invoicing' ),
487
-        'GA' => __( 'Georgia', 'invoicing' ),
488
-        'HI' => __( 'Hawaii', 'invoicing' ),
489
-        'ID' => __( 'Idaho', 'invoicing' ),
490
-        'IL' => __( 'Illinois', 'invoicing' ),
491
-        'IN' => __( 'Indiana', 'invoicing' ),
492
-        'IA' => __( 'Iowa', 'invoicing' ),
493
-        'KS' => __( 'Kansas', 'invoicing' ),
494
-        'KY' => __( 'Kentucky', 'invoicing' ),
495
-        'LA' => __( 'Louisiana', 'invoicing' ),
496
-        'ME' => __( 'Maine', 'invoicing' ),
497
-        'MD' => __( 'Maryland', 'invoicing' ),
498
-        'MA' => __( 'Massachusetts', 'invoicing' ),
499
-        'MI' => __( 'Michigan', 'invoicing' ),
500
-        'MN' => __( 'Minnesota', 'invoicing' ),
501
-        'MS' => __( 'Mississippi', 'invoicing' ),
502
-        'MO' => __( 'Missouri', 'invoicing' ),
503
-        'MT' => __( 'Montana', 'invoicing' ),
504
-        'NE' => __( 'Nebraska', 'invoicing' ),
505
-        'NV' => __( 'Nevada', 'invoicing' ),
506
-        'NH' => __( 'New Hampshire', 'invoicing' ),
507
-        'NJ' => __( 'New Jersey', 'invoicing' ),
508
-        'NM' => __( 'New Mexico', 'invoicing' ),
509
-        'NY' => __( 'New York', 'invoicing' ),
510
-        'NC' => __( 'North Carolina', 'invoicing' ),
511
-        'ND' => __( 'North Dakota', 'invoicing' ),
512
-        'OH' => __( 'Ohio', 'invoicing' ),
513
-        'OK' => __( 'Oklahoma', 'invoicing' ),
514
-        'OR' => __( 'Oregon', 'invoicing' ),
515
-        'PA' => __( 'Pennsylvania', 'invoicing' ),
516
-        'RI' => __( 'Rhode Island', 'invoicing' ),
517
-        'SC' => __( 'South Carolina', 'invoicing' ),
518
-        'SD' => __( 'South Dakota', 'invoicing' ),
519
-        'TN' => __( 'Tennessee', 'invoicing' ),
520
-        'TX' => __( 'Texas', 'invoicing' ),
521
-        'UT' => __( 'Utah', 'invoicing' ),
522
-        'VT' => __( 'Vermont', 'invoicing' ),
523
-        'VA' => __( 'Virginia', 'invoicing' ),
524
-        'WA' => __( 'Washington', 'invoicing' ),
525
-        'WV' => __( 'West Virginia', 'invoicing' ),
526
-        'WI' => __( 'Wisconsin', 'invoicing' ),
527
-        'WY' => __( 'Wyoming', 'invoicing' ),
528
-        'AS' => __( 'American Samoa', 'invoicing' ),
529
-        'CZ' => __( 'Canal Zone', 'invoicing' ),
530
-        'CM' => __( 'Commonwealth of the Northern Mariana Islands', 'invoicing' ),
531
-        'FM' => __( 'Federated States of Micronesia', 'invoicing' ),
532
-        'GU' => __( 'Guam', 'invoicing' ),
533
-        'MH' => __( 'Marshall Islands', 'invoicing' ),
534
-        'MP' => __( 'Northern Mariana Islands', 'invoicing' ),
535
-        'PW' => __( 'Palau', 'invoicing' ),
536
-        'PI' => __( 'Philippine Islands', 'invoicing' ),
537
-        'PR' => __( 'Puerto Rico', 'invoicing' ),
538
-        'TT' => __( 'Trust Territory of the Pacific Islands', 'invoicing' ),
539
-        'VI' => __( 'Virgin Islands', 'invoicing' ),
540
-        'AA' => __( 'Armed Forces - Americas', 'invoicing' ),
541
-        'AE' => __( 'Armed Forces - Europe, Canada, Middle East, Africa', 'invoicing' ),
542
-        'AP' => __( 'Armed Forces - Pacific', 'invoicing' )
477
+        'AL' => __('Alabama', 'invoicing'),
478
+        'AK' => __('Alaska', 'invoicing'),
479
+        'AZ' => __('Arizona', 'invoicing'),
480
+        'AR' => __('Arkansas', 'invoicing'),
481
+        'CA' => __('California', 'invoicing'),
482
+        'CO' => __('Colorado', 'invoicing'),
483
+        'CT' => __('Connecticut', 'invoicing'),
484
+        'DE' => __('Delaware', 'invoicing'),
485
+        'DC' => __('District of Columbia', 'invoicing'),
486
+        'FL' => __('Florida', 'invoicing'),
487
+        'GA' => __('Georgia', 'invoicing'),
488
+        'HI' => __('Hawaii', 'invoicing'),
489
+        'ID' => __('Idaho', 'invoicing'),
490
+        'IL' => __('Illinois', 'invoicing'),
491
+        'IN' => __('Indiana', 'invoicing'),
492
+        'IA' => __('Iowa', 'invoicing'),
493
+        'KS' => __('Kansas', 'invoicing'),
494
+        'KY' => __('Kentucky', 'invoicing'),
495
+        'LA' => __('Louisiana', 'invoicing'),
496
+        'ME' => __('Maine', 'invoicing'),
497
+        'MD' => __('Maryland', 'invoicing'),
498
+        'MA' => __('Massachusetts', 'invoicing'),
499
+        'MI' => __('Michigan', 'invoicing'),
500
+        'MN' => __('Minnesota', 'invoicing'),
501
+        'MS' => __('Mississippi', 'invoicing'),
502
+        'MO' => __('Missouri', 'invoicing'),
503
+        'MT' => __('Montana', 'invoicing'),
504
+        'NE' => __('Nebraska', 'invoicing'),
505
+        'NV' => __('Nevada', 'invoicing'),
506
+        'NH' => __('New Hampshire', 'invoicing'),
507
+        'NJ' => __('New Jersey', 'invoicing'),
508
+        'NM' => __('New Mexico', 'invoicing'),
509
+        'NY' => __('New York', 'invoicing'),
510
+        'NC' => __('North Carolina', 'invoicing'),
511
+        'ND' => __('North Dakota', 'invoicing'),
512
+        'OH' => __('Ohio', 'invoicing'),
513
+        'OK' => __('Oklahoma', 'invoicing'),
514
+        'OR' => __('Oregon', 'invoicing'),
515
+        'PA' => __('Pennsylvania', 'invoicing'),
516
+        'RI' => __('Rhode Island', 'invoicing'),
517
+        'SC' => __('South Carolina', 'invoicing'),
518
+        'SD' => __('South Dakota', 'invoicing'),
519
+        'TN' => __('Tennessee', 'invoicing'),
520
+        'TX' => __('Texas', 'invoicing'),
521
+        'UT' => __('Utah', 'invoicing'),
522
+        'VT' => __('Vermont', 'invoicing'),
523
+        'VA' => __('Virginia', 'invoicing'),
524
+        'WA' => __('Washington', 'invoicing'),
525
+        'WV' => __('West Virginia', 'invoicing'),
526
+        'WI' => __('Wisconsin', 'invoicing'),
527
+        'WY' => __('Wyoming', 'invoicing'),
528
+        'AS' => __('American Samoa', 'invoicing'),
529
+        'CZ' => __('Canal Zone', 'invoicing'),
530
+        'CM' => __('Commonwealth of the Northern Mariana Islands', 'invoicing'),
531
+        'FM' => __('Federated States of Micronesia', 'invoicing'),
532
+        'GU' => __('Guam', 'invoicing'),
533
+        'MH' => __('Marshall Islands', 'invoicing'),
534
+        'MP' => __('Northern Mariana Islands', 'invoicing'),
535
+        'PW' => __('Palau', 'invoicing'),
536
+        'PI' => __('Philippine Islands', 'invoicing'),
537
+        'PR' => __('Puerto Rico', 'invoicing'),
538
+        'TT' => __('Trust Territory of the Pacific Islands', 'invoicing'),
539
+        'VI' => __('Virgin Islands', 'invoicing'),
540
+        'AA' => __('Armed Forces - Americas', 'invoicing'),
541
+        'AE' => __('Armed Forces - Europe, Canada, Middle East, Africa', 'invoicing'),
542
+        'AP' => __('Armed Forces - Pacific', 'invoicing')
543 543
     );
544 544
 
545
-    return apply_filters( 'wpinv_us_states', $states );
545
+    return apply_filters('wpinv_us_states', $states);
546 546
 }
547 547
 
548 548
 function wpinv_get_canada_states_list() {
549 549
     $states = array(
550
-        'AB' => __( 'Alberta', 'invoicing' ),
551
-        'BC' => __( 'British Columbia', 'invoicing' ),
552
-        'MB' => __( 'Manitoba', 'invoicing' ),
553
-        'NB' => __( 'New Brunswick', 'invoicing' ),
554
-        'NL' => __( 'Newfoundland and Labrador', 'invoicing' ),
555
-        'NS' => __( 'Nova Scotia', 'invoicing' ),
556
-        'NT' => __( 'Northwest Territories', 'invoicing' ),
557
-        'NU' => __( 'Nunavut', 'invoicing' ),
558
-        'ON' => __( 'Ontario', 'invoicing' ),
559
-        'PE' => __( 'Prince Edward Island', 'invoicing' ),
560
-        'QC' => __( 'Quebec', 'invoicing' ),
561
-        'SK' => __( 'Saskatchewan', 'invoicing' ),
562
-        'YT' => __( 'Yukon', 'invoicing' )
550
+        'AB' => __('Alberta', 'invoicing'),
551
+        'BC' => __('British Columbia', 'invoicing'),
552
+        'MB' => __('Manitoba', 'invoicing'),
553
+        'NB' => __('New Brunswick', 'invoicing'),
554
+        'NL' => __('Newfoundland and Labrador', 'invoicing'),
555
+        'NS' => __('Nova Scotia', 'invoicing'),
556
+        'NT' => __('Northwest Territories', 'invoicing'),
557
+        'NU' => __('Nunavut', 'invoicing'),
558
+        'ON' => __('Ontario', 'invoicing'),
559
+        'PE' => __('Prince Edward Island', 'invoicing'),
560
+        'QC' => __('Quebec', 'invoicing'),
561
+        'SK' => __('Saskatchewan', 'invoicing'),
562
+        'YT' => __('Yukon', 'invoicing')
563 563
     );
564 564
 
565
-    return apply_filters( 'wpinv_canada_provinces', $states );
565
+    return apply_filters('wpinv_canada_provinces', $states);
566 566
 }
567 567
 
568 568
 function wpinv_get_australia_states_list() {
569 569
     $states = array(
570
-        'ACT' => __( 'Australian Capital Territory', 'invoicing' ),
571
-        'NSW' => __( 'New South Wales', 'invoicing' ),
572
-        'NT'  => __( 'Northern Territory', 'invoicing' ),
573
-        'QLD' => __( 'Queensland', 'invoicing' ),
574
-        'SA'  => __( 'South Australia', 'invoicing' ),
575
-        'TAS' => __( 'Tasmania', 'invoicing' ),
576
-        'VIC' => __( 'Victoria', 'invoicing' ),
577
-        'WA'  => __( 'Western Australia', 'invoicing' )
570
+        'ACT' => __('Australian Capital Territory', 'invoicing'),
571
+        'NSW' => __('New South Wales', 'invoicing'),
572
+        'NT'  => __('Northern Territory', 'invoicing'),
573
+        'QLD' => __('Queensland', 'invoicing'),
574
+        'SA'  => __('South Australia', 'invoicing'),
575
+        'TAS' => __('Tasmania', 'invoicing'),
576
+        'VIC' => __('Victoria', 'invoicing'),
577
+        'WA'  => __('Western Australia', 'invoicing')
578 578
     );
579 579
 
580
-    return apply_filters( 'wpinv_australia_states', $states );
580
+    return apply_filters('wpinv_australia_states', $states);
581 581
 }
582 582
 
583 583
 function wpinv_get_bangladesh_states_list() {
584 584
     $states = array(
585
-        'BAG' => __( 'Bagerhat', 'invoicing' ),
586
-        'BAN' => __( 'Bandarban', 'invoicing' ),
587
-        'BAR' => __( 'Barguna', 'invoicing' ),
588
-        'BARI'=> __( 'Barisal', 'invoicing' ),
589
-        'BHO' => __( 'Bhola', 'invoicing' ),
590
-        'BOG' => __( 'Bogra', 'invoicing' ),
591
-        'BRA' => __( 'Brahmanbaria', 'invoicing' ),
592
-        'CHA' => __( 'Chandpur', 'invoicing' ),
593
-        'CHI' => __( 'Chittagong', 'invoicing' ),
594
-        'CHU' => __( 'Chuadanga', 'invoicing' ),
595
-        'COM' => __( 'Comilla', 'invoicing' ),
596
-        'COX' => __( 'Cox\'s Bazar', 'invoicing' ),
597
-        'DHA' => __( 'Dhaka', 'invoicing' ),
598
-        'DIN' => __( 'Dinajpur', 'invoicing' ),
599
-        'FAR' => __( 'Faridpur', 'invoicing' ),
600
-        'FEN' => __( 'Feni', 'invoicing' ),
601
-        'GAI' => __( 'Gaibandha', 'invoicing' ),
602
-        'GAZI'=> __( 'Gazipur', 'invoicing' ),
603
-        'GOP' => __( 'Gopalganj', 'invoicing' ),
604
-        'HAB' => __( 'Habiganj', 'invoicing' ),
605
-        'JAM' => __( 'Jamalpur', 'invoicing' ),
606
-        'JES' => __( 'Jessore', 'invoicing' ),
607
-        'JHA' => __( 'Jhalokati', 'invoicing' ),
608
-        'JHE' => __( 'Jhenaidah', 'invoicing' ),
609
-        'JOY' => __( 'Joypurhat', 'invoicing' ),
610
-        'KHA' => __( 'Khagrachhari', 'invoicing' ),
611
-        'KHU' => __( 'Khulna', 'invoicing' ),
612
-        'KIS' => __( 'Kishoreganj', 'invoicing' ),
613
-        'KUR' => __( 'Kurigram', 'invoicing' ),
614
-        'KUS' => __( 'Kushtia', 'invoicing' ),
615
-        'LAK' => __( 'Lakshmipur', 'invoicing' ),
616
-        'LAL' => __( 'Lalmonirhat', 'invoicing' ),
617
-        'MAD' => __( 'Madaripur', 'invoicing' ),
618
-        'MAG' => __( 'Magura', 'invoicing' ),
619
-        'MAN' => __( 'Manikganj', 'invoicing' ),
620
-        'MEH' => __( 'Meherpur', 'invoicing' ),
621
-        'MOU' => __( 'Moulvibazar', 'invoicing' ),
622
-        'MUN' => __( 'Munshiganj', 'invoicing' ),
623
-        'MYM' => __( 'Mymensingh', 'invoicing' ),
624
-        'NAO' => __( 'Naogaon', 'invoicing' ),
625
-        'NAR' => __( 'Narail', 'invoicing' ),
626
-        'NARG'=> __( 'Narayanganj', 'invoicing' ),
627
-        'NARD'=> __( 'Narsingdi', 'invoicing' ),
628
-        'NAT' => __( 'Natore', 'invoicing' ),
629
-        'NAW' => __( 'Nawabganj', 'invoicing' ),
630
-        'NET' => __( 'Netrakona', 'invoicing' ),
631
-        'NIL' => __( 'Nilphamari', 'invoicing' ),
632
-        'NOA' => __( 'Noakhali', 'invoicing' ),
633
-        'PAB' => __( 'Pabna', 'invoicing' ),
634
-        'PAN' => __( 'Panchagarh', 'invoicing' ),
635
-        'PAT' => __( 'Patuakhali', 'invoicing' ),
636
-        'PIR' => __( 'Pirojpur', 'invoicing' ),
637
-        'RAJB'=> __( 'Rajbari', 'invoicing' ),
638
-        'RAJ' => __( 'Rajshahi', 'invoicing' ),
639
-        'RAN' => __( 'Rangamati', 'invoicing' ),
640
-        'RANP'=> __( 'Rangpur', 'invoicing' ),
641
-        'SAT' => __( 'Satkhira', 'invoicing' ),
642
-        'SHA' => __( 'Shariatpur', 'invoicing' ),
643
-        'SHE' => __( 'Sherpur', 'invoicing' ),
644
-        'SIR' => __( 'Sirajganj', 'invoicing' ),
645
-        'SUN' => __( 'Sunamganj', 'invoicing' ),
646
-        'SYL' => __( 'Sylhet', 'invoicing' ),
647
-        'TAN' => __( 'Tangail', 'invoicing' ),
648
-        'THA' => __( 'Thakurgaon', 'invoicing' )
585
+        'BAG' => __('Bagerhat', 'invoicing'),
586
+        'BAN' => __('Bandarban', 'invoicing'),
587
+        'BAR' => __('Barguna', 'invoicing'),
588
+        'BARI'=> __('Barisal', 'invoicing'),
589
+        'BHO' => __('Bhola', 'invoicing'),
590
+        'BOG' => __('Bogra', 'invoicing'),
591
+        'BRA' => __('Brahmanbaria', 'invoicing'),
592
+        'CHA' => __('Chandpur', 'invoicing'),
593
+        'CHI' => __('Chittagong', 'invoicing'),
594
+        'CHU' => __('Chuadanga', 'invoicing'),
595
+        'COM' => __('Comilla', 'invoicing'),
596
+        'COX' => __('Cox\'s Bazar', 'invoicing'),
597
+        'DHA' => __('Dhaka', 'invoicing'),
598
+        'DIN' => __('Dinajpur', 'invoicing'),
599
+        'FAR' => __('Faridpur', 'invoicing'),
600
+        'FEN' => __('Feni', 'invoicing'),
601
+        'GAI' => __('Gaibandha', 'invoicing'),
602
+        'GAZI'=> __('Gazipur', 'invoicing'),
603
+        'GOP' => __('Gopalganj', 'invoicing'),
604
+        'HAB' => __('Habiganj', 'invoicing'),
605
+        'JAM' => __('Jamalpur', 'invoicing'),
606
+        'JES' => __('Jessore', 'invoicing'),
607
+        'JHA' => __('Jhalokati', 'invoicing'),
608
+        'JHE' => __('Jhenaidah', 'invoicing'),
609
+        'JOY' => __('Joypurhat', 'invoicing'),
610
+        'KHA' => __('Khagrachhari', 'invoicing'),
611
+        'KHU' => __('Khulna', 'invoicing'),
612
+        'KIS' => __('Kishoreganj', 'invoicing'),
613
+        'KUR' => __('Kurigram', 'invoicing'),
614
+        'KUS' => __('Kushtia', 'invoicing'),
615
+        'LAK' => __('Lakshmipur', 'invoicing'),
616
+        'LAL' => __('Lalmonirhat', 'invoicing'),
617
+        'MAD' => __('Madaripur', 'invoicing'),
618
+        'MAG' => __('Magura', 'invoicing'),
619
+        'MAN' => __('Manikganj', 'invoicing'),
620
+        'MEH' => __('Meherpur', 'invoicing'),
621
+        'MOU' => __('Moulvibazar', 'invoicing'),
622
+        'MUN' => __('Munshiganj', 'invoicing'),
623
+        'MYM' => __('Mymensingh', 'invoicing'),
624
+        'NAO' => __('Naogaon', 'invoicing'),
625
+        'NAR' => __('Narail', 'invoicing'),
626
+        'NARG'=> __('Narayanganj', 'invoicing'),
627
+        'NARD'=> __('Narsingdi', 'invoicing'),
628
+        'NAT' => __('Natore', 'invoicing'),
629
+        'NAW' => __('Nawabganj', 'invoicing'),
630
+        'NET' => __('Netrakona', 'invoicing'),
631
+        'NIL' => __('Nilphamari', 'invoicing'),
632
+        'NOA' => __('Noakhali', 'invoicing'),
633
+        'PAB' => __('Pabna', 'invoicing'),
634
+        'PAN' => __('Panchagarh', 'invoicing'),
635
+        'PAT' => __('Patuakhali', 'invoicing'),
636
+        'PIR' => __('Pirojpur', 'invoicing'),
637
+        'RAJB'=> __('Rajbari', 'invoicing'),
638
+        'RAJ' => __('Rajshahi', 'invoicing'),
639
+        'RAN' => __('Rangamati', 'invoicing'),
640
+        'RANP'=> __('Rangpur', 'invoicing'),
641
+        'SAT' => __('Satkhira', 'invoicing'),
642
+        'SHA' => __('Shariatpur', 'invoicing'),
643
+        'SHE' => __('Sherpur', 'invoicing'),
644
+        'SIR' => __('Sirajganj', 'invoicing'),
645
+        'SUN' => __('Sunamganj', 'invoicing'),
646
+        'SYL' => __('Sylhet', 'invoicing'),
647
+        'TAN' => __('Tangail', 'invoicing'),
648
+        'THA' => __('Thakurgaon', 'invoicing')
649 649
     );
650 650
 
651
-    return apply_filters( 'wpinv_bangladesh_states', $states );
651
+    return apply_filters('wpinv_bangladesh_states', $states);
652 652
 }
653 653
 
654 654
 function wpinv_get_brazil_states_list() {
655 655
     $states = array(
656
-        'AC' => __( 'Acre', 'invoicing' ),
657
-        'AL' => __( 'Alagoas', 'invoicing' ),
658
-        'AP' => __( 'Amapá', 'invoicing' ),
659
-        'AM' => __( 'Amazonas', 'invoicing' ),
660
-        'BA' => __( 'Bahia', 'invoicing' ),
661
-        'CE' => __( 'Ceará', 'invoicing' ),
662
-        'DF' => __( 'Distrito Federal', 'invoicing' ),
663
-        'ES' => __( 'Espírito Santo', 'invoicing' ),
664
-        'GO' => __( 'Goiás', 'invoicing' ),
665
-        'MA' => __( 'Maranhão', 'invoicing' ),
666
-        'MT' => __( 'Mato Grosso', 'invoicing' ),
667
-        'MS' => __( 'Mato Grosso do Sul', 'invoicing' ),
668
-        'MG' => __( 'Minas Gerais', 'invoicing' ),
669
-        'PA' => __( 'Pará', 'invoicing' ),
670
-        'PB' => __( 'Paraíba', 'invoicing' ),
671
-        'PR' => __( 'Paraná', 'invoicing' ),
672
-        'PE' => __( 'Pernambuco', 'invoicing' ),
673
-        'PI' => __( 'Piauí', 'invoicing' ),
674
-        'RJ' => __( 'Rio de Janeiro', 'invoicing' ),
675
-        'RN' => __( 'Rio Grande do Norte', 'invoicing' ),
676
-        'RS' => __( 'Rio Grande do Sul', 'invoicing' ),
677
-        'RO' => __( 'Rondônia', 'invoicing' ),
678
-        'RR' => __( 'Roraima', 'invoicing' ),
679
-        'SC' => __( 'Santa Catarina', 'invoicing' ),
680
-        'SP' => __( 'São Paulo', 'invoicing' ),
681
-        'SE' => __( 'Sergipe', 'invoicing' ),
682
-        'TO' => __( 'Tocantins', 'invoicing' )
656
+        'AC' => __('Acre', 'invoicing'),
657
+        'AL' => __('Alagoas', 'invoicing'),
658
+        'AP' => __('Amapá', 'invoicing'),
659
+        'AM' => __('Amazonas', 'invoicing'),
660
+        'BA' => __('Bahia', 'invoicing'),
661
+        'CE' => __('Ceará', 'invoicing'),
662
+        'DF' => __('Distrito Federal', 'invoicing'),
663
+        'ES' => __('Espírito Santo', 'invoicing'),
664
+        'GO' => __('Goiás', 'invoicing'),
665
+        'MA' => __('Maranhão', 'invoicing'),
666
+        'MT' => __('Mato Grosso', 'invoicing'),
667
+        'MS' => __('Mato Grosso do Sul', 'invoicing'),
668
+        'MG' => __('Minas Gerais', 'invoicing'),
669
+        'PA' => __('Pará', 'invoicing'),
670
+        'PB' => __('Paraíba', 'invoicing'),
671
+        'PR' => __('Paraná', 'invoicing'),
672
+        'PE' => __('Pernambuco', 'invoicing'),
673
+        'PI' => __('Piauí', 'invoicing'),
674
+        'RJ' => __('Rio de Janeiro', 'invoicing'),
675
+        'RN' => __('Rio Grande do Norte', 'invoicing'),
676
+        'RS' => __('Rio Grande do Sul', 'invoicing'),
677
+        'RO' => __('Rondônia', 'invoicing'),
678
+        'RR' => __('Roraima', 'invoicing'),
679
+        'SC' => __('Santa Catarina', 'invoicing'),
680
+        'SP' => __('São Paulo', 'invoicing'),
681
+        'SE' => __('Sergipe', 'invoicing'),
682
+        'TO' => __('Tocantins', 'invoicing')
683 683
     );
684 684
 
685
-    return apply_filters( 'wpinv_brazil_states', $states );
685
+    return apply_filters('wpinv_brazil_states', $states);
686 686
 }
687 687
 
688 688
 function wpinv_get_bulgaria_states_list() {
689 689
     $states = array(
690
-        'BG-01' => __( 'Blagoevgrad', 'invoicing' ),
691
-        'BG-02' => __( 'Burgas', 'invoicing' ),
692
-        'BG-08' => __( 'Dobrich', 'invoicing' ),
693
-        'BG-07' => __( 'Gabrovo', 'invoicing' ),
694
-        'BG-26' => __( 'Haskovo', 'invoicing' ),
695
-        'BG-09' => __( 'Kardzhali', 'invoicing' ),
696
-        'BG-10' => __( 'Kyustendil', 'invoicing' ),
697
-        'BG-11' => __( 'Lovech', 'invoicing' ),
698
-        'BG-12' => __( 'Montana', 'invoicing' ),
699
-        'BG-13' => __( 'Pazardzhik', 'invoicing' ),
700
-        'BG-14' => __( 'Pernik', 'invoicing' ),
701
-        'BG-15' => __( 'Pleven', 'invoicing' ),
702
-        'BG-16' => __( 'Plovdiv', 'invoicing' ),
703
-        'BG-17' => __( 'Razgrad', 'invoicing' ),
704
-        'BG-18' => __( 'Ruse', 'invoicing' ),
705
-        'BG-27' => __( 'Shumen', 'invoicing' ),
706
-        'BG-19' => __( 'Silistra', 'invoicing' ),
707
-        'BG-20' => __( 'Sliven', 'invoicing' ),
708
-        'BG-21' => __( 'Smolyan', 'invoicing' ),
709
-        'BG-23' => __( 'Sofia', 'invoicing' ),
710
-        'BG-22' => __( 'Sofia-Grad', 'invoicing' ),
711
-        'BG-24' => __( 'Stara Zagora', 'invoicing' ),
712
-        'BG-25' => __( 'Targovishte', 'invoicing' ),
713
-        'BG-03' => __( 'Varna', 'invoicing' ),
714
-        'BG-04' => __( 'Veliko Tarnovo', 'invoicing' ),
715
-        'BG-05' => __( 'Vidin', 'invoicing' ),
716
-        'BG-06' => __( 'Vratsa', 'invoicing' ),
717
-        'BG-28' => __( 'Yambol', 'invoicing' )
690
+        'BG-01' => __('Blagoevgrad', 'invoicing'),
691
+        'BG-02' => __('Burgas', 'invoicing'),
692
+        'BG-08' => __('Dobrich', 'invoicing'),
693
+        'BG-07' => __('Gabrovo', 'invoicing'),
694
+        'BG-26' => __('Haskovo', 'invoicing'),
695
+        'BG-09' => __('Kardzhali', 'invoicing'),
696
+        'BG-10' => __('Kyustendil', 'invoicing'),
697
+        'BG-11' => __('Lovech', 'invoicing'),
698
+        'BG-12' => __('Montana', 'invoicing'),
699
+        'BG-13' => __('Pazardzhik', 'invoicing'),
700
+        'BG-14' => __('Pernik', 'invoicing'),
701
+        'BG-15' => __('Pleven', 'invoicing'),
702
+        'BG-16' => __('Plovdiv', 'invoicing'),
703
+        'BG-17' => __('Razgrad', 'invoicing'),
704
+        'BG-18' => __('Ruse', 'invoicing'),
705
+        'BG-27' => __('Shumen', 'invoicing'),
706
+        'BG-19' => __('Silistra', 'invoicing'),
707
+        'BG-20' => __('Sliven', 'invoicing'),
708
+        'BG-21' => __('Smolyan', 'invoicing'),
709
+        'BG-23' => __('Sofia', 'invoicing'),
710
+        'BG-22' => __('Sofia-Grad', 'invoicing'),
711
+        'BG-24' => __('Stara Zagora', 'invoicing'),
712
+        'BG-25' => __('Targovishte', 'invoicing'),
713
+        'BG-03' => __('Varna', 'invoicing'),
714
+        'BG-04' => __('Veliko Tarnovo', 'invoicing'),
715
+        'BG-05' => __('Vidin', 'invoicing'),
716
+        'BG-06' => __('Vratsa', 'invoicing'),
717
+        'BG-28' => __('Yambol', 'invoicing')
718 718
     );
719 719
 
720
-    return apply_filters( 'wpinv_bulgaria_states', $states );
720
+    return apply_filters('wpinv_bulgaria_states', $states);
721 721
 }
722 722
 
723 723
 function wpinv_get_hong_kong_states_list() {
724 724
     $states = array(
725
-        'HONG KONG'       => __( 'Hong Kong Island', 'invoicing' ),
726
-        'KOWLOON'         => __( 'Kowloon', 'invoicing' ),
727
-        'NEW TERRITORIES' => __( 'New Territories', 'invoicing' )
725
+        'HONG KONG'       => __('Hong Kong Island', 'invoicing'),
726
+        'KOWLOON'         => __('Kowloon', 'invoicing'),
727
+        'NEW TERRITORIES' => __('New Territories', 'invoicing')
728 728
     );
729 729
 
730
-    return apply_filters( 'wpinv_hong_kong_states', $states );
730
+    return apply_filters('wpinv_hong_kong_states', $states);
731 731
 }
732 732
 
733 733
 function wpinv_get_hungary_states_list() {
734 734
     $states = array(
735
-        'BK' => __( 'Bács-Kiskun', 'invoicing' ),
736
-        'BE' => __( 'Békés', 'invoicing' ),
737
-        'BA' => __( 'Baranya', 'invoicing' ),
738
-        'BZ' => __( 'Borsod-Abaúj-Zemplén', 'invoicing' ),
739
-        'BU' => __( 'Budapest', 'invoicing' ),
740
-        'CS' => __( 'Csongrád', 'invoicing' ),
741
-        'FE' => __( 'Fejér', 'invoicing' ),
742
-        'GS' => __( 'Győr-Moson-Sopron', 'invoicing' ),
743
-        'HB' => __( 'Hajdú-Bihar', 'invoicing' ),
744
-        'HE' => __( 'Heves', 'invoicing' ),
745
-        'JN' => __( 'Jász-Nagykun-Szolnok', 'invoicing' ),
746
-        'KE' => __( 'Komárom-Esztergom', 'invoicing' ),
747
-        'NO' => __( 'Nógrád', 'invoicing' ),
748
-        'PE' => __( 'Pest', 'invoicing' ),
749
-        'SO' => __( 'Somogy', 'invoicing' ),
750
-        'SZ' => __( 'Szabolcs-Szatmár-Bereg', 'invoicing' ),
751
-        'TO' => __( 'Tolna', 'invoicing' ),
752
-        'VA' => __( 'Vas', 'invoicing' ),
753
-        'VE' => __( 'Veszprém', 'invoicing' ),
754
-        'ZA' => __( 'Zala', 'invoicing' )
735
+        'BK' => __('Bács-Kiskun', 'invoicing'),
736
+        'BE' => __('Békés', 'invoicing'),
737
+        'BA' => __('Baranya', 'invoicing'),
738
+        'BZ' => __('Borsod-Abaúj-Zemplén', 'invoicing'),
739
+        'BU' => __('Budapest', 'invoicing'),
740
+        'CS' => __('Csongrád', 'invoicing'),
741
+        'FE' => __('Fejér', 'invoicing'),
742
+        'GS' => __('Győr-Moson-Sopron', 'invoicing'),
743
+        'HB' => __('Hajdú-Bihar', 'invoicing'),
744
+        'HE' => __('Heves', 'invoicing'),
745
+        'JN' => __('Jász-Nagykun-Szolnok', 'invoicing'),
746
+        'KE' => __('Komárom-Esztergom', 'invoicing'),
747
+        'NO' => __('Nógrád', 'invoicing'),
748
+        'PE' => __('Pest', 'invoicing'),
749
+        'SO' => __('Somogy', 'invoicing'),
750
+        'SZ' => __('Szabolcs-Szatmár-Bereg', 'invoicing'),
751
+        'TO' => __('Tolna', 'invoicing'),
752
+        'VA' => __('Vas', 'invoicing'),
753
+        'VE' => __('Veszprém', 'invoicing'),
754
+        'ZA' => __('Zala', 'invoicing')
755 755
     );
756 756
 
757
-    return apply_filters( 'wpinv_hungary_states', $states );
757
+    return apply_filters('wpinv_hungary_states', $states);
758 758
 }
759 759
 
760 760
 function wpinv_get_japan_states_list() {
761 761
     $states = array(
762
-        'JP01' => __( 'Hokkaido', 'invoicing' ),
763
-        'JP02' => __( 'Aomori', 'invoicing' ),
764
-        'JP03' => __( 'Iwate', 'invoicing' ),
765
-        'JP04' => __( 'Miyagi', 'invoicing' ),
766
-        'JP05' => __( 'Akita', 'invoicing' ),
767
-        'JP06' => __( 'Yamagata', 'invoicing' ),
768
-        'JP07' => __( 'Fukushima', 'invoicing' ),
769
-        'JP08' => __( 'Ibaraki', 'invoicing' ),
770
-        'JP09' => __( 'Tochigi', 'invoicing' ),
771
-        'JP10' => __( 'Gunma', 'invoicing' ),
772
-        'JP11' => __( 'Saitama', 'invoicing' ),
773
-        'JP12' => __( 'Chiba', 'invoicing' ),
774
-        'JP13' => __( 'Tokyo', 'invoicing' ),
775
-        'JP14' => __( 'Kanagawa', 'invoicing' ),
776
-        'JP15' => __( 'Niigata', 'invoicing' ),
777
-        'JP16' => __( 'Toyama', 'invoicing' ),
778
-        'JP17' => __( 'Ishikawa', 'invoicing' ),
779
-        'JP18' => __( 'Fukui', 'invoicing' ),
780
-        'JP19' => __( 'Yamanashi', 'invoicing' ),
781
-        'JP20' => __( 'Nagano', 'invoicing' ),
782
-        'JP21' => __( 'Gifu', 'invoicing' ),
783
-        'JP22' => __( 'Shizuoka', 'invoicing' ),
784
-        'JP23' => __( 'Aichi', 'invoicing' ),
785
-        'JP24' => __( 'Mie', 'invoicing' ),
786
-        'JP25' => __( 'Shiga', 'invoicing' ),
787
-        'JP26' => __( 'Kyouto', 'invoicing' ),
788
-        'JP27' => __( 'Osaka', 'invoicing' ),
789
-        'JP28' => __( 'Hyougo', 'invoicing' ),
790
-        'JP29' => __( 'Nara', 'invoicing' ),
791
-        'JP30' => __( 'Wakayama', 'invoicing' ),
792
-        'JP31' => __( 'Tottori', 'invoicing' ),
793
-        'JP32' => __( 'Shimane', 'invoicing' ),
794
-        'JP33' => __( 'Okayama', 'invoicing' ),
795
-        'JP34' => __( 'Hiroshima', 'invoicing' ),
796
-        'JP35' => __( 'Yamaguchi', 'invoicing' ),
797
-        'JP36' => __( 'Tokushima', 'invoicing' ),
798
-        'JP37' => __( 'Kagawa', 'invoicing' ),
799
-        'JP38' => __( 'Ehime', 'invoicing' ),
800
-        'JP39' => __( 'Kochi', 'invoicing' ),
801
-        'JP40' => __( 'Fukuoka', 'invoicing' ),
802
-        'JP41' => __( 'Saga', 'invoicing' ),
803
-        'JP42' => __( 'Nagasaki', 'invoicing' ),
804
-        'JP43' => __( 'Kumamoto', 'invoicing' ),
805
-        'JP44' => __( 'Oita', 'invoicing' ),
806
-        'JP45' => __( 'Miyazaki', 'invoicing' ),
807
-        'JP46' => __( 'Kagoshima', 'invoicing' ),
808
-        'JP47' => __( 'Okinawa', 'invoicing' )
762
+        'JP01' => __('Hokkaido', 'invoicing'),
763
+        'JP02' => __('Aomori', 'invoicing'),
764
+        'JP03' => __('Iwate', 'invoicing'),
765
+        'JP04' => __('Miyagi', 'invoicing'),
766
+        'JP05' => __('Akita', 'invoicing'),
767
+        'JP06' => __('Yamagata', 'invoicing'),
768
+        'JP07' => __('Fukushima', 'invoicing'),
769
+        'JP08' => __('Ibaraki', 'invoicing'),
770
+        'JP09' => __('Tochigi', 'invoicing'),
771
+        'JP10' => __('Gunma', 'invoicing'),
772
+        'JP11' => __('Saitama', 'invoicing'),
773
+        'JP12' => __('Chiba', 'invoicing'),
774
+        'JP13' => __('Tokyo', 'invoicing'),
775
+        'JP14' => __('Kanagawa', 'invoicing'),
776
+        'JP15' => __('Niigata', 'invoicing'),
777
+        'JP16' => __('Toyama', 'invoicing'),
778
+        'JP17' => __('Ishikawa', 'invoicing'),
779
+        'JP18' => __('Fukui', 'invoicing'),
780
+        'JP19' => __('Yamanashi', 'invoicing'),
781
+        'JP20' => __('Nagano', 'invoicing'),
782
+        'JP21' => __('Gifu', 'invoicing'),
783
+        'JP22' => __('Shizuoka', 'invoicing'),
784
+        'JP23' => __('Aichi', 'invoicing'),
785
+        'JP24' => __('Mie', 'invoicing'),
786
+        'JP25' => __('Shiga', 'invoicing'),
787
+        'JP26' => __('Kyouto', 'invoicing'),
788
+        'JP27' => __('Osaka', 'invoicing'),
789
+        'JP28' => __('Hyougo', 'invoicing'),
790
+        'JP29' => __('Nara', 'invoicing'),
791
+        'JP30' => __('Wakayama', 'invoicing'),
792
+        'JP31' => __('Tottori', 'invoicing'),
793
+        'JP32' => __('Shimane', 'invoicing'),
794
+        'JP33' => __('Okayama', 'invoicing'),
795
+        'JP34' => __('Hiroshima', 'invoicing'),
796
+        'JP35' => __('Yamaguchi', 'invoicing'),
797
+        'JP36' => __('Tokushima', 'invoicing'),
798
+        'JP37' => __('Kagawa', 'invoicing'),
799
+        'JP38' => __('Ehime', 'invoicing'),
800
+        'JP39' => __('Kochi', 'invoicing'),
801
+        'JP40' => __('Fukuoka', 'invoicing'),
802
+        'JP41' => __('Saga', 'invoicing'),
803
+        'JP42' => __('Nagasaki', 'invoicing'),
804
+        'JP43' => __('Kumamoto', 'invoicing'),
805
+        'JP44' => __('Oita', 'invoicing'),
806
+        'JP45' => __('Miyazaki', 'invoicing'),
807
+        'JP46' => __('Kagoshima', 'invoicing'),
808
+        'JP47' => __('Okinawa', 'invoicing')
809 809
     );
810 810
 
811
-    return apply_filters( 'wpinv_japan_states', $states );
811
+    return apply_filters('wpinv_japan_states', $states);
812 812
 }
813 813
 
814 814
 function wpinv_get_china_states_list() {
815 815
     $states = array(
816
-        'CN1'  => __( 'Yunnan / 云南', 'invoicing' ),
817
-        'CN2'  => __( 'Beijing / 北京', 'invoicing' ),
818
-        'CN3'  => __( 'Tianjin / 天津', 'invoicing' ),
819
-        'CN4'  => __( 'Hebei / 河北', 'invoicing' ),
820
-        'CN5'  => __( 'Shanxi / 山西', 'invoicing' ),
821
-        'CN6'  => __( 'Inner Mongolia / 內蒙古', 'invoicing' ),
822
-        'CN7'  => __( 'Liaoning / 辽宁', 'invoicing' ),
823
-        'CN8'  => __( 'Jilin / 吉林', 'invoicing' ),
824
-        'CN9'  => __( 'Heilongjiang / 黑龙江', 'invoicing' ),
825
-        'CN10' => __( 'Shanghai / 上海', 'invoicing' ),
826
-        'CN11' => __( 'Jiangsu / 江苏', 'invoicing' ),
827
-        'CN12' => __( 'Zhejiang / 浙江', 'invoicing' ),
828
-        'CN13' => __( 'Anhui / 安徽', 'invoicing' ),
829
-        'CN14' => __( 'Fujian / 福建', 'invoicing' ),
830
-        'CN15' => __( 'Jiangxi / 江西', 'invoicing' ),
831
-        'CN16' => __( 'Shandong / 山东', 'invoicing' ),
832
-        'CN17' => __( 'Henan / 河南', 'invoicing' ),
833
-        'CN18' => __( 'Hubei / 湖北', 'invoicing' ),
834
-        'CN19' => __( 'Hunan / 湖南', 'invoicing' ),
835
-        'CN20' => __( 'Guangdong / 广东', 'invoicing' ),
836
-        'CN21' => __( 'Guangxi Zhuang / 广西壮族', 'invoicing' ),
837
-        'CN22' => __( 'Hainan / 海南', 'invoicing' ),
838
-        'CN23' => __( 'Chongqing / 重庆', 'invoicing' ),
839
-        'CN24' => __( 'Sichuan / 四川', 'invoicing' ),
840
-        'CN25' => __( 'Guizhou / 贵州', 'invoicing' ),
841
-        'CN26' => __( 'Shaanxi / 陕西', 'invoicing' ),
842
-        'CN27' => __( 'Gansu / 甘肃', 'invoicing' ),
843
-        'CN28' => __( 'Qinghai / 青海', 'invoicing' ),
844
-        'CN29' => __( 'Ningxia Hui / 宁夏', 'invoicing' ),
845
-        'CN30' => __( 'Macau / 澳门', 'invoicing' ),
846
-        'CN31' => __( 'Tibet / 西藏', 'invoicing' ),
847
-        'CN32' => __( 'Xinjiang / 新疆', 'invoicing' )
816
+        'CN1'  => __('Yunnan / 云南', 'invoicing'),
817
+        'CN2'  => __('Beijing / 北京', 'invoicing'),
818
+        'CN3'  => __('Tianjin / 天津', 'invoicing'),
819
+        'CN4'  => __('Hebei / 河北', 'invoicing'),
820
+        'CN5'  => __('Shanxi / 山西', 'invoicing'),
821
+        'CN6'  => __('Inner Mongolia / 內蒙古', 'invoicing'),
822
+        'CN7'  => __('Liaoning / 辽宁', 'invoicing'),
823
+        'CN8'  => __('Jilin / 吉林', 'invoicing'),
824
+        'CN9'  => __('Heilongjiang / 黑龙江', 'invoicing'),
825
+        'CN10' => __('Shanghai / 上海', 'invoicing'),
826
+        'CN11' => __('Jiangsu / 江苏', 'invoicing'),
827
+        'CN12' => __('Zhejiang / 浙江', 'invoicing'),
828
+        'CN13' => __('Anhui / 安徽', 'invoicing'),
829
+        'CN14' => __('Fujian / 福建', 'invoicing'),
830
+        'CN15' => __('Jiangxi / 江西', 'invoicing'),
831
+        'CN16' => __('Shandong / 山东', 'invoicing'),
832
+        'CN17' => __('Henan / 河南', 'invoicing'),
833
+        'CN18' => __('Hubei / 湖北', 'invoicing'),
834
+        'CN19' => __('Hunan / 湖南', 'invoicing'),
835
+        'CN20' => __('Guangdong / 广东', 'invoicing'),
836
+        'CN21' => __('Guangxi Zhuang / 广西壮族', 'invoicing'),
837
+        'CN22' => __('Hainan / 海南', 'invoicing'),
838
+        'CN23' => __('Chongqing / 重庆', 'invoicing'),
839
+        'CN24' => __('Sichuan / 四川', 'invoicing'),
840
+        'CN25' => __('Guizhou / 贵州', 'invoicing'),
841
+        'CN26' => __('Shaanxi / 陕西', 'invoicing'),
842
+        'CN27' => __('Gansu / 甘肃', 'invoicing'),
843
+        'CN28' => __('Qinghai / 青海', 'invoicing'),
844
+        'CN29' => __('Ningxia Hui / 宁夏', 'invoicing'),
845
+        'CN30' => __('Macau / 澳门', 'invoicing'),
846
+        'CN31' => __('Tibet / 西藏', 'invoicing'),
847
+        'CN32' => __('Xinjiang / 新疆', 'invoicing')
848 848
     );
849 849
 
850
-    return apply_filters( 'wpinv_china_states', $states );
850
+    return apply_filters('wpinv_china_states', $states);
851 851
 }
852 852
 
853 853
 function wpinv_get_new_zealand_states_list() {
854 854
     $states = array(
855
-        'AK' => __( 'Auckland', 'invoicing' ),
856
-        'BP' => __( 'Bay of Plenty', 'invoicing' ),
857
-        'CT' => __( 'Canterbury', 'invoicing' ),
858
-        'HB' => __( 'Hawke’s Bay', 'invoicing' ),
859
-        'MW' => __( 'Manawatu-Wanganui', 'invoicing' ),
860
-        'MB' => __( 'Marlborough', 'invoicing' ),
861
-        'NS' => __( 'Nelson', 'invoicing' ),
862
-        'NL' => __( 'Northland', 'invoicing' ),
863
-        'OT' => __( 'Otago', 'invoicing' ),
864
-        'SL' => __( 'Southland', 'invoicing' ),
865
-        'TK' => __( 'Taranaki', 'invoicing' ),
866
-        'TM' => __( 'Tasman', 'invoicing' ),
867
-        'WA' => __( 'Waikato', 'invoicing' ),
868
-        'WR' => __( 'Wairarapa', 'invoicing' ),
869
-        'WE' => __( 'Wellington', 'invoicing' ),
870
-        'WC' => __( 'West Coast', 'invoicing' )
855
+        'AK' => __('Auckland', 'invoicing'),
856
+        'BP' => __('Bay of Plenty', 'invoicing'),
857
+        'CT' => __('Canterbury', 'invoicing'),
858
+        'HB' => __('Hawke’s Bay', 'invoicing'),
859
+        'MW' => __('Manawatu-Wanganui', 'invoicing'),
860
+        'MB' => __('Marlborough', 'invoicing'),
861
+        'NS' => __('Nelson', 'invoicing'),
862
+        'NL' => __('Northland', 'invoicing'),
863
+        'OT' => __('Otago', 'invoicing'),
864
+        'SL' => __('Southland', 'invoicing'),
865
+        'TK' => __('Taranaki', 'invoicing'),
866
+        'TM' => __('Tasman', 'invoicing'),
867
+        'WA' => __('Waikato', 'invoicing'),
868
+        'WR' => __('Wairarapa', 'invoicing'),
869
+        'WE' => __('Wellington', 'invoicing'),
870
+        'WC' => __('West Coast', 'invoicing')
871 871
     );
872 872
 
873
-    return apply_filters( 'wpinv_new_zealand_states', $states );
873
+    return apply_filters('wpinv_new_zealand_states', $states);
874 874
 }
875 875
 
876 876
 function wpinv_get_peru_states_list() {
877 877
     $states = array(
878
-        'CAL' => __( 'El Callao', 'invoicing' ),
879
-        'LMA' => __( 'Municipalidad Metropolitana de Lima', 'invoicing' ),
880
-        'AMA' => __( 'Amazonas', 'invoicing' ),
881
-        'ANC' => __( 'Ancash', 'invoicing' ),
882
-        'APU' => __( 'Apurímac', 'invoicing' ),
883
-        'ARE' => __( 'Arequipa', 'invoicing' ),
884
-        'AYA' => __( 'Ayacucho', 'invoicing' ),
885
-        'CAJ' => __( 'Cajamarca', 'invoicing' ),
886
-        'CUS' => __( 'Cusco', 'invoicing' ),
887
-        'HUV' => __( 'Huancavelica', 'invoicing' ),
888
-        'HUC' => __( 'Huánuco', 'invoicing' ),
889
-        'ICA' => __( 'Ica', 'invoicing' ),
890
-        'JUN' => __( 'Junín', 'invoicing' ),
891
-        'LAL' => __( 'La Libertad', 'invoicing' ),
892
-        'LAM' => __( 'Lambayeque', 'invoicing' ),
893
-        'LIM' => __( 'Lima', 'invoicing' ),
894
-        'LOR' => __( 'Loreto', 'invoicing' ),
895
-        'MDD' => __( 'Madre de Dios', 'invoicing' ),
896
-        'MOQ' => __( 'Moquegua', 'invoicing' ),
897
-        'PAS' => __( 'Pasco', 'invoicing' ),
898
-        'PIU' => __( 'Piura', 'invoicing' ),
899
-        'PUN' => __( 'Puno', 'invoicing' ),
900
-        'SAM' => __( 'San Martín', 'invoicing' ),
901
-        'TAC' => __( 'Tacna', 'invoicing' ),
902
-        'TUM' => __( 'Tumbes', 'invoicing' ),
903
-        'UCA' => __( 'Ucayali', 'invoicing' )
878
+        'CAL' => __('El Callao', 'invoicing'),
879
+        'LMA' => __('Municipalidad Metropolitana de Lima', 'invoicing'),
880
+        'AMA' => __('Amazonas', 'invoicing'),
881
+        'ANC' => __('Ancash', 'invoicing'),
882
+        'APU' => __('Apurímac', 'invoicing'),
883
+        'ARE' => __('Arequipa', 'invoicing'),
884
+        'AYA' => __('Ayacucho', 'invoicing'),
885
+        'CAJ' => __('Cajamarca', 'invoicing'),
886
+        'CUS' => __('Cusco', 'invoicing'),
887
+        'HUV' => __('Huancavelica', 'invoicing'),
888
+        'HUC' => __('Huánuco', 'invoicing'),
889
+        'ICA' => __('Ica', 'invoicing'),
890
+        'JUN' => __('Junín', 'invoicing'),
891
+        'LAL' => __('La Libertad', 'invoicing'),
892
+        'LAM' => __('Lambayeque', 'invoicing'),
893
+        'LIM' => __('Lima', 'invoicing'),
894
+        'LOR' => __('Loreto', 'invoicing'),
895
+        'MDD' => __('Madre de Dios', 'invoicing'),
896
+        'MOQ' => __('Moquegua', 'invoicing'),
897
+        'PAS' => __('Pasco', 'invoicing'),
898
+        'PIU' => __('Piura', 'invoicing'),
899
+        'PUN' => __('Puno', 'invoicing'),
900
+        'SAM' => __('San Martín', 'invoicing'),
901
+        'TAC' => __('Tacna', 'invoicing'),
902
+        'TUM' => __('Tumbes', 'invoicing'),
903
+        'UCA' => __('Ucayali', 'invoicing')
904 904
     );
905 905
 
906
-    return apply_filters( 'wpinv_peru_states', $states );
906
+    return apply_filters('wpinv_peru_states', $states);
907 907
 }
908 908
 
909 909
 function wpinv_get_indonesia_states_list() {
910
-    $states  = array(
911
-        'AC' => __( 'Daerah Istimewa Aceh', 'invoicing' ),
912
-        'SU' => __( 'Sumatera Utara', 'invoicing' ),
913
-        'SB' => __( 'Sumatera Barat', 'invoicing' ),
914
-        'RI' => __( 'Riau', 'invoicing' ),
915
-        'KR' => __( 'Kepulauan Riau', 'invoicing' ),
916
-        'JA' => __( 'Jambi', 'invoicing' ),
917
-        'SS' => __( 'Sumatera Selatan', 'invoicing' ),
918
-        'BB' => __( 'Bangka Belitung', 'invoicing' ),
919
-        'BE' => __( 'Bengkulu', 'invoicing' ),
920
-        'LA' => __( 'Lampung', 'invoicing' ),
921
-        'JK' => __( 'DKI Jakarta', 'invoicing' ),
922
-        'JB' => __( 'Jawa Barat', 'invoicing' ),
923
-        'BT' => __( 'Banten', 'invoicing' ),
924
-        'JT' => __( 'Jawa Tengah', 'invoicing' ),
925
-        'JI' => __( 'Jawa Timur', 'invoicing' ),
926
-        'YO' => __( 'Daerah Istimewa Yogyakarta', 'invoicing' ),
927
-        'BA' => __( 'Bali', 'invoicing' ),
928
-        'NB' => __( 'Nusa Tenggara Barat', 'invoicing' ),
929
-        'NT' => __( 'Nusa Tenggara Timur', 'invoicing' ),
930
-        'KB' => __( 'Kalimantan Barat', 'invoicing' ),
931
-        'KT' => __( 'Kalimantan Tengah', 'invoicing' ),
932
-        'KI' => __( 'Kalimantan Timur', 'invoicing' ),
933
-        'KS' => __( 'Kalimantan Selatan', 'invoicing' ),
934
-        'KU' => __( 'Kalimantan Utara', 'invoicing' ),
935
-        'SA' => __( 'Sulawesi Utara', 'invoicing' ),
936
-        'ST' => __( 'Sulawesi Tengah', 'invoicing' ),
937
-        'SG' => __( 'Sulawesi Tenggara', 'invoicing' ),
938
-        'SR' => __( 'Sulawesi Barat', 'invoicing' ),
939
-        'SN' => __( 'Sulawesi Selatan', 'invoicing' ),
940
-        'GO' => __( 'Gorontalo', 'invoicing' ),
941
-        'MA' => __( 'Maluku', 'invoicing' ),
942
-        'MU' => __( 'Maluku Utara', 'invoicing' ),
943
-        'PA' => __( 'Papua', 'invoicing' ),
944
-        'PB' => __( 'Papua Barat', 'invoicing' )
910
+    $states = array(
911
+        'AC' => __('Daerah Istimewa Aceh', 'invoicing'),
912
+        'SU' => __('Sumatera Utara', 'invoicing'),
913
+        'SB' => __('Sumatera Barat', 'invoicing'),
914
+        'RI' => __('Riau', 'invoicing'),
915
+        'KR' => __('Kepulauan Riau', 'invoicing'),
916
+        'JA' => __('Jambi', 'invoicing'),
917
+        'SS' => __('Sumatera Selatan', 'invoicing'),
918
+        'BB' => __('Bangka Belitung', 'invoicing'),
919
+        'BE' => __('Bengkulu', 'invoicing'),
920
+        'LA' => __('Lampung', 'invoicing'),
921
+        'JK' => __('DKI Jakarta', 'invoicing'),
922
+        'JB' => __('Jawa Barat', 'invoicing'),
923
+        'BT' => __('Banten', 'invoicing'),
924
+        'JT' => __('Jawa Tengah', 'invoicing'),
925
+        'JI' => __('Jawa Timur', 'invoicing'),
926
+        'YO' => __('Daerah Istimewa Yogyakarta', 'invoicing'),
927
+        'BA' => __('Bali', 'invoicing'),
928
+        'NB' => __('Nusa Tenggara Barat', 'invoicing'),
929
+        'NT' => __('Nusa Tenggara Timur', 'invoicing'),
930
+        'KB' => __('Kalimantan Barat', 'invoicing'),
931
+        'KT' => __('Kalimantan Tengah', 'invoicing'),
932
+        'KI' => __('Kalimantan Timur', 'invoicing'),
933
+        'KS' => __('Kalimantan Selatan', 'invoicing'),
934
+        'KU' => __('Kalimantan Utara', 'invoicing'),
935
+        'SA' => __('Sulawesi Utara', 'invoicing'),
936
+        'ST' => __('Sulawesi Tengah', 'invoicing'),
937
+        'SG' => __('Sulawesi Tenggara', 'invoicing'),
938
+        'SR' => __('Sulawesi Barat', 'invoicing'),
939
+        'SN' => __('Sulawesi Selatan', 'invoicing'),
940
+        'GO' => __('Gorontalo', 'invoicing'),
941
+        'MA' => __('Maluku', 'invoicing'),
942
+        'MU' => __('Maluku Utara', 'invoicing'),
943
+        'PA' => __('Papua', 'invoicing'),
944
+        'PB' => __('Papua Barat', 'invoicing')
945 945
     );
946 946
 
947
-    return apply_filters( 'wpinv_indonesia_states', $states );
947
+    return apply_filters('wpinv_indonesia_states', $states);
948 948
 }
949 949
 
950 950
 function wpinv_get_india_states_list() {
951 951
     $states = array(
952
-        'AP' => __( 'Andhra Pradesh', 'invoicing' ),
953
-        'AR' => __( 'Arunachal Pradesh', 'invoicing' ),
954
-        'AS' => __( 'Assam', 'invoicing' ),
955
-        'BR' => __( 'Bihar', 'invoicing' ),
956
-        'CT' => __( 'Chhattisgarh', 'invoicing' ),
957
-        'GA' => __( 'Goa', 'invoicing' ),
958
-        'GJ' => __( 'Gujarat', 'invoicing' ),
959
-        'HR' => __( 'Haryana', 'invoicing' ),
960
-        'HP' => __( 'Himachal Pradesh', 'invoicing' ),
961
-        'JK' => __( 'Jammu and Kashmir', 'invoicing' ),
962
-        'JH' => __( 'Jharkhand', 'invoicing' ),
963
-        'KA' => __( 'Karnataka', 'invoicing' ),
964
-        'KL' => __( 'Kerala', 'invoicing' ),
965
-        'MP' => __( 'Madhya Pradesh', 'invoicing' ),
966
-        'MH' => __( 'Maharashtra', 'invoicing' ),
967
-        'MN' => __( 'Manipur', 'invoicing' ),
968
-        'ML' => __( 'Meghalaya', 'invoicing' ),
969
-        'MZ' => __( 'Mizoram', 'invoicing' ),
970
-        'NL' => __( 'Nagaland', 'invoicing' ),
971
-        'OR' => __( 'Orissa', 'invoicing' ),
972
-        'PB' => __( 'Punjab', 'invoicing' ),
973
-        'RJ' => __( 'Rajasthan', 'invoicing' ),
974
-        'SK' => __( 'Sikkim', 'invoicing' ),
975
-        'TN' => __( 'Tamil Nadu', 'invoicing' ),
976
-        'TG' => __( 'Telangana', 'invoicing' ),
977
-        'TR' => __( 'Tripura', 'invoicing' ),
978
-        'UT' => __( 'Uttarakhand', 'invoicing' ),
979
-        'UP' => __( 'Uttar Pradesh', 'invoicing' ),
980
-        'WB' => __( 'West Bengal', 'invoicing' ),
981
-        'AN' => __( 'Andaman and Nicobar Islands', 'invoicing' ),
982
-        'CH' => __( 'Chandigarh', 'invoicing' ),
983
-        'DN' => __( 'Dadar and Nagar Haveli', 'invoicing' ),
984
-        'DD' => __( 'Daman and Diu', 'invoicing' ),
985
-        'DL' => __( 'Delhi', 'invoicing' ),
986
-        'LD' => __( 'Lakshadweep', 'invoicing' ),
987
-        'PY' => __( 'Pondicherry (Puducherry)', 'invoicing' )
952
+        'AP' => __('Andhra Pradesh', 'invoicing'),
953
+        'AR' => __('Arunachal Pradesh', 'invoicing'),
954
+        'AS' => __('Assam', 'invoicing'),
955
+        'BR' => __('Bihar', 'invoicing'),
956
+        'CT' => __('Chhattisgarh', 'invoicing'),
957
+        'GA' => __('Goa', 'invoicing'),
958
+        'GJ' => __('Gujarat', 'invoicing'),
959
+        'HR' => __('Haryana', 'invoicing'),
960
+        'HP' => __('Himachal Pradesh', 'invoicing'),
961
+        'JK' => __('Jammu and Kashmir', 'invoicing'),
962
+        'JH' => __('Jharkhand', 'invoicing'),
963
+        'KA' => __('Karnataka', 'invoicing'),
964
+        'KL' => __('Kerala', 'invoicing'),
965
+        'MP' => __('Madhya Pradesh', 'invoicing'),
966
+        'MH' => __('Maharashtra', 'invoicing'),
967
+        'MN' => __('Manipur', 'invoicing'),
968
+        'ML' => __('Meghalaya', 'invoicing'),
969
+        'MZ' => __('Mizoram', 'invoicing'),
970
+        'NL' => __('Nagaland', 'invoicing'),
971
+        'OR' => __('Orissa', 'invoicing'),
972
+        'PB' => __('Punjab', 'invoicing'),
973
+        'RJ' => __('Rajasthan', 'invoicing'),
974
+        'SK' => __('Sikkim', 'invoicing'),
975
+        'TN' => __('Tamil Nadu', 'invoicing'),
976
+        'TG' => __('Telangana', 'invoicing'),
977
+        'TR' => __('Tripura', 'invoicing'),
978
+        'UT' => __('Uttarakhand', 'invoicing'),
979
+        'UP' => __('Uttar Pradesh', 'invoicing'),
980
+        'WB' => __('West Bengal', 'invoicing'),
981
+        'AN' => __('Andaman and Nicobar Islands', 'invoicing'),
982
+        'CH' => __('Chandigarh', 'invoicing'),
983
+        'DN' => __('Dadar and Nagar Haveli', 'invoicing'),
984
+        'DD' => __('Daman and Diu', 'invoicing'),
985
+        'DL' => __('Delhi', 'invoicing'),
986
+        'LD' => __('Lakshadweep', 'invoicing'),
987
+        'PY' => __('Pondicherry (Puducherry)', 'invoicing')
988 988
     );
989 989
 
990
-    return apply_filters( 'wpinv_india_states', $states );
990
+    return apply_filters('wpinv_india_states', $states);
991 991
 }
992 992
 
993 993
 function wpinv_get_iran_states_list() {
994 994
     $states = array(
995
-        'KHZ' => __( 'Khuzestan', 'invoicing' ),
996
-        'THR' => __( 'Tehran', 'invoicing' ),
997
-        'ILM' => __( 'Ilaam', 'invoicing' ),
998
-        'BHR' => __( 'Bushehr', 'invoicing' ),
999
-        'ADL' => __( 'Ardabil', 'invoicing' ),
1000
-        'ESF' => __( 'Isfahan', 'invoicing' ),
1001
-        'YZD' => __( 'Yazd', 'invoicing' ),
1002
-        'KRH' => __( 'Kermanshah', 'invoicing' ),
1003
-        'KRN' => __( 'Kerman', 'invoicing' ),
1004
-        'HDN' => __( 'Hamadan', 'invoicing' ),
1005
-        'GZN' => __( 'Ghazvin', 'invoicing' ),
1006
-        'ZJN' => __( 'Zanjan', 'invoicing' ),
1007
-        'LRS' => __( 'Luristan', 'invoicing' ),
1008
-        'ABZ' => __( 'Alborz', 'invoicing' ),
1009
-        'EAZ' => __( 'East Azerbaijan', 'invoicing' ),
1010
-        'WAZ' => __( 'West Azerbaijan', 'invoicing' ),
1011
-        'CHB' => __( 'Chaharmahal and Bakhtiari', 'invoicing' ),
1012
-        'SKH' => __( 'South Khorasan', 'invoicing' ),
1013
-        'RKH' => __( 'Razavi Khorasan', 'invoicing' ),
1014
-        'NKH' => __( 'North Khorasan', 'invoicing' ),
1015
-        'SMN' => __( 'Semnan', 'invoicing' ),
1016
-        'FRS' => __( 'Fars', 'invoicing' ),
1017
-        'QHM' => __( 'Qom', 'invoicing' ),
1018
-        'KRD' => __( 'Kurdistan', 'invoicing' ),
1019
-        'KBD' => __( 'Kohgiluyeh and BoyerAhmad', 'invoicing' ),
1020
-        'GLS' => __( 'Golestan', 'invoicing' ),
1021
-        'GIL' => __( 'Gilan', 'invoicing' ),
1022
-        'MZN' => __( 'Mazandaran', 'invoicing' ),
1023
-        'MKZ' => __( 'Markazi', 'invoicing' ),
1024
-        'HRZ' => __( 'Hormozgan', 'invoicing' ),
1025
-        'SBN' => __( 'Sistan and Baluchestan', 'invoicing' )
995
+        'KHZ' => __('Khuzestan', 'invoicing'),
996
+        'THR' => __('Tehran', 'invoicing'),
997
+        'ILM' => __('Ilaam', 'invoicing'),
998
+        'BHR' => __('Bushehr', 'invoicing'),
999
+        'ADL' => __('Ardabil', 'invoicing'),
1000
+        'ESF' => __('Isfahan', 'invoicing'),
1001
+        'YZD' => __('Yazd', 'invoicing'),
1002
+        'KRH' => __('Kermanshah', 'invoicing'),
1003
+        'KRN' => __('Kerman', 'invoicing'),
1004
+        'HDN' => __('Hamadan', 'invoicing'),
1005
+        'GZN' => __('Ghazvin', 'invoicing'),
1006
+        'ZJN' => __('Zanjan', 'invoicing'),
1007
+        'LRS' => __('Luristan', 'invoicing'),
1008
+        'ABZ' => __('Alborz', 'invoicing'),
1009
+        'EAZ' => __('East Azerbaijan', 'invoicing'),
1010
+        'WAZ' => __('West Azerbaijan', 'invoicing'),
1011
+        'CHB' => __('Chaharmahal and Bakhtiari', 'invoicing'),
1012
+        'SKH' => __('South Khorasan', 'invoicing'),
1013
+        'RKH' => __('Razavi Khorasan', 'invoicing'),
1014
+        'NKH' => __('North Khorasan', 'invoicing'),
1015
+        'SMN' => __('Semnan', 'invoicing'),
1016
+        'FRS' => __('Fars', 'invoicing'),
1017
+        'QHM' => __('Qom', 'invoicing'),
1018
+        'KRD' => __('Kurdistan', 'invoicing'),
1019
+        'KBD' => __('Kohgiluyeh and BoyerAhmad', 'invoicing'),
1020
+        'GLS' => __('Golestan', 'invoicing'),
1021
+        'GIL' => __('Gilan', 'invoicing'),
1022
+        'MZN' => __('Mazandaran', 'invoicing'),
1023
+        'MKZ' => __('Markazi', 'invoicing'),
1024
+        'HRZ' => __('Hormozgan', 'invoicing'),
1025
+        'SBN' => __('Sistan and Baluchestan', 'invoicing')
1026 1026
     );
1027 1027
 
1028
-    return apply_filters( 'wpinv_iran_states', $states );
1028
+    return apply_filters('wpinv_iran_states', $states);
1029 1029
 }
1030 1030
 
1031 1031
 function wpinv_get_italy_states_list() {
1032 1032
     $states = array(
1033
-        'AG' => __( 'Agrigento', 'invoicing' ),
1034
-        'AL' => __( 'Alessandria', 'invoicing' ),
1035
-        'AN' => __( 'Ancona', 'invoicing' ),
1036
-        'AO' => __( 'Aosta', 'invoicing' ),
1037
-        'AR' => __( 'Arezzo', 'invoicing' ),
1038
-        'AP' => __( 'Ascoli Piceno', 'invoicing' ),
1039
-        'AT' => __( 'Asti', 'invoicing' ),
1040
-        'AV' => __( 'Avellino', 'invoicing' ),
1041
-        'BA' => __( 'Bari', 'invoicing' ),
1042
-        'BT' => __( 'Barletta-Andria-Trani', 'invoicing' ),
1043
-        'BL' => __( 'Belluno', 'invoicing' ),
1044
-        'BN' => __( 'Benevento', 'invoicing' ),
1045
-        'BG' => __( 'Bergamo', 'invoicing' ),
1046
-        'BI' => __( 'Biella', 'invoicing' ),
1047
-        'BO' => __( 'Bologna', 'invoicing' ),
1048
-        'BZ' => __( 'Bolzano', 'invoicing' ),
1049
-        'BS' => __( 'Brescia', 'invoicing' ),
1050
-        'BR' => __( 'Brindisi', 'invoicing' ),
1051
-        'CA' => __( 'Cagliari', 'invoicing' ),
1052
-        'CL' => __( 'Caltanissetta', 'invoicing' ),
1053
-        'CB' => __( 'Campobasso', 'invoicing' ),
1054
-        'CI' => __( 'Caltanissetta', 'invoicing' ),
1055
-        'CE' => __( 'Caserta', 'invoicing' ),
1056
-        'CT' => __( 'Catania', 'invoicing' ),
1057
-        'CZ' => __( 'Catanzaro', 'invoicing' ),
1058
-        'CH' => __( 'Chieti', 'invoicing' ),
1059
-        'CO' => __( 'Como', 'invoicing' ),
1060
-        'CS' => __( 'Cosenza', 'invoicing' ),
1061
-        'CR' => __( 'Cremona', 'invoicing' ),
1062
-        'KR' => __( 'Crotone', 'invoicing' ),
1063
-        'CN' => __( 'Cuneo', 'invoicing' ),
1064
-        'EN' => __( 'Enna', 'invoicing' ),
1065
-        'FM' => __( 'Fermo', 'invoicing' ),
1066
-        'FE' => __( 'Ferrara', 'invoicing' ),
1067
-        'FI' => __( 'Firenze', 'invoicing' ),
1068
-        'FG' => __( 'Foggia', 'invoicing' ),
1069
-        'FC' => __( 'Forli-Cesena', 'invoicing' ),
1070
-        'FR' => __( 'Frosinone', 'invoicing' ),
1071
-        'GE' => __( 'Genova', 'invoicing' ),
1072
-        'GO' => __( 'Gorizia', 'invoicing' ),
1073
-        'GR' => __( 'Grosseto', 'invoicing' ),
1074
-        'IM' => __( 'Imperia', 'invoicing' ),
1075
-        'IS' => __( 'Isernia', 'invoicing' ),
1076
-        'SP' => __( 'La Spezia', 'invoicing' ),
1077
-        'AQ' => __( 'L'Aquila', 'invoicing' ),
1078
-        'LT' => __( 'Latina', 'invoicing' ),
1079
-        'LE' => __( 'Lecce', 'invoicing' ),
1080
-        'LC' => __( 'Lecco', 'invoicing' ),
1081
-        'LI' => __( 'Livorno', 'invoicing' ),
1082
-        'LO' => __( 'Lodi', 'invoicing' ),
1083
-        'LU' => __( 'Lucca', 'invoicing' ),
1084
-        'MC' => __( 'Macerata', 'invoicing' ),
1085
-        'MN' => __( 'Mantova', 'invoicing' ),
1086
-        'MS' => __( 'Massa-Carrara', 'invoicing' ),
1087
-        'MT' => __( 'Matera', 'invoicing' ),
1088
-        'ME' => __( 'Messina', 'invoicing' ),
1089
-        'MI' => __( 'Milano', 'invoicing' ),
1090
-        'MO' => __( 'Modena', 'invoicing' ),
1091
-        'MB' => __( 'Monza e della Brianza', 'invoicing' ),
1092
-        'NA' => __( 'Napoli', 'invoicing' ),
1093
-        'NO' => __( 'Novara', 'invoicing' ),
1094
-        'NU' => __( 'Nuoro', 'invoicing' ),
1095
-        'OT' => __( 'Olbia-Tempio', 'invoicing' ),
1096
-        'OR' => __( 'Oristano', 'invoicing' ),
1097
-        'PD' => __( 'Padova', 'invoicing' ),
1098
-        'PA' => __( 'Palermo', 'invoicing' ),
1099
-        'PR' => __( 'Parma', 'invoicing' ),
1100
-        'PV' => __( 'Pavia', 'invoicing' ),
1101
-        'PG' => __( 'Perugia', 'invoicing' ),
1102
-        'PU' => __( 'Pesaro e Urbino', 'invoicing' ),
1103
-        'PE' => __( 'Pescara', 'invoicing' ),
1104
-        'PC' => __( 'Piacenza', 'invoicing' ),
1105
-        'PI' => __( 'Pisa', 'invoicing' ),
1106
-        'PT' => __( 'Pistoia', 'invoicing' ),
1107
-        'PN' => __( 'Pordenone', 'invoicing' ),
1108
-        'PZ' => __( 'Potenza', 'invoicing' ),
1109
-        'PO' => __( 'Prato', 'invoicing' ),
1110
-        'RG' => __( 'Ragusa', 'invoicing' ),
1111
-        'RA' => __( 'Ravenna', 'invoicing' ),
1112
-        'RC' => __( 'Reggio Calabria', 'invoicing' ),
1113
-        'RE' => __( 'Reggio Emilia', 'invoicing' ),
1114
-        'RI' => __( 'Rieti', 'invoicing' ),
1115
-        'RN' => __( 'Rimini', 'invoicing' ),
1116
-        'RM' => __( 'Roma', 'invoicing' ),
1117
-        'RO' => __( 'Rovigo', 'invoicing' ),
1118
-        'SA' => __( 'Salerno', 'invoicing' ),
1119
-        'VS' => __( 'Medio Campidano', 'invoicing' ),
1120
-        'SS' => __( 'Sassari', 'invoicing' ),
1121
-        'SV' => __( 'Savona', 'invoicing' ),
1122
-        'SI' => __( 'Siena', 'invoicing' ),
1123
-        'SR' => __( 'Siracusa', 'invoicing' ),
1124
-        'SO' => __( 'Sondrio', 'invoicing' ),
1125
-        'TA' => __( 'Taranto', 'invoicing' ),
1126
-        'TE' => __( 'Teramo', 'invoicing' ),
1127
-        'TR' => __( 'Terni', 'invoicing' ),
1128
-        'TO' => __( 'Torino', 'invoicing' ),
1129
-        'OG' => __( 'Ogliastra', 'invoicing' ),
1130
-        'TP' => __( 'Trapani', 'invoicing' ),
1131
-        'TN' => __( 'Trento', 'invoicing' ),
1132
-        'TV' => __( 'Treviso', 'invoicing' ),
1133
-        'TS' => __( 'Trieste', 'invoicing' ),
1134
-        'UD' => __( 'Udine', 'invoicing' ),
1135
-        'VA' => __( 'Varesa', 'invoicing' ),
1136
-        'VE' => __( 'Venezia', 'invoicing' ),
1137
-        'VB' => __( 'Verbano-Cusio-Ossola', 'invoicing' ),
1138
-        'VC' => __( 'Vercelli', 'invoicing' ),
1139
-        'VR' => __( 'Verona', 'invoicing' ),
1140
-        'VV' => __( 'Vibo Valentia', 'invoicing' ),
1141
-        'VI' => __( 'Vicenza', 'invoicing' ),
1142
-        'VT' => __( 'Viterbo', 'invoicing' )
1033
+        'AG' => __('Agrigento', 'invoicing'),
1034
+        'AL' => __('Alessandria', 'invoicing'),
1035
+        'AN' => __('Ancona', 'invoicing'),
1036
+        'AO' => __('Aosta', 'invoicing'),
1037
+        'AR' => __('Arezzo', 'invoicing'),
1038
+        'AP' => __('Ascoli Piceno', 'invoicing'),
1039
+        'AT' => __('Asti', 'invoicing'),
1040
+        'AV' => __('Avellino', 'invoicing'),
1041
+        'BA' => __('Bari', 'invoicing'),
1042
+        'BT' => __('Barletta-Andria-Trani', 'invoicing'),
1043
+        'BL' => __('Belluno', 'invoicing'),
1044
+        'BN' => __('Benevento', 'invoicing'),
1045
+        'BG' => __('Bergamo', 'invoicing'),
1046
+        'BI' => __('Biella', 'invoicing'),
1047
+        'BO' => __('Bologna', 'invoicing'),
1048
+        'BZ' => __('Bolzano', 'invoicing'),
1049
+        'BS' => __('Brescia', 'invoicing'),
1050
+        'BR' => __('Brindisi', 'invoicing'),
1051
+        'CA' => __('Cagliari', 'invoicing'),
1052
+        'CL' => __('Caltanissetta', 'invoicing'),
1053
+        'CB' => __('Campobasso', 'invoicing'),
1054
+        'CI' => __('Caltanissetta', 'invoicing'),
1055
+        'CE' => __('Caserta', 'invoicing'),
1056
+        'CT' => __('Catania', 'invoicing'),
1057
+        'CZ' => __('Catanzaro', 'invoicing'),
1058
+        'CH' => __('Chieti', 'invoicing'),
1059
+        'CO' => __('Como', 'invoicing'),
1060
+        'CS' => __('Cosenza', 'invoicing'),
1061
+        'CR' => __('Cremona', 'invoicing'),
1062
+        'KR' => __('Crotone', 'invoicing'),
1063
+        'CN' => __('Cuneo', 'invoicing'),
1064
+        'EN' => __('Enna', 'invoicing'),
1065
+        'FM' => __('Fermo', 'invoicing'),
1066
+        'FE' => __('Ferrara', 'invoicing'),
1067
+        'FI' => __('Firenze', 'invoicing'),
1068
+        'FG' => __('Foggia', 'invoicing'),
1069
+        'FC' => __('Forli-Cesena', 'invoicing'),
1070
+        'FR' => __('Frosinone', 'invoicing'),
1071
+        'GE' => __('Genova', 'invoicing'),
1072
+        'GO' => __('Gorizia', 'invoicing'),
1073
+        'GR' => __('Grosseto', 'invoicing'),
1074
+        'IM' => __('Imperia', 'invoicing'),
1075
+        'IS' => __('Isernia', 'invoicing'),
1076
+        'SP' => __('La Spezia', 'invoicing'),
1077
+        'AQ' => __('L'Aquila', 'invoicing'),
1078
+        'LT' => __('Latina', 'invoicing'),
1079
+        'LE' => __('Lecce', 'invoicing'),
1080
+        'LC' => __('Lecco', 'invoicing'),
1081
+        'LI' => __('Livorno', 'invoicing'),
1082
+        'LO' => __('Lodi', 'invoicing'),
1083
+        'LU' => __('Lucca', 'invoicing'),
1084
+        'MC' => __('Macerata', 'invoicing'),
1085
+        'MN' => __('Mantova', 'invoicing'),
1086
+        'MS' => __('Massa-Carrara', 'invoicing'),
1087
+        'MT' => __('Matera', 'invoicing'),
1088
+        'ME' => __('Messina', 'invoicing'),
1089
+        'MI' => __('Milano', 'invoicing'),
1090
+        'MO' => __('Modena', 'invoicing'),
1091
+        'MB' => __('Monza e della Brianza', 'invoicing'),
1092
+        'NA' => __('Napoli', 'invoicing'),
1093
+        'NO' => __('Novara', 'invoicing'),
1094
+        'NU' => __('Nuoro', 'invoicing'),
1095
+        'OT' => __('Olbia-Tempio', 'invoicing'),
1096
+        'OR' => __('Oristano', 'invoicing'),
1097
+        'PD' => __('Padova', 'invoicing'),
1098
+        'PA' => __('Palermo', 'invoicing'),
1099
+        'PR' => __('Parma', 'invoicing'),
1100
+        'PV' => __('Pavia', 'invoicing'),
1101
+        'PG' => __('Perugia', 'invoicing'),
1102
+        'PU' => __('Pesaro e Urbino', 'invoicing'),
1103
+        'PE' => __('Pescara', 'invoicing'),
1104
+        'PC' => __('Piacenza', 'invoicing'),
1105
+        'PI' => __('Pisa', 'invoicing'),
1106
+        'PT' => __('Pistoia', 'invoicing'),
1107
+        'PN' => __('Pordenone', 'invoicing'),
1108
+        'PZ' => __('Potenza', 'invoicing'),
1109
+        'PO' => __('Prato', 'invoicing'),
1110
+        'RG' => __('Ragusa', 'invoicing'),
1111
+        'RA' => __('Ravenna', 'invoicing'),
1112
+        'RC' => __('Reggio Calabria', 'invoicing'),
1113
+        'RE' => __('Reggio Emilia', 'invoicing'),
1114
+        'RI' => __('Rieti', 'invoicing'),
1115
+        'RN' => __('Rimini', 'invoicing'),
1116
+        'RM' => __('Roma', 'invoicing'),
1117
+        'RO' => __('Rovigo', 'invoicing'),
1118
+        'SA' => __('Salerno', 'invoicing'),
1119
+        'VS' => __('Medio Campidano', 'invoicing'),
1120
+        'SS' => __('Sassari', 'invoicing'),
1121
+        'SV' => __('Savona', 'invoicing'),
1122
+        'SI' => __('Siena', 'invoicing'),
1123
+        'SR' => __('Siracusa', 'invoicing'),
1124
+        'SO' => __('Sondrio', 'invoicing'),
1125
+        'TA' => __('Taranto', 'invoicing'),
1126
+        'TE' => __('Teramo', 'invoicing'),
1127
+        'TR' => __('Terni', 'invoicing'),
1128
+        'TO' => __('Torino', 'invoicing'),
1129
+        'OG' => __('Ogliastra', 'invoicing'),
1130
+        'TP' => __('Trapani', 'invoicing'),
1131
+        'TN' => __('Trento', 'invoicing'),
1132
+        'TV' => __('Treviso', 'invoicing'),
1133
+        'TS' => __('Trieste', 'invoicing'),
1134
+        'UD' => __('Udine', 'invoicing'),
1135
+        'VA' => __('Varesa', 'invoicing'),
1136
+        'VE' => __('Venezia', 'invoicing'),
1137
+        'VB' => __('Verbano-Cusio-Ossola', 'invoicing'),
1138
+        'VC' => __('Vercelli', 'invoicing'),
1139
+        'VR' => __('Verona', 'invoicing'),
1140
+        'VV' => __('Vibo Valentia', 'invoicing'),
1141
+        'VI' => __('Vicenza', 'invoicing'),
1142
+        'VT' => __('Viterbo', 'invoicing')
1143 1143
     );
1144 1144
 
1145
-    return apply_filters( 'wpinv_italy_states', $states );
1145
+    return apply_filters('wpinv_italy_states', $states);
1146 1146
 }
1147 1147
 
1148 1148
 function wpinv_get_malaysia_states_list() {
1149 1149
     $states = array(
1150
-        'JHR' => __( 'Johor', 'invoicing' ),
1151
-        'KDH' => __( 'Kedah', 'invoicing' ),
1152
-        'KTN' => __( 'Kelantan', 'invoicing' ),
1153
-        'MLK' => __( 'Melaka', 'invoicing' ),
1154
-        'NSN' => __( 'Negeri Sembilan', 'invoicing' ),
1155
-        'PHG' => __( 'Pahang', 'invoicing' ),
1156
-        'PRK' => __( 'Perak', 'invoicing' ),
1157
-        'PLS' => __( 'Perlis', 'invoicing' ),
1158
-        'PNG' => __( 'Pulau Pinang', 'invoicing' ),
1159
-        'SBH' => __( 'Sabah', 'invoicing' ),
1160
-        'SWK' => __( 'Sarawak', 'invoicing' ),
1161
-        'SGR' => __( 'Selangor', 'invoicing' ),
1162
-        'TRG' => __( 'Terengganu', 'invoicing' ),
1163
-        'KUL' => __( 'W.P. Kuala Lumpur', 'invoicing' ),
1164
-        'LBN' => __( 'W.P. Labuan', 'invoicing' ),
1165
-        'PJY' => __( 'W.P. Putrajaya', 'invoicing' )
1150
+        'JHR' => __('Johor', 'invoicing'),
1151
+        'KDH' => __('Kedah', 'invoicing'),
1152
+        'KTN' => __('Kelantan', 'invoicing'),
1153
+        'MLK' => __('Melaka', 'invoicing'),
1154
+        'NSN' => __('Negeri Sembilan', 'invoicing'),
1155
+        'PHG' => __('Pahang', 'invoicing'),
1156
+        'PRK' => __('Perak', 'invoicing'),
1157
+        'PLS' => __('Perlis', 'invoicing'),
1158
+        'PNG' => __('Pulau Pinang', 'invoicing'),
1159
+        'SBH' => __('Sabah', 'invoicing'),
1160
+        'SWK' => __('Sarawak', 'invoicing'),
1161
+        'SGR' => __('Selangor', 'invoicing'),
1162
+        'TRG' => __('Terengganu', 'invoicing'),
1163
+        'KUL' => __('W.P. Kuala Lumpur', 'invoicing'),
1164
+        'LBN' => __('W.P. Labuan', 'invoicing'),
1165
+        'PJY' => __('W.P. Putrajaya', 'invoicing')
1166 1166
     );
1167 1167
 
1168
-    return apply_filters( 'wpinv_malaysia_states', $states );
1168
+    return apply_filters('wpinv_malaysia_states', $states);
1169 1169
 }
1170 1170
 
1171 1171
 function wpinv_get_mexico_states_list() {
1172 1172
     $states = array(
1173
-        'DIF' => __( 'Distrito Federal', 'invoicing' ),
1174
-        'JAL' => __( 'Jalisco', 'invoicing' ),
1175
-        'NLE' => __( 'Nuevo León', 'invoicing' ),
1176
-        'AGU' => __( 'Aguascalientes', 'invoicing' ),
1177
-        'BCN' => __( 'Baja California Norte', 'invoicing' ),
1178
-        'BCS' => __( 'Baja California Sur', 'invoicing' ),
1179
-        'CAM' => __( 'Campeche', 'invoicing' ),
1180
-        'CHP' => __( 'Chiapas', 'invoicing' ),
1181
-        'CHH' => __( 'Chihuahua', 'invoicing' ),
1182
-        'COA' => __( 'Coahuila', 'invoicing' ),
1183
-        'COL' => __( 'Colima', 'invoicing' ),
1184
-        'DUR' => __( 'Durango', 'invoicing' ),
1185
-        'GUA' => __( 'Guanajuato', 'invoicing' ),
1186
-        'GRO' => __( 'Guerrero', 'invoicing' ),
1187
-        'HID' => __( 'Hidalgo', 'invoicing' ),
1188
-        'MEX' => __( 'Edo. de México', 'invoicing' ),
1189
-        'MIC' => __( 'Michoacán', 'invoicing' ),
1190
-        'MOR' => __( 'Morelos', 'invoicing' ),
1191
-        'NAY' => __( 'Nayarit', 'invoicing' ),
1192
-        'OAX' => __( 'Oaxaca', 'invoicing' ),
1193
-        'PUE' => __( 'Puebla', 'invoicing' ),
1194
-        'QUE' => __( 'Querétaro', 'invoicing' ),
1195
-        'ROO' => __( 'Quintana Roo', 'invoicing' ),
1196
-        'SLP' => __( 'San Luis Potosí', 'invoicing' ),
1197
-        'SIN' => __( 'Sinaloa', 'invoicing' ),
1198
-        'SON' => __( 'Sonora', 'invoicing' ),
1199
-        'TAB' => __( 'Tabasco', 'invoicing' ),
1200
-        'TAM' => __( 'Tamaulipas', 'invoicing' ),
1201
-        'TLA' => __( 'Tlaxcala', 'invoicing' ),
1202
-        'VER' => __( 'Veracruz', 'invoicing' ),
1203
-        'YUC' => __( 'Yucatán', 'invoicing' ),
1204
-        'ZAC' => __( 'Zacatecas', 'invoicing' )
1173
+        'DIF' => __('Distrito Federal', 'invoicing'),
1174
+        'JAL' => __('Jalisco', 'invoicing'),
1175
+        'NLE' => __('Nuevo León', 'invoicing'),
1176
+        'AGU' => __('Aguascalientes', 'invoicing'),
1177
+        'BCN' => __('Baja California Norte', 'invoicing'),
1178
+        'BCS' => __('Baja California Sur', 'invoicing'),
1179
+        'CAM' => __('Campeche', 'invoicing'),
1180
+        'CHP' => __('Chiapas', 'invoicing'),
1181
+        'CHH' => __('Chihuahua', 'invoicing'),
1182
+        'COA' => __('Coahuila', 'invoicing'),
1183
+        'COL' => __('Colima', 'invoicing'),
1184
+        'DUR' => __('Durango', 'invoicing'),
1185
+        'GUA' => __('Guanajuato', 'invoicing'),
1186
+        'GRO' => __('Guerrero', 'invoicing'),
1187
+        'HID' => __('Hidalgo', 'invoicing'),
1188
+        'MEX' => __('Edo. de México', 'invoicing'),
1189
+        'MIC' => __('Michoacán', 'invoicing'),
1190
+        'MOR' => __('Morelos', 'invoicing'),
1191
+        'NAY' => __('Nayarit', 'invoicing'),
1192
+        'OAX' => __('Oaxaca', 'invoicing'),
1193
+        'PUE' => __('Puebla', 'invoicing'),
1194
+        'QUE' => __('Querétaro', 'invoicing'),
1195
+        'ROO' => __('Quintana Roo', 'invoicing'),
1196
+        'SLP' => __('San Luis Potosí', 'invoicing'),
1197
+        'SIN' => __('Sinaloa', 'invoicing'),
1198
+        'SON' => __('Sonora', 'invoicing'),
1199
+        'TAB' => __('Tabasco', 'invoicing'),
1200
+        'TAM' => __('Tamaulipas', 'invoicing'),
1201
+        'TLA' => __('Tlaxcala', 'invoicing'),
1202
+        'VER' => __('Veracruz', 'invoicing'),
1203
+        'YUC' => __('Yucatán', 'invoicing'),
1204
+        'ZAC' => __('Zacatecas', 'invoicing')
1205 1205
     );
1206 1206
 
1207
-    return apply_filters( 'wpinv_mexico_states', $states );
1207
+    return apply_filters('wpinv_mexico_states', $states);
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_get_nepal_states_list() {
1211 1211
     $states = array(
1212
-        'ILL' => __( 'Illam', 'invoicing' ),
1213
-        'JHA' => __( 'Jhapa', 'invoicing' ),
1214
-        'PAN' => __( 'Panchthar', 'invoicing' ),
1215
-        'TAP' => __( 'Taplejung', 'invoicing' ),
1216
-        'BHO' => __( 'Bhojpur', 'invoicing' ),
1217
-        'DKA' => __( 'Dhankuta', 'invoicing' ),
1218
-        'MOR' => __( 'Morang', 'invoicing' ),
1219
-        'SUN' => __( 'Sunsari', 'invoicing' ),
1220
-        'SAN' => __( 'Sankhuwa', 'invoicing' ),
1221
-        'TER' => __( 'Terhathum', 'invoicing' ),
1222
-        'KHO' => __( 'Khotang', 'invoicing' ),
1223
-        'OKH' => __( 'Okhaldhunga', 'invoicing' ),
1224
-        'SAP' => __( 'Saptari', 'invoicing' ),
1225
-        'SIR' => __( 'Siraha', 'invoicing' ),
1226
-        'SOL' => __( 'Solukhumbu', 'invoicing' ),
1227
-        'UDA' => __( 'Udayapur', 'invoicing' ),
1228
-        'DHA' => __( 'Dhanusa', 'invoicing' ),
1229
-        'DLK' => __( 'Dolakha', 'invoicing' ),
1230
-        'MOH' => __( 'Mohottari', 'invoicing' ),
1231
-        'RAM' => __( 'Ramechha', 'invoicing' ),
1232
-        'SAR' => __( 'Sarlahi', 'invoicing' ),
1233
-        'SIN' => __( 'Sindhuli', 'invoicing' ),
1234
-        'BHA' => __( 'Bhaktapur', 'invoicing' ),
1235
-        'DHD' => __( 'Dhading', 'invoicing' ),
1236
-        'KTM' => __( 'Kathmandu', 'invoicing' ),
1237
-        'KAV' => __( 'Kavrepalanchowk', 'invoicing' ),
1238
-        'LAL' => __( 'Lalitpur', 'invoicing' ),
1239
-        'NUW' => __( 'Nuwakot', 'invoicing' ),
1240
-        'RAS' => __( 'Rasuwa', 'invoicing' ),
1241
-        'SPC' => __( 'Sindhupalchowk', 'invoicing' ),
1242
-        'BAR' => __( 'Bara', 'invoicing' ),
1243
-        'CHI' => __( 'Chitwan', 'invoicing' ),
1244
-        'MAK' => __( 'Makwanpur', 'invoicing' ),
1245
-        'PAR' => __( 'Parsa', 'invoicing' ),
1246
-        'RAU' => __( 'Rautahat', 'invoicing' ),
1247
-        'GOR' => __( 'Gorkha', 'invoicing' ),
1248
-        'KAS' => __( 'Kaski', 'invoicing' ),
1249
-        'LAM' => __( 'Lamjung', 'invoicing' ),
1250
-        'MAN' => __( 'Manang', 'invoicing' ),
1251
-        'SYN' => __( 'Syangja', 'invoicing' ),
1252
-        'TAN' => __( 'Tanahun', 'invoicing' ),
1253
-        'BAG' => __( 'Baglung', 'invoicing' ),
1254
-        'PBT' => __( 'Parbat', 'invoicing' ),
1255
-        'MUS' => __( 'Mustang', 'invoicing' ),
1256
-        'MYG' => __( 'Myagdi', 'invoicing' ),
1257
-        'AGR' => __( 'Agrghakanchi', 'invoicing' ),
1258
-        'GUL' => __( 'Gulmi', 'invoicing' ),
1259
-        'KAP' => __( 'Kapilbastu', 'invoicing' ),
1260
-        'NAW' => __( 'Nawalparasi', 'invoicing' ),
1261
-        'PAL' => __( 'Palpa', 'invoicing' ),
1262
-        'RUP' => __( 'Rupandehi', 'invoicing' ),
1263
-        'DAN' => __( 'Dang', 'invoicing' ),
1264
-        'PYU' => __( 'Pyuthan', 'invoicing' ),
1265
-        'ROL' => __( 'Rolpa', 'invoicing' ),
1266
-        'RUK' => __( 'Rukum', 'invoicing' ),
1267
-        'SAL' => __( 'Salyan', 'invoicing' ),
1268
-        'BAN' => __( 'Banke', 'invoicing' ),
1269
-        'BDA' => __( 'Bardiya', 'invoicing' ),
1270
-        'DAI' => __( 'Dailekh', 'invoicing' ),
1271
-        'JAJ' => __( 'Jajarkot', 'invoicing' ),
1272
-        'SUR' => __( 'Surkhet', 'invoicing' ),
1273
-        'DOL' => __( 'Dolpa', 'invoicing' ),
1274
-        'HUM' => __( 'Humla', 'invoicing' ),
1275
-        'JUM' => __( 'Jumla', 'invoicing' ),
1276
-        'KAL' => __( 'Kalikot', 'invoicing' ),
1277
-        'MUG' => __( 'Mugu', 'invoicing' ),
1278
-        'ACH' => __( 'Achham', 'invoicing' ),
1279
-        'BJH' => __( 'Bajhang', 'invoicing' ),
1280
-        'BJU' => __( 'Bajura', 'invoicing' ),
1281
-        'DOT' => __( 'Doti', 'invoicing' ),
1282
-        'KAI' => __( 'Kailali', 'invoicing' ),
1283
-        'BAI' => __( 'Baitadi', 'invoicing' ),
1284
-        'DAD' => __( 'Dadeldhura', 'invoicing' ),
1285
-        'DAR' => __( 'Darchula', 'invoicing' ),
1286
-        'KAN' => __( 'Kanchanpur', 'invoicing' )
1212
+        'ILL' => __('Illam', 'invoicing'),
1213
+        'JHA' => __('Jhapa', 'invoicing'),
1214
+        'PAN' => __('Panchthar', 'invoicing'),
1215
+        'TAP' => __('Taplejung', 'invoicing'),
1216
+        'BHO' => __('Bhojpur', 'invoicing'),
1217
+        'DKA' => __('Dhankuta', 'invoicing'),
1218
+        'MOR' => __('Morang', 'invoicing'),
1219
+        'SUN' => __('Sunsari', 'invoicing'),
1220
+        'SAN' => __('Sankhuwa', 'invoicing'),
1221
+        'TER' => __('Terhathum', 'invoicing'),
1222
+        'KHO' => __('Khotang', 'invoicing'),
1223
+        'OKH' => __('Okhaldhunga', 'invoicing'),
1224
+        'SAP' => __('Saptari', 'invoicing'),
1225
+        'SIR' => __('Siraha', 'invoicing'),
1226
+        'SOL' => __('Solukhumbu', 'invoicing'),
1227
+        'UDA' => __('Udayapur', 'invoicing'),
1228
+        'DHA' => __('Dhanusa', 'invoicing'),
1229
+        'DLK' => __('Dolakha', 'invoicing'),
1230
+        'MOH' => __('Mohottari', 'invoicing'),
1231
+        'RAM' => __('Ramechha', 'invoicing'),
1232
+        'SAR' => __('Sarlahi', 'invoicing'),
1233
+        'SIN' => __('Sindhuli', 'invoicing'),
1234
+        'BHA' => __('Bhaktapur', 'invoicing'),
1235
+        'DHD' => __('Dhading', 'invoicing'),
1236
+        'KTM' => __('Kathmandu', 'invoicing'),
1237
+        'KAV' => __('Kavrepalanchowk', 'invoicing'),
1238
+        'LAL' => __('Lalitpur', 'invoicing'),
1239
+        'NUW' => __('Nuwakot', 'invoicing'),
1240
+        'RAS' => __('Rasuwa', 'invoicing'),
1241
+        'SPC' => __('Sindhupalchowk', 'invoicing'),
1242
+        'BAR' => __('Bara', 'invoicing'),
1243
+        'CHI' => __('Chitwan', 'invoicing'),
1244
+        'MAK' => __('Makwanpur', 'invoicing'),
1245
+        'PAR' => __('Parsa', 'invoicing'),
1246
+        'RAU' => __('Rautahat', 'invoicing'),
1247
+        'GOR' => __('Gorkha', 'invoicing'),
1248
+        'KAS' => __('Kaski', 'invoicing'),
1249
+        'LAM' => __('Lamjung', 'invoicing'),
1250
+        'MAN' => __('Manang', 'invoicing'),
1251
+        'SYN' => __('Syangja', 'invoicing'),
1252
+        'TAN' => __('Tanahun', 'invoicing'),
1253
+        'BAG' => __('Baglung', 'invoicing'),
1254
+        'PBT' => __('Parbat', 'invoicing'),
1255
+        'MUS' => __('Mustang', 'invoicing'),
1256
+        'MYG' => __('Myagdi', 'invoicing'),
1257
+        'AGR' => __('Agrghakanchi', 'invoicing'),
1258
+        'GUL' => __('Gulmi', 'invoicing'),
1259
+        'KAP' => __('Kapilbastu', 'invoicing'),
1260
+        'NAW' => __('Nawalparasi', 'invoicing'),
1261
+        'PAL' => __('Palpa', 'invoicing'),
1262
+        'RUP' => __('Rupandehi', 'invoicing'),
1263
+        'DAN' => __('Dang', 'invoicing'),
1264
+        'PYU' => __('Pyuthan', 'invoicing'),
1265
+        'ROL' => __('Rolpa', 'invoicing'),
1266
+        'RUK' => __('Rukum', 'invoicing'),
1267
+        'SAL' => __('Salyan', 'invoicing'),
1268
+        'BAN' => __('Banke', 'invoicing'),
1269
+        'BDA' => __('Bardiya', 'invoicing'),
1270
+        'DAI' => __('Dailekh', 'invoicing'),
1271
+        'JAJ' => __('Jajarkot', 'invoicing'),
1272
+        'SUR' => __('Surkhet', 'invoicing'),
1273
+        'DOL' => __('Dolpa', 'invoicing'),
1274
+        'HUM' => __('Humla', 'invoicing'),
1275
+        'JUM' => __('Jumla', 'invoicing'),
1276
+        'KAL' => __('Kalikot', 'invoicing'),
1277
+        'MUG' => __('Mugu', 'invoicing'),
1278
+        'ACH' => __('Achham', 'invoicing'),
1279
+        'BJH' => __('Bajhang', 'invoicing'),
1280
+        'BJU' => __('Bajura', 'invoicing'),
1281
+        'DOT' => __('Doti', 'invoicing'),
1282
+        'KAI' => __('Kailali', 'invoicing'),
1283
+        'BAI' => __('Baitadi', 'invoicing'),
1284
+        'DAD' => __('Dadeldhura', 'invoicing'),
1285
+        'DAR' => __('Darchula', 'invoicing'),
1286
+        'KAN' => __('Kanchanpur', 'invoicing')
1287 1287
     );
1288 1288
 
1289
-    return apply_filters( 'wpinv_nepal_states', $states );
1289
+    return apply_filters('wpinv_nepal_states', $states);
1290 1290
 }
1291 1291
 
1292 1292
 function wpinv_get_south_africa_states_list() {
1293 1293
     $states = array(
1294
-        'EC'  => __( 'Eastern Cape', 'invoicing' ),
1295
-        'FS'  => __( 'Free State', 'invoicing' ),
1296
-        'GP'  => __( 'Gauteng', 'invoicing' ),
1297
-        'KZN' => __( 'KwaZulu-Natal', 'invoicing' ),
1298
-        'LP'  => __( 'Limpopo', 'invoicing' ),
1299
-        'MP'  => __( 'Mpumalanga', 'invoicing' ),
1300
-        'NC'  => __( 'Northern Cape', 'invoicing' ),
1301
-        'NW'  => __( 'North West', 'invoicing' ),
1302
-        'WC'  => __( 'Western Cape', 'invoicing' )
1294
+        'EC'  => __('Eastern Cape', 'invoicing'),
1295
+        'FS'  => __('Free State', 'invoicing'),
1296
+        'GP'  => __('Gauteng', 'invoicing'),
1297
+        'KZN' => __('KwaZulu-Natal', 'invoicing'),
1298
+        'LP'  => __('Limpopo', 'invoicing'),
1299
+        'MP'  => __('Mpumalanga', 'invoicing'),
1300
+        'NC'  => __('Northern Cape', 'invoicing'),
1301
+        'NW'  => __('North West', 'invoicing'),
1302
+        'WC'  => __('Western Cape', 'invoicing')
1303 1303
     );
1304 1304
 
1305
-    return apply_filters( 'wpinv_south_africa_states', $states );
1305
+    return apply_filters('wpinv_south_africa_states', $states);
1306 1306
 }
1307 1307
 
1308 1308
 function wpinv_get_thailand_states_list() {
1309 1309
     $states = array(
1310
-        'TH-37' => __( 'Amnat Charoen (อำนาจเจริญ)', 'invoicing' ),
1311
-        'TH-15' => __( 'Ang Thong (อ่างทอง)', 'invoicing' ),
1312
-        'TH-14' => __( 'Ayutthaya (พระนครศรีอยุธยา)', 'invoicing' ),
1313
-        'TH-10' => __( 'Bangkok (กรุงเทพมหานคร)', 'invoicing' ),
1314
-        'TH-38' => __( 'Bueng Kan (บึงกาฬ)', 'invoicing' ),
1315
-        'TH-31' => __( 'Buri Ram (บุรีรัมย์)', 'invoicing' ),
1316
-        'TH-24' => __( 'Chachoengsao (ฉะเชิงเทรา)', 'invoicing' ),
1317
-        'TH-18' => __( 'Chai Nat (ชัยนาท)', 'invoicing' ),
1318
-        'TH-36' => __( 'Chaiyaphum (ชัยภูมิ)', 'invoicing' ),
1319
-        'TH-22' => __( 'Chanthaburi (จันทบุรี)', 'invoicing' ),
1320
-        'TH-50' => __( 'Chiang Mai (เชียงใหม่)', 'invoicing' ),
1321
-        'TH-57' => __( 'Chiang Rai (เชียงราย)', 'invoicing' ),
1322
-        'TH-20' => __( 'Chonburi (ชลบุรี)', 'invoicing' ),
1323
-        'TH-86' => __( 'Chumphon (ชุมพร)', 'invoicing' ),
1324
-        'TH-46' => __( 'Kalasin (กาฬสินธุ์)', 'invoicing' ),
1325
-        'TH-62' => __( 'Kamphaeng Phet (กำแพงเพชร)', 'invoicing' ),
1326
-        'TH-71' => __( 'Kanchanaburi (กาญจนบุรี)', 'invoicing' ),
1327
-        'TH-40' => __( 'Khon Kaen (ขอนแก่น)', 'invoicing' ),
1328
-        'TH-81' => __( 'Krabi (กระบี่)', 'invoicing' ),
1329
-        'TH-52' => __( 'Lampang (ลำปาง)', 'invoicing' ),
1330
-        'TH-51' => __( 'Lamphun (ลำพูน)', 'invoicing' ),
1331
-        'TH-42' => __( 'Loei (เลย)', 'invoicing' ),
1332
-        'TH-16' => __( 'Lopburi (ลพบุรี)', 'invoicing' ),
1333
-        'TH-58' => __( 'Mae Hong Son (แม่ฮ่องสอน)', 'invoicing' ),
1334
-        'TH-44' => __( 'Maha Sarakham (มหาสารคาม)', 'invoicing' ),
1335
-        'TH-49' => __( 'Mukdahan (มุกดาหาร)', 'invoicing' ),
1336
-        'TH-26' => __( 'Nakhon Nayok (นครนายก)', 'invoicing' ),
1337
-        'TH-73' => __( 'Nakhon Pathom (นครปฐม)', 'invoicing' ),
1338
-        'TH-48' => __( 'Nakhon Phanom (นครพนม)', 'invoicing' ),
1339
-        'TH-30' => __( 'Nakhon Ratchasima (นครราชสีมา)', 'invoicing' ),
1340
-        'TH-60' => __( 'Nakhon Sawan (นครสวรรค์)', 'invoicing' ),
1341
-        'TH-80' => __( 'Nakhon Si Thammarat (นครศรีธรรมราช)', 'invoicing' ),
1342
-        'TH-55' => __( 'Nan (น่าน)', 'invoicing' ),
1343
-        'TH-96' => __( 'Narathiwat (นราธิวาส)', 'invoicing' ),
1344
-        'TH-39' => __( 'Nong Bua Lam Phu (หนองบัวลำภู)', 'invoicing' ),
1345
-        'TH-43' => __( 'Nong Khai (หนองคาย)', 'invoicing' ),
1346
-        'TH-12' => __( 'Nonthaburi (นนทบุรี)', 'invoicing' ),
1347
-        'TH-13' => __( 'Pathum Thani (ปทุมธานี)', 'invoicing' ),
1348
-        'TH-94' => __( 'Pattani (ปัตตานี)', 'invoicing' ),
1349
-        'TH-82' => __( 'Phang Nga (พังงา)', 'invoicing' ),
1350
-        'TH-93' => __( 'Phatthalung (พัทลุง)', 'invoicing' ),
1351
-        'TH-56' => __( 'Phayao (พะเยา)', 'invoicing' ),
1352
-        'TH-67' => __( 'Phetchabun (เพชรบูรณ์)', 'invoicing' ),
1353
-        'TH-76' => __( 'Phetchaburi (เพชรบุรี)', 'invoicing' ),
1354
-        'TH-66' => __( 'Phichit (พิจิตร)', 'invoicing' ),
1355
-        'TH-65' => __( 'Phitsanulok (พิษณุโลก)', 'invoicing' ),
1356
-        'TH-54' => __( 'Phrae (แพร่)', 'invoicing' ),
1357
-        'TH-83' => __( 'Phuket (ภูเก็ต)', 'invoicing' ),
1358
-        'TH-25' => __( 'Prachin Buri (ปราจีนบุรี)', 'invoicing' ),
1359
-        'TH-77' => __( 'Prachuap Khiri Khan (ประจวบคีรีขันธ์)', 'invoicing' ),
1360
-        'TH-85' => __( 'Ranong (ระนอง)', 'invoicing' ),
1361
-        'TH-70' => __( 'Ratchaburi (ราชบุรี)', 'invoicing' ),
1362
-        'TH-21' => __( 'Rayong (ระยอง)', 'invoicing' ),
1363
-        'TH-45' => __( 'Roi Et (ร้อยเอ็ด)', 'invoicing' ),
1364
-        'TH-27' => __( 'Sa Kaeo (สระแก้ว)', 'invoicing' ),
1365
-        'TH-47' => __( 'Sakon Nakhon (สกลนคร)', 'invoicing' ),
1366
-        'TH-11' => __( 'Samut Prakan (สมุทรปราการ)', 'invoicing' ),
1367
-        'TH-74' => __( 'Samut Sakhon (สมุทรสาคร)', 'invoicing' ),
1368
-        'TH-75' => __( 'Samut Songkhram (สมุทรสงคราม)', 'invoicing' ),
1369
-        'TH-19' => __( 'Saraburi (สระบุรี)', 'invoicing' ),
1370
-        'TH-91' => __( 'Satun (สตูล)', 'invoicing' ),
1371
-        'TH-17' => __( 'Sing Buri (สิงห์บุรี)', 'invoicing' ),
1372
-        'TH-33' => __( 'Sisaket (ศรีสะเกษ)', 'invoicing' ),
1373
-        'TH-90' => __( 'Songkhla (สงขลา)', 'invoicing' ),
1374
-        'TH-64' => __( 'Sukhothai (สุโขทัย)', 'invoicing' ),
1375
-        'TH-72' => __( 'Suphan Buri (สุพรรณบุรี)', 'invoicing' ),
1376
-        'TH-84' => __( 'Surat Thani (สุราษฎร์ธานี)', 'invoicing' ),
1377
-        'TH-32' => __( 'Surin (สุรินทร์)', 'invoicing' ),
1378
-        'TH-63' => __( 'Tak (ตาก)', 'invoicing' ),
1379
-        'TH-92' => __( 'Trang (ตรัง)', 'invoicing' ),
1380
-        'TH-23' => __( 'Trat (ตราด)', 'invoicing' ),
1381
-        'TH-34' => __( 'Ubon Ratchathani (อุบลราชธานี)', 'invoicing' ),
1382
-        'TH-41' => __( 'Udon Thani (อุดรธานี)', 'invoicing' ),
1383
-        'TH-61' => __( 'Uthai Thani (อุทัยธานี)', 'invoicing' ),
1384
-        'TH-53' => __( 'Uttaradit (อุตรดิตถ์)', 'invoicing' ),
1385
-        'TH-95' => __( 'Yala (ยะลา)', 'invoicing' ),
1386
-        'TH-35' => __( 'Yasothon (ยโสธร)', 'invoicing' )
1310
+        'TH-37' => __('Amnat Charoen (อำนาจเจริญ)', 'invoicing'),
1311
+        'TH-15' => __('Ang Thong (อ่างทอง)', 'invoicing'),
1312
+        'TH-14' => __('Ayutthaya (พระนครศรีอยุธยา)', 'invoicing'),
1313
+        'TH-10' => __('Bangkok (กรุงเทพมหานคร)', 'invoicing'),
1314
+        'TH-38' => __('Bueng Kan (บึงกาฬ)', 'invoicing'),
1315
+        'TH-31' => __('Buri Ram (บุรีรัมย์)', 'invoicing'),
1316
+        'TH-24' => __('Chachoengsao (ฉะเชิงเทรา)', 'invoicing'),
1317
+        'TH-18' => __('Chai Nat (ชัยนาท)', 'invoicing'),
1318
+        'TH-36' => __('Chaiyaphum (ชัยภูมิ)', 'invoicing'),
1319
+        'TH-22' => __('Chanthaburi (จันทบุรี)', 'invoicing'),
1320
+        'TH-50' => __('Chiang Mai (เชียงใหม่)', 'invoicing'),
1321
+        'TH-57' => __('Chiang Rai (เชียงราย)', 'invoicing'),
1322
+        'TH-20' => __('Chonburi (ชลบุรี)', 'invoicing'),
1323
+        'TH-86' => __('Chumphon (ชุมพร)', 'invoicing'),
1324
+        'TH-46' => __('Kalasin (กาฬสินธุ์)', 'invoicing'),
1325
+        'TH-62' => __('Kamphaeng Phet (กำแพงเพชร)', 'invoicing'),
1326
+        'TH-71' => __('Kanchanaburi (กาญจนบุรี)', 'invoicing'),
1327
+        'TH-40' => __('Khon Kaen (ขอนแก่น)', 'invoicing'),
1328
+        'TH-81' => __('Krabi (กระบี่)', 'invoicing'),
1329
+        'TH-52' => __('Lampang (ลำปาง)', 'invoicing'),
1330
+        'TH-51' => __('Lamphun (ลำพูน)', 'invoicing'),
1331
+        'TH-42' => __('Loei (เลย)', 'invoicing'),
1332
+        'TH-16' => __('Lopburi (ลพบุรี)', 'invoicing'),
1333
+        'TH-58' => __('Mae Hong Son (แม่ฮ่องสอน)', 'invoicing'),
1334
+        'TH-44' => __('Maha Sarakham (มหาสารคาม)', 'invoicing'),
1335
+        'TH-49' => __('Mukdahan (มุกดาหาร)', 'invoicing'),
1336
+        'TH-26' => __('Nakhon Nayok (นครนายก)', 'invoicing'),
1337
+        'TH-73' => __('Nakhon Pathom (นครปฐม)', 'invoicing'),
1338
+        'TH-48' => __('Nakhon Phanom (นครพนม)', 'invoicing'),
1339
+        'TH-30' => __('Nakhon Ratchasima (นครราชสีมา)', 'invoicing'),
1340
+        'TH-60' => __('Nakhon Sawan (นครสวรรค์)', 'invoicing'),
1341
+        'TH-80' => __('Nakhon Si Thammarat (นครศรีธรรมราช)', 'invoicing'),
1342
+        'TH-55' => __('Nan (น่าน)', 'invoicing'),
1343
+        'TH-96' => __('Narathiwat (นราธิวาส)', 'invoicing'),
1344
+        'TH-39' => __('Nong Bua Lam Phu (หนองบัวลำภู)', 'invoicing'),
1345
+        'TH-43' => __('Nong Khai (หนองคาย)', 'invoicing'),
1346
+        'TH-12' => __('Nonthaburi (นนทบุรี)', 'invoicing'),
1347
+        'TH-13' => __('Pathum Thani (ปทุมธานี)', 'invoicing'),
1348
+        'TH-94' => __('Pattani (ปัตตานี)', 'invoicing'),
1349
+        'TH-82' => __('Phang Nga (พังงา)', 'invoicing'),
1350
+        'TH-93' => __('Phatthalung (พัทลุง)', 'invoicing'),
1351
+        'TH-56' => __('Phayao (พะเยา)', 'invoicing'),
1352
+        'TH-67' => __('Phetchabun (เพชรบูรณ์)', 'invoicing'),
1353
+        'TH-76' => __('Phetchaburi (เพชรบุรี)', 'invoicing'),
1354
+        'TH-66' => __('Phichit (พิจิตร)', 'invoicing'),
1355
+        'TH-65' => __('Phitsanulok (พิษณุโลก)', 'invoicing'),
1356
+        'TH-54' => __('Phrae (แพร่)', 'invoicing'),
1357
+        'TH-83' => __('Phuket (ภูเก็ต)', 'invoicing'),
1358
+        'TH-25' => __('Prachin Buri (ปราจีนบุรี)', 'invoicing'),
1359
+        'TH-77' => __('Prachuap Khiri Khan (ประจวบคีรีขันธ์)', 'invoicing'),
1360
+        'TH-85' => __('Ranong (ระนอง)', 'invoicing'),
1361
+        'TH-70' => __('Ratchaburi (ราชบุรี)', 'invoicing'),
1362
+        'TH-21' => __('Rayong (ระยอง)', 'invoicing'),
1363
+        'TH-45' => __('Roi Et (ร้อยเอ็ด)', 'invoicing'),
1364
+        'TH-27' => __('Sa Kaeo (สระแก้ว)', 'invoicing'),
1365
+        'TH-47' => __('Sakon Nakhon (สกลนคร)', 'invoicing'),
1366
+        'TH-11' => __('Samut Prakan (สมุทรปราการ)', 'invoicing'),
1367
+        'TH-74' => __('Samut Sakhon (สมุทรสาคร)', 'invoicing'),
1368
+        'TH-75' => __('Samut Songkhram (สมุทรสงคราม)', 'invoicing'),
1369
+        'TH-19' => __('Saraburi (สระบุรี)', 'invoicing'),
1370
+        'TH-91' => __('Satun (สตูล)', 'invoicing'),
1371
+        'TH-17' => __('Sing Buri (สิงห์บุรี)', 'invoicing'),
1372
+        'TH-33' => __('Sisaket (ศรีสะเกษ)', 'invoicing'),
1373
+        'TH-90' => __('Songkhla (สงขลา)', 'invoicing'),
1374
+        'TH-64' => __('Sukhothai (สุโขทัย)', 'invoicing'),
1375
+        'TH-72' => __('Suphan Buri (สุพรรณบุรี)', 'invoicing'),
1376
+        'TH-84' => __('Surat Thani (สุราษฎร์ธานี)', 'invoicing'),
1377
+        'TH-32' => __('Surin (สุรินทร์)', 'invoicing'),
1378
+        'TH-63' => __('Tak (ตาก)', 'invoicing'),
1379
+        'TH-92' => __('Trang (ตรัง)', 'invoicing'),
1380
+        'TH-23' => __('Trat (ตราด)', 'invoicing'),
1381
+        'TH-34' => __('Ubon Ratchathani (อุบลราชธานี)', 'invoicing'),
1382
+        'TH-41' => __('Udon Thani (อุดรธานี)', 'invoicing'),
1383
+        'TH-61' => __('Uthai Thani (อุทัยธานี)', 'invoicing'),
1384
+        'TH-53' => __('Uttaradit (อุตรดิตถ์)', 'invoicing'),
1385
+        'TH-95' => __('Yala (ยะลา)', 'invoicing'),
1386
+        'TH-35' => __('Yasothon (ยโสธร)', 'invoicing')
1387 1387
     );
1388 1388
 
1389
-    return apply_filters( 'wpinv_thailand_states', $states );
1389
+    return apply_filters('wpinv_thailand_states', $states);
1390 1390
 }
1391 1391
 
1392 1392
 function wpinv_get_turkey_states_list() {
1393 1393
     $states = array(
1394
-        'TR01' => __( 'Adana', 'invoicing' ),
1395
-        'TR02' => __( 'Adıyaman', 'invoicing' ),
1396
-        'TR03' => __( 'Afyon', 'invoicing' ),
1397
-        'TR04' => __( 'Ağrı', 'invoicing' ),
1398
-        'TR05' => __( 'Amasya', 'invoicing' ),
1399
-        'TR06' => __( 'Ankara', 'invoicing' ),
1400
-        'TR07' => __( 'Antalya', 'invoicing' ),
1401
-        'TR08' => __( 'Artvin', 'invoicing' ),
1402
-        'TR09' => __( 'Aydın', 'invoicing' ),
1403
-        'TR10' => __( 'Balıkesir', 'invoicing' ),
1404
-        'TR11' => __( 'Bilecik', 'invoicing' ),
1405
-        'TR12' => __( 'Bingöl', 'invoicing' ),
1406
-        'TR13' => __( 'Bitlis', 'invoicing' ),
1407
-        'TR14' => __( 'Bolu', 'invoicing' ),
1408
-        'TR15' => __( 'Burdur', 'invoicing' ),
1409
-        'TR16' => __( 'Bursa', 'invoicing' ),
1410
-        'TR17' => __( 'Çanakkale', 'invoicing' ),
1411
-        'TR18' => __( 'Çankıkesir', 'invoicing' ),
1412
-        'TR19' => __( 'Çorum', 'invoicing' ),
1413
-        'TR20' => __( 'Denizli', 'invoicing' ),
1414
-        'TR21' => __( 'Diyarbakır', 'invoicing' ),
1415
-        'TR22' => __( 'Edirne', 'invoicing' ),
1416
-        'TR23' => __( 'Elazığ', 'invoicing' ),
1417
-        'TR24' => __( 'Erzincan', 'invoicing' ),
1418
-        'TR25' => __( 'Erzurum', 'invoicing' ),
1419
-        'TR26' => __( 'Eskişehir', 'invoicing' ),
1420
-        'TR27' => __( 'Gaziantep', 'invoicing' ),
1421
-        'TR28' => __( 'Giresun', 'invoicing' ),
1422
-        'TR29' => __( 'Gümüşhane', 'invoicing' ),
1423
-        'TR30' => __( 'Hakkari', 'invoicing' ),
1424
-        'TR31' => __( 'Hatay', 'invoicing' ),
1425
-        'TR32' => __( 'Isparta', 'invoicing' ),
1426
-        'TR33' => __( 'İçel', 'invoicing' ),
1427
-        'TR34' => __( 'İstanbul', 'invoicing' ),
1428
-        'TR35' => __( 'İzmir', 'invoicing' ),
1429
-        'TR36' => __( 'Kars', 'invoicing' ),
1430
-        'TR37' => __( 'Kastamonu', 'invoicing' ),
1431
-        'TR38' => __( 'Kayseri', 'invoicing' ),
1432
-        'TR39' => __( 'Kırklareli', 'invoicing' ),
1433
-        'TR40' => __( 'Kırşehir', 'invoicing' ),
1434
-        'TR41' => __( 'Kocaeli', 'invoicing' ),
1435
-        'TR42' => __( 'Konya', 'invoicing' ),
1436
-        'TR43' => __( 'Kütahya', 'invoicing' ),
1437
-        'TR44' => __( 'Malatya', 'invoicing' ),
1438
-        'TR45' => __( 'Manisa', 'invoicing' ),
1439
-        'TR46' => __( 'Kahramanmaraş', 'invoicing' ),
1440
-        'TR47' => __( 'Mardin', 'invoicing' ),
1441
-        'TR48' => __( 'Muğla', 'invoicing' ),
1442
-        'TR49' => __( 'Muş', 'invoicing' ),
1443
-        'TR50' => __( 'Nevşehir', 'invoicing' ),
1444
-        'TR51' => __( 'Niğde', 'invoicing' ),
1445
-        'TR52' => __( 'Ordu', 'invoicing' ),
1446
-        'TR53' => __( 'Rize', 'invoicing' ),
1447
-        'TR54' => __( 'Sakarya', 'invoicing' ),
1448
-        'TR55' => __( 'Samsun', 'invoicing' ),
1449
-        'TR56' => __( 'Siirt', 'invoicing' ),
1450
-        'TR57' => __( 'Sinop', 'invoicing' ),
1451
-        'TR58' => __( 'Sivas', 'invoicing' ),
1452
-        'TR59' => __( 'Tekirdağ', 'invoicing' ),
1453
-        'TR60' => __( 'Tokat', 'invoicing' ),
1454
-        'TR61' => __( 'Trabzon', 'invoicing' ),
1455
-        'TR62' => __( 'Tunceli', 'invoicing' ),
1456
-        'TR63' => __( 'Şanlıurfa', 'invoicing' ),
1457
-        'TR64' => __( 'Uşak', 'invoicing' ),
1458
-        'TR65' => __( 'Van', 'invoicing' ),
1459
-        'TR66' => __( 'Yozgat', 'invoicing' ),
1460
-        'TR67' => __( 'Zonguldak', 'invoicing' ),
1461
-        'TR68' => __( 'Aksaray', 'invoicing' ),
1462
-        'TR69' => __( 'Bayburt', 'invoicing' ),
1463
-        'TR70' => __( 'Karaman', 'invoicing' ),
1464
-        'TR71' => __( 'Kırıkkale', 'invoicing' ),
1465
-        'TR72' => __( 'Batman', 'invoicing' ),
1466
-        'TR73' => __( 'Şırnak', 'invoicing' ),
1467
-        'TR74' => __( 'Bartın', 'invoicing' ),
1468
-        'TR75' => __( 'Ardahan', 'invoicing' ),
1469
-        'TR76' => __( 'Iğdır', 'invoicing' ),
1470
-        'TR77' => __( 'Yalova', 'invoicing' ),
1471
-        'TR78' => __( 'Karabük', 'invoicing' ),
1472
-        'TR79' => __( 'Kilis', 'invoicing' ),
1473
-        'TR80' => __( 'Osmaniye', 'invoicing' ),
1474
-        'TR81' => __( 'Düzce', 'invoicing' )
1394
+        'TR01' => __('Adana', 'invoicing'),
1395
+        'TR02' => __('Adıyaman', 'invoicing'),
1396
+        'TR03' => __('Afyon', 'invoicing'),
1397
+        'TR04' => __('Ağrı', 'invoicing'),
1398
+        'TR05' => __('Amasya', 'invoicing'),
1399
+        'TR06' => __('Ankara', 'invoicing'),
1400
+        'TR07' => __('Antalya', 'invoicing'),
1401
+        'TR08' => __('Artvin', 'invoicing'),
1402
+        'TR09' => __('Aydın', 'invoicing'),
1403
+        'TR10' => __('Balıkesir', 'invoicing'),
1404
+        'TR11' => __('Bilecik', 'invoicing'),
1405
+        'TR12' => __('Bingöl', 'invoicing'),
1406
+        'TR13' => __('Bitlis', 'invoicing'),
1407
+        'TR14' => __('Bolu', 'invoicing'),
1408
+        'TR15' => __('Burdur', 'invoicing'),
1409
+        'TR16' => __('Bursa', 'invoicing'),
1410
+        'TR17' => __('Çanakkale', 'invoicing'),
1411
+        'TR18' => __('Çankıkesir', 'invoicing'),
1412
+        'TR19' => __('Çorum', 'invoicing'),
1413
+        'TR20' => __('Denizli', 'invoicing'),
1414
+        'TR21' => __('Diyarbakır', 'invoicing'),
1415
+        'TR22' => __('Edirne', 'invoicing'),
1416
+        'TR23' => __('Elazığ', 'invoicing'),
1417
+        'TR24' => __('Erzincan', 'invoicing'),
1418
+        'TR25' => __('Erzurum', 'invoicing'),
1419
+        'TR26' => __('Eskişehir', 'invoicing'),
1420
+        'TR27' => __('Gaziantep', 'invoicing'),
1421
+        'TR28' => __('Giresun', 'invoicing'),
1422
+        'TR29' => __('Gümüşhane', 'invoicing'),
1423
+        'TR30' => __('Hakkari', 'invoicing'),
1424
+        'TR31' => __('Hatay', 'invoicing'),
1425
+        'TR32' => __('Isparta', 'invoicing'),
1426
+        'TR33' => __('İçel', 'invoicing'),
1427
+        'TR34' => __('İstanbul', 'invoicing'),
1428
+        'TR35' => __('İzmir', 'invoicing'),
1429
+        'TR36' => __('Kars', 'invoicing'),
1430
+        'TR37' => __('Kastamonu', 'invoicing'),
1431
+        'TR38' => __('Kayseri', 'invoicing'),
1432
+        'TR39' => __('Kırklareli', 'invoicing'),
1433
+        'TR40' => __('Kırşehir', 'invoicing'),
1434
+        'TR41' => __('Kocaeli', 'invoicing'),
1435
+        'TR42' => __('Konya', 'invoicing'),
1436
+        'TR43' => __('Kütahya', 'invoicing'),
1437
+        'TR44' => __('Malatya', 'invoicing'),
1438
+        'TR45' => __('Manisa', 'invoicing'),
1439
+        'TR46' => __('Kahramanmaraş', 'invoicing'),
1440
+        'TR47' => __('Mardin', 'invoicing'),
1441
+        'TR48' => __('Muğla', 'invoicing'),
1442
+        'TR49' => __('Muş', 'invoicing'),
1443
+        'TR50' => __('Nevşehir', 'invoicing'),
1444
+        'TR51' => __('Niğde', 'invoicing'),
1445
+        'TR52' => __('Ordu', 'invoicing'),
1446
+        'TR53' => __('Rize', 'invoicing'),
1447
+        'TR54' => __('Sakarya', 'invoicing'),
1448
+        'TR55' => __('Samsun', 'invoicing'),
1449
+        'TR56' => __('Siirt', 'invoicing'),
1450
+        'TR57' => __('Sinop', 'invoicing'),
1451
+        'TR58' => __('Sivas', 'invoicing'),
1452
+        'TR59' => __('Tekirdağ', 'invoicing'),
1453
+        'TR60' => __('Tokat', 'invoicing'),
1454
+        'TR61' => __('Trabzon', 'invoicing'),
1455
+        'TR62' => __('Tunceli', 'invoicing'),
1456
+        'TR63' => __('Şanlıurfa', 'invoicing'),
1457
+        'TR64' => __('Uşak', 'invoicing'),
1458
+        'TR65' => __('Van', 'invoicing'),
1459
+        'TR66' => __('Yozgat', 'invoicing'),
1460
+        'TR67' => __('Zonguldak', 'invoicing'),
1461
+        'TR68' => __('Aksaray', 'invoicing'),
1462
+        'TR69' => __('Bayburt', 'invoicing'),
1463
+        'TR70' => __('Karaman', 'invoicing'),
1464
+        'TR71' => __('Kırıkkale', 'invoicing'),
1465
+        'TR72' => __('Batman', 'invoicing'),
1466
+        'TR73' => __('Şırnak', 'invoicing'),
1467
+        'TR74' => __('Bartın', 'invoicing'),
1468
+        'TR75' => __('Ardahan', 'invoicing'),
1469
+        'TR76' => __('Iğdır', 'invoicing'),
1470
+        'TR77' => __('Yalova', 'invoicing'),
1471
+        'TR78' => __('Karabük', 'invoicing'),
1472
+        'TR79' => __('Kilis', 'invoicing'),
1473
+        'TR80' => __('Osmaniye', 'invoicing'),
1474
+        'TR81' => __('Düzce', 'invoicing')
1475 1475
     );
1476 1476
 
1477
-    return apply_filters( 'wpinv_turkey_states', $states );
1477
+    return apply_filters('wpinv_turkey_states', $states);
1478 1478
 }
1479 1479
 
1480 1480
 function wpinv_get_spain_states_list() {
1481 1481
     $states = array(
1482
-        'C'  => __( 'A Coruña', 'invoicing' ),
1483
-        'VI' => __( 'Araba', 'invoicing' ),
1484
-        'AB' => __( 'Albacete', 'invoicing' ),
1485
-        'A'  => __( 'Alicante', 'invoicing' ),
1486
-        'AL' => __( 'Almería', 'invoicing' ),
1487
-        'O'  => __( 'Asturias', 'invoicing' ),
1488
-        'AV' => __( 'Ávila', 'invoicing' ),
1489
-        'BA' => __( 'Badajoz', 'invoicing' ),
1490
-        'PM' => __( 'Baleares', 'invoicing' ),
1491
-        'B'  => __( 'Barcelona', 'invoicing' ),
1492
-        'BU' => __( 'Burgos', 'invoicing' ),
1493
-        'CC' => __( 'Cáceres', 'invoicing' ),
1494
-        'CA' => __( 'Cádiz', 'invoicing' ),
1495
-        'S'  => __( 'Cantabria', 'invoicing' ),
1496
-        'CS' => __( 'Castellón', 'invoicing' ),
1497
-        'CE' => __( 'Ceuta', 'invoicing' ),
1498
-        'CR' => __( 'Ciudad Real', 'invoicing' ),
1499
-        'CO' => __( 'Córdoba', 'invoicing' ),
1500
-        'CU' => __( 'Cuenca', 'invoicing' ),
1501
-        'GI' => __( 'Girona', 'invoicing' ),
1502
-        'GR' => __( 'Granada', 'invoicing' ),
1503
-        'GU' => __( 'Guadalajara', 'invoicing' ),
1504
-        'SS' => __( 'Gipuzkoa', 'invoicing' ),
1505
-        'H'  => __( 'Huelva', 'invoicing' ),
1506
-        'HU' => __( 'Huesca', 'invoicing' ),
1507
-        'J'  => __( 'Jaén', 'invoicing' ),
1508
-        'LO' => __( 'La Rioja', 'invoicing' ),
1509
-        'GC' => __( 'Las Palmas', 'invoicing' ),
1510
-        'LE' => __( 'León', 'invoicing' ),
1511
-        'L'  => __( 'Lleida', 'invoicing' ),
1512
-        'LU' => __( 'Lugo', 'invoicing' ),
1513
-        'M'  => __( 'Madrid', 'invoicing' ),
1514
-        'MA' => __( 'Málaga', 'invoicing' ),
1515
-        'ML' => __( 'Melilla', 'invoicing' ),
1516
-        'MU' => __( 'Murcia', 'invoicing' ),
1517
-        'NA' => __( 'Navarra', 'invoicing' ),
1518
-        'OR' => __( 'Ourense', 'invoicing' ),
1519
-        'P'  => __( 'Palencia', 'invoicing' ),
1520
-        'PO' => __( 'Pontevedra', 'invoicing' ),
1521
-        'SA' => __( 'Salamanca', 'invoicing' ),
1522
-        'TF' => __( 'Santa Cruz de Tenerife', 'invoicing' ),
1523
-        'SG' => __( 'Segovia', 'invoicing' ),
1524
-        'SE' => __( 'Sevilla', 'invoicing' ),
1525
-        'SO' => __( 'Soria', 'invoicing' ),
1526
-        'T'  => __( 'Tarragona', 'invoicing' ),
1527
-        'TE' => __( 'Teruel', 'invoicing' ),
1528
-        'TO' => __( 'Toledo', 'invoicing' ),
1529
-        'V'  => __( 'Valencia', 'invoicing' ),
1530
-        'VA' => __( 'Valladolid', 'invoicing' ),
1531
-        'BI' => __( 'Bizkaia', 'invoicing' ),
1532
-        'ZA' => __( 'Zamora', 'invoicing' ),
1533
-        'Z'  => __( 'Zaragoza', 'invoicing' )
1482
+        'C'  => __('A Coruña', 'invoicing'),
1483
+        'VI' => __('Araba', 'invoicing'),
1484
+        'AB' => __('Albacete', 'invoicing'),
1485
+        'A'  => __('Alicante', 'invoicing'),
1486
+        'AL' => __('Almería', 'invoicing'),
1487
+        'O'  => __('Asturias', 'invoicing'),
1488
+        'AV' => __('Ávila', 'invoicing'),
1489
+        'BA' => __('Badajoz', 'invoicing'),
1490
+        'PM' => __('Baleares', 'invoicing'),
1491
+        'B'  => __('Barcelona', 'invoicing'),
1492
+        'BU' => __('Burgos', 'invoicing'),
1493
+        'CC' => __('Cáceres', 'invoicing'),
1494
+        'CA' => __('Cádiz', 'invoicing'),
1495
+        'S'  => __('Cantabria', 'invoicing'),
1496
+        'CS' => __('Castellón', 'invoicing'),
1497
+        'CE' => __('Ceuta', 'invoicing'),
1498
+        'CR' => __('Ciudad Real', 'invoicing'),
1499
+        'CO' => __('Córdoba', 'invoicing'),
1500
+        'CU' => __('Cuenca', 'invoicing'),
1501
+        'GI' => __('Girona', 'invoicing'),
1502
+        'GR' => __('Granada', 'invoicing'),
1503
+        'GU' => __('Guadalajara', 'invoicing'),
1504
+        'SS' => __('Gipuzkoa', 'invoicing'),
1505
+        'H'  => __('Huelva', 'invoicing'),
1506
+        'HU' => __('Huesca', 'invoicing'),
1507
+        'J'  => __('Jaén', 'invoicing'),
1508
+        'LO' => __('La Rioja', 'invoicing'),
1509
+        'GC' => __('Las Palmas', 'invoicing'),
1510
+        'LE' => __('León', 'invoicing'),
1511
+        'L'  => __('Lleida', 'invoicing'),
1512
+        'LU' => __('Lugo', 'invoicing'),
1513
+        'M'  => __('Madrid', 'invoicing'),
1514
+        'MA' => __('Málaga', 'invoicing'),
1515
+        'ML' => __('Melilla', 'invoicing'),
1516
+        'MU' => __('Murcia', 'invoicing'),
1517
+        'NA' => __('Navarra', 'invoicing'),
1518
+        'OR' => __('Ourense', 'invoicing'),
1519
+        'P'  => __('Palencia', 'invoicing'),
1520
+        'PO' => __('Pontevedra', 'invoicing'),
1521
+        'SA' => __('Salamanca', 'invoicing'),
1522
+        'TF' => __('Santa Cruz de Tenerife', 'invoicing'),
1523
+        'SG' => __('Segovia', 'invoicing'),
1524
+        'SE' => __('Sevilla', 'invoicing'),
1525
+        'SO' => __('Soria', 'invoicing'),
1526
+        'T'  => __('Tarragona', 'invoicing'),
1527
+        'TE' => __('Teruel', 'invoicing'),
1528
+        'TO' => __('Toledo', 'invoicing'),
1529
+        'V'  => __('Valencia', 'invoicing'),
1530
+        'VA' => __('Valladolid', 'invoicing'),
1531
+        'BI' => __('Bizkaia', 'invoicing'),
1532
+        'ZA' => __('Zamora', 'invoicing'),
1533
+        'Z'  => __('Zaragoza', 'invoicing')
1534 1534
     );
1535 1535
 
1536
-    return apply_filters( 'wpinv_spain_states', $states );
1536
+    return apply_filters('wpinv_spain_states', $states);
1537 1537
 }
1538 1538
 
1539 1539
 function wpinv_get_states_field() {
1540
-	if( empty( $_POST['country'] ) ) {
1540
+	if (empty($_POST['country'])) {
1541 1541
 		$_POST['country'] = wpinv_get_default_country();
1542 1542
 	}
1543
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1543
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
1544 1544
 
1545
-	if( !empty( $states ) ) {
1546
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1545
+	if (!empty($states)) {
1546
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
1547 1547
         
1548 1548
         $args = array(
1549 1549
 			'name'    => $sanitized_field_name,
1550 1550
 			'id'      => $sanitized_field_name,
1551 1551
 			'class'   => $sanitized_field_name . ' wpinv-select',
1552
-			'options' => array_merge( array( '' => '' ), $states ),
1552
+			'options' => array_merge(array('' => ''), $states),
1553 1553
 			'show_option_all'  => false,
1554 1554
 			'show_option_none' => false
1555 1555
 		);
1556 1556
 
1557
-		$response = wpinv_html_select( $args );
1557
+		$response = wpinv_html_select($args);
1558 1558
 
1559 1559
 	} else {
1560 1560
 		$response = 'nostates';
@@ -1563,8 +1563,8 @@  discard block
 block discarded – undo
1563 1563
 	return $response;
1564 1564
 }
1565 1565
 
1566
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
1567
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
1566
+function wpinv_default_billing_country($country = '', $user_id = 0) {
1567
+    $country = !empty($country) ? $country : wpinv_get_default_country();
1568 1568
     
1569
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
1569
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
1570 1570
 }
1571 1571
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -7,440 +7,440 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
25
-    if ( $cart && empty( $invoice_id ) ) {
24
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
25
+    if ($cart && empty($invoice_id)) {
26 26
         $invoice_id = (int)wpinv_get_invoice_cart_id();
27 27
     }
28 28
 
29
-    $invoice = new WPInv_Invoice( $invoice_id );
29
+    $invoice = new WPInv_Invoice($invoice_id);
30 30
     return $invoice;
31 31
 }
32 32
 
33
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
34
-    return wpinv_get_invoice( $invoice_id, true );
33
+function wpinv_get_invoice_cart($invoice_id = 0) {
34
+    return wpinv_get_invoice($invoice_id, true);
35 35
 }
36 36
 
37
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
38
-    $invoice = new WPInv_Invoice( $invoice_id );
37
+function wpinv_get_invoice_description($invoice_id = 0) {
38
+    $invoice = new WPInv_Invoice($invoice_id);
39 39
     return $invoice->get_description();
40 40
 }
41 41
 
42
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
43
-    $invoice = new WPInv_Invoice( $invoice_id );
42
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
43
+    $invoice = new WPInv_Invoice($invoice_id);
44 44
     return $invoice->get_currency();
45 45
 }
46 46
 
47
-function wpinv_get_payment_user_email( $invoice_id ) {
48
-    $invoice = new WPInv_Invoice( $invoice_id );
47
+function wpinv_get_payment_user_email($invoice_id) {
48
+    $invoice = new WPInv_Invoice($invoice_id);
49 49
     return $invoice->get_email();
50 50
 }
51 51
 
52
-function wpinv_get_user_id( $invoice_id ) {
53
-    $invoice = new WPInv_Invoice( $invoice_id );
52
+function wpinv_get_user_id($invoice_id) {
53
+    $invoice = new WPInv_Invoice($invoice_id);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
58
-    $invoice = new WPInv_Invoice( $invoice_id );
57
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
58
+    $invoice = new WPInv_Invoice($invoice_id);
59 59
     
60
-    return $invoice->get_status( $return_label );
60
+    return $invoice->get_status($return_label);
61 61
 }
62 62
 
63
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
64
-    $invoice = new WPInv_Invoice( $invoice_id );
63
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
64
+    $invoice = new WPInv_Invoice($invoice_id);
65 65
     
66
-    return $invoice->get_gateway( $return_label );
66
+    return $invoice->get_gateway($return_label);
67 67
 }
68 68
 
69
-function wpinv_get_payment_gateway_name( $invoice_id ) {
70
-    $invoice = new WPInv_Invoice( $invoice_id );
69
+function wpinv_get_payment_gateway_name($invoice_id) {
70
+    $invoice = new WPInv_Invoice($invoice_id);
71 71
     
72 72
     return $invoice->get_gateway_title();
73 73
 }
74 74
 
75
-function wpinv_get_payment_transaction_id( $invoice_id ) {
76
-    $invoice = new WPInv_Invoice( $invoice_id );
75
+function wpinv_get_payment_transaction_id($invoice_id) {
76
+    $invoice = new WPInv_Invoice($invoice_id);
77 77
     
78 78
     return $invoice->get_transaction_id();
79 79
 }
80 80
 
81
-function wpinv_get_id_by_transaction_id( $key ) {
81
+function wpinv_get_id_by_transaction_id($key) {
82 82
     global $wpdb;
83 83
 
84
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
84
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
85 85
 
86
-    if ( $invoice_id != NULL )
86
+    if ($invoice_id != NULL)
87 87
         return $invoice_id;
88 88
 
89 89
     return 0;
90 90
 }
91 91
 
92
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
93
-    $invoice = new WPInv_Invoice( $invoice_id );
92
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
93
+    $invoice = new WPInv_Invoice($invoice_id);
94 94
 
95
-    return $invoice->get_meta( $meta_key, $single );
95
+    return $invoice->get_meta($meta_key, $single);
96 96
 }
97 97
 
98
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
99
-    $invoice = new WPInv_Invoice( $invoice_id );
98
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
99
+    $invoice = new WPInv_Invoice($invoice_id);
100 100
     
101
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
101
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
102 102
 }
103 103
 
104
-function wpinv_get_items( $invoice_id = 0 ) {
105
-    $invoice            = wpinv_get_invoice( $invoice_id );
104
+function wpinv_get_items($invoice_id = 0) {
105
+    $invoice            = wpinv_get_invoice($invoice_id);
106 106
     
107 107
     $items              = $invoice->get_items();
108 108
     $invoice_currency   = $invoice->get_currency();
109 109
 
110
-    if ( !empty( $items ) && is_array( $items ) ) {
111
-        foreach ( $items as $key => $item ) {
110
+    if (!empty($items) && is_array($items)) {
111
+        foreach ($items as $key => $item) {
112 112
             $items[$key]['currency'] = $invoice_currency;
113 113
 
114
-            if ( !isset( $cart_item['subtotal'] ) ) {
114
+            if (!isset($cart_item['subtotal'])) {
115 115
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
116 116
             }
117 117
         }
118 118
     }
119 119
 
120
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
120
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
121 121
 }
122 122
 
123
-function wpinv_get_fees( $invoice_id = 0 ) {
124
-    $invoice           = wpinv_get_invoice( $invoice_id );
123
+function wpinv_get_fees($invoice_id = 0) {
124
+    $invoice           = wpinv_get_invoice($invoice_id);
125 125
     $fees              = $invoice->get_fees();
126 126
 
127
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
127
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
128 128
 }
129 129
 
130
-function wpinv_get_invoice_ip( $invoice_id ) {
131
-    $invoice = new WPInv_Invoice( $invoice_id );
130
+function wpinv_get_invoice_ip($invoice_id) {
131
+    $invoice = new WPInv_Invoice($invoice_id);
132 132
     return $invoice->get_ip();
133 133
 }
134 134
 
135
-function wpinv_get_invoice_user_info( $invoice_id ) {
136
-    $invoice = new WPInv_Invoice( $invoice_id );
135
+function wpinv_get_invoice_user_info($invoice_id) {
136
+    $invoice = new WPInv_Invoice($invoice_id);
137 137
     return $invoice->get_user_info();
138 138
 }
139 139
 
140
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
141
-    $invoice = new WPInv_Invoice( $invoice_id );
140
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
141
+    $invoice = new WPInv_Invoice($invoice_id);
142 142
 
143
-    return $invoice->get_subtotal( $currency );
143
+    return $invoice->get_subtotal($currency);
144 144
 }
145 145
 
146
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
147
-    $invoice = new WPInv_Invoice( $invoice_id );
146
+function wpinv_tax($invoice_id = 0, $currency = false) {
147
+    $invoice = new WPInv_Invoice($invoice_id);
148 148
 
149
-    return $invoice->get_tax( $currency );
149
+    return $invoice->get_tax($currency);
150 150
 }
151 151
 
152
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
153
-    $invoice = wpinv_get_invoice( $invoice_id );
152
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
153
+    $invoice = wpinv_get_invoice($invoice_id);
154 154
 
155
-    return $invoice->get_discount( $currency, $dash );
155
+    return $invoice->get_discount($currency, $dash);
156 156
 }
157 157
 
158
-function wpinv_discount_code( $invoice_id = 0 ) {
159
-    $invoice = new WPInv_Invoice( $invoice_id );
158
+function wpinv_discount_code($invoice_id = 0) {
159
+    $invoice = new WPInv_Invoice($invoice_id);
160 160
 
161 161
     return $invoice->get_discount_code();
162 162
 }
163 163
 
164
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
165
-    $invoice = new WPInv_Invoice( $invoice_id );
164
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
165
+    $invoice = new WPInv_Invoice($invoice_id);
166 166
 
167
-    return $invoice->get_total( $currency );
167
+    return $invoice->get_total($currency);
168 168
 }
169 169
 
170
-function wpinv_get_date_created( $invoice_id = 0 ) {
171
-    $invoice = new WPInv_Invoice( $invoice_id );
170
+function wpinv_get_date_created($invoice_id = 0) {
171
+    $invoice = new WPInv_Invoice($invoice_id);
172 172
     
173 173
     $date_created   = $invoice->get_created_date();
174
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
174
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
175 175
 
176 176
     return $date_created;
177 177
 }
178 178
 
179
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
180
-    $invoice = new WPInv_Invoice( $invoice_id );
179
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
180
+    $invoice = new WPInv_Invoice($invoice_id);
181 181
     
182
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
182
+    $format         = !empty($format) ? $format : get_option('date_format');
183 183
     $date_completed = $invoice->get_completed_date();
184
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
185
-    if ( $invoice_date == '' ) {
184
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
185
+    if ($invoice_date == '') {
186 186
         $date_created   = $invoice->get_created_date();
187
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
187
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
188 188
     }
189 189
 
190 190
     return $invoice_date;
191 191
 }
192 192
 
193
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
194
-    $invoice = new WPInv_Invoice( $invoice_id );
193
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
194
+    $invoice = new WPInv_Invoice($invoice_id);
195 195
     
196 196
     return $invoice->vat_number;
197 197
 }
198 198
 
199
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
200
-    $invoice = new WPInv_Invoice( $invoice_id );
199
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
200
+    $invoice = new WPInv_Invoice($invoice_id);
201 201
 
202
-    return $invoice->add_note( $note, $user_type, $added_by_user );
202
+    return $invoice->add_note($note, $user_type, $added_by_user);
203 203
 }
204 204
 
205
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
205
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
206 206
     global $invoicing;
207 207
     
208
-    if ( empty( $invoice_id ) ) {
208
+    if (empty($invoice_id)) {
209 209
         return NULL;
210 210
     }
211 211
     
212
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
212
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
213 213
     
214
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
214
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
215 215
 }
216 216
 
217
-function wpinv_get_payment_key( $invoice_id = 0 ) {
218
-	$invoice = new WPInv_Invoice( $invoice_id );
217
+function wpinv_get_payment_key($invoice_id = 0) {
218
+	$invoice = new WPInv_Invoice($invoice_id);
219 219
     return $invoice->get_key();
220 220
 }
221 221
 
222
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
223
-    $invoice = new WPInv_Invoice( $invoice_id );
222
+function wpinv_get_invoice_number($invoice_id = 0) {
223
+    $invoice = new WPInv_Invoice($invoice_id);
224 224
     return $invoice->get_number();
225 225
 }
226 226
 
227
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
227
+function wpinv_get_cart_discountable_subtotal($code_id) {
228 228
     $cart_items = wpinv_get_cart_content_details();
229 229
     $items      = array();
230 230
 
231
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
231
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
232 232
 
233
-    if( $cart_items ) {
233
+    if ($cart_items) {
234 234
 
235
-        foreach( $cart_items as $item ) {
235
+        foreach ($cart_items as $item) {
236 236
 
237
-            if( ! in_array( $item['id'], $excluded_items ) ) {
238
-                $items[] =  $item;
237
+            if (!in_array($item['id'], $excluded_items)) {
238
+                $items[] = $item;
239 239
             }
240 240
         }
241 241
     }
242 242
 
243
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
243
+    $subtotal = wpinv_get_cart_items_subtotal($items);
244 244
 
245
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
245
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
246 246
 }
247 247
 
248
-function wpinv_get_cart_items_subtotal( $items ) {
248
+function wpinv_get_cart_items_subtotal($items) {
249 249
     $subtotal = 0.00;
250 250
 
251
-    if ( is_array( $items ) && ! empty( $items ) ) {
252
-        $prices = wp_list_pluck( $items, 'subtotal' );
251
+    if (is_array($items) && !empty($items)) {
252
+        $prices = wp_list_pluck($items, 'subtotal');
253 253
 
254
-        if( is_array( $prices ) ) {
255
-            $subtotal = array_sum( $prices );
254
+        if (is_array($prices)) {
255
+            $subtotal = array_sum($prices);
256 256
         } else {
257 257
             $subtotal = 0.00;
258 258
         }
259 259
 
260
-        if( $subtotal < 0 ) {
260
+        if ($subtotal < 0) {
261 261
             $subtotal = 0.00;
262 262
         }
263 263
     }
264 264
 
265
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
265
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
266 266
 }
267 267
 
268
-function wpinv_get_cart_subtotal( $items = array() ) {
269
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
270
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
268
+function wpinv_get_cart_subtotal($items = array()) {
269
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
270
+    $subtotal = wpinv_get_cart_items_subtotal($items);
271 271
 
272
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
272
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
273 273
 }
274 274
 
275
-function wpinv_cart_subtotal( $items = array() ) {
276
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
275
+function wpinv_cart_subtotal($items = array()) {
276
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
277 277
 
278 278
     // Todo - Show tax labels here (if needed)
279 279
 
280 280
     return $price;
281 281
 }
282 282
 
283
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
284
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
285
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
286
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
283
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
284
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
285
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
286
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
287 287
     $fees      = (float)wpinv_get_cart_fee_total();
288
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
288
+    if (!empty($invoice) && $invoice->is_free_trial()) {
289 289
         $total = 0;
290 290
     } else {
291
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
291
+        $total = $subtotal - $discounts + $cart_tax + $fees;
292 292
     }
293 293
 
294
-    if ( $total < 0 ) {
294
+    if ($total < 0) {
295 295
         $total = 0.00;
296 296
     }
297 297
     
298
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
298
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
299 299
 
300
-    return wpinv_sanitize_amount( $total );
300
+    return wpinv_sanitize_amount($total);
301 301
 }
302 302
 
303
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
303
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
304 304
     global $cart_total;
305
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
306
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
305
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
306
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
307 307
 
308 308
     // Todo - Show tax labels here (if needed)
309 309
     
310 310
     $cart_total = $total;
311 311
 
312
-    if ( !$echo ) {
312
+    if (!$echo) {
313 313
         return $total;
314 314
     }
315 315
 
316 316
     echo $total;
317 317
 }
318 318
 
319
-function wpinv_get_cart_tax( $items = array() ) {
319
+function wpinv_get_cart_tax($items = array()) {
320 320
     $cart_tax = 0;
321
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
321
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
322 322
 
323
-    if ( $items ) {
324
-        $taxes = wp_list_pluck( $items, 'tax' );
323
+    if ($items) {
324
+        $taxes = wp_list_pluck($items, 'tax');
325 325
 
326
-        if( is_array( $taxes ) ) {
327
-            $cart_tax = array_sum( $taxes );
326
+        if (is_array($taxes)) {
327
+            $cart_tax = array_sum($taxes);
328 328
         }
329 329
     }
330 330
 
331 331
     $cart_tax += wpinv_get_cart_fee_tax();
332 332
 
333
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
333
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
334 334
 }
335 335
 
336
-function wpinv_cart_tax( $items = array(), $echo = false ) {
337
-    $cart_tax = wpinv_get_cart_tax( $items );
338
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
336
+function wpinv_cart_tax($items = array(), $echo = false) {
337
+    $cart_tax = wpinv_get_cart_tax($items);
338
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
339 339
 
340
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
340
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
341 341
 
342
-    if ( !$echo ) {
342
+    if (!$echo) {
343 343
         return $tax;
344 344
     }
345 345
 
346 346
     echo $tax;
347 347
 }
348 348
 
349
-function wpinv_get_cart_discount_code( $items = array() ) {
349
+function wpinv_get_cart_discount_code($items = array()) {
350 350
     $invoice = wpinv_get_invoice_cart();
351
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
351
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
352 352
     
353
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
353
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
354 354
 }
355 355
 
356
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
357
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
356
+function wpinv_cart_discount_code($items = array(), $echo = false) {
357
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
358 358
 
359
-    if ( $cart_discount_code != '' ) {
359
+    if ($cart_discount_code != '') {
360 360
         $cart_discount_code = ' (' . $cart_discount_code . ')';
361 361
     }
362 362
     
363
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
363
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
364 364
 
365
-    if ( !$echo ) {
365
+    if (!$echo) {
366 366
         return $discount_code;
367 367
     }
368 368
 
369 369
     echo $discount_code;
370 370
 }
371 371
 
372
-function wpinv_get_cart_discount( $items = array() ) {
372
+function wpinv_get_cart_discount($items = array()) {
373 373
     $invoice = wpinv_get_invoice_cart();
374
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
374
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
375 375
     
376
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
376
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
377 377
 }
378 378
 
379
-function wpinv_cart_discount( $items = array(), $echo = false ) {
380
-    $cart_discount = wpinv_get_cart_discount( $items );
381
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
379
+function wpinv_cart_discount($items = array(), $echo = false) {
380
+    $cart_discount = wpinv_get_cart_discount($items);
381
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
382 382
 
383
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
383
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
384 384
 
385
-    if ( !$echo ) {
385
+    if (!$echo) {
386 386
         return $discount;
387 387
     }
388 388
 
389 389
     echo $discount;
390 390
 }
391 391
 
392
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
393
-    $item = new WPInv_Item( $item_id );
392
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
393
+    $item = new WPInv_Item($item_id);
394 394
     
395
-    return $item->get_fees( $type, $item_id );
395
+    return $item->get_fees($type, $item_id);
396 396
 }
397 397
 
398 398
 function wpinv_get_cart_fee_total() {
399
-    $total  = 0;
399
+    $total = 0;
400 400
     $fees = wpinv_get_cart_fees();
401 401
     
402
-    if ( $fees ) {
403
-        foreach ( $fees as $fee_id => $fee ) {
402
+    if ($fees) {
403
+        foreach ($fees as $fee_id => $fee) {
404 404
             $total += $fee['amount'];
405 405
         }
406 406
     }
407 407
 
408
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
408
+    return apply_filters('wpinv_get_cart_fee_total', $total);
409 409
 }
410 410
 
411 411
 function wpinv_get_cart_fee_tax() {
412 412
     $tax  = 0;
413 413
     $fees = wpinv_get_cart_fees();
414 414
 
415
-    if ( $fees ) {
416
-        foreach ( $fees as $fee_id => $fee ) {
417
-            if( ! empty( $fee['no_tax'] ) ) {
415
+    if ($fees) {
416
+        foreach ($fees as $fee_id => $fee) {
417
+            if (!empty($fee['no_tax'])) {
418 418
                 continue;
419 419
             }
420 420
 
421
-            $tax += wpinv_calculate_tax( $fee['amount'] );
421
+            $tax += wpinv_calculate_tax($fee['amount']);
422 422
         }
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
425
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
426 426
 }
427 427
 
428 428
 function wpinv_cart_has_recurring_item() {
429 429
     $cart_items = wpinv_get_cart_contents();
430 430
     
431
-    if ( empty( $cart_items ) ) {
431
+    if (empty($cart_items)) {
432 432
         return false;
433 433
     }
434 434
     
435 435
     $has_subscription = false;
436
-    foreach( $cart_items as $cart_item ) {
437
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
436
+    foreach ($cart_items as $cart_item) {
437
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
438 438
             $has_subscription = true;
439 439
             break;
440 440
         }
441 441
     }
442 442
     
443
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
443
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
444 444
 }
445 445
 
446 446
 function wpinv_cart_has_free_trial() {
@@ -448,85 +448,85 @@  discard block
 block discarded – undo
448 448
     
449 449
     $free_trial = false;
450 450
     
451
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
451
+    if (!empty($invoice) && $invoice->is_free_trial()) {
452 452
         $free_trial = true;
453 453
     }
454 454
     
455
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
455
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
456 456
 }
457 457
 
458 458
 function wpinv_get_cart_contents() {
459 459
     $cart_details = wpinv_get_cart_details();
460 460
     
461
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
461
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
462 462
 }
463 463
 
464 464
 function wpinv_get_cart_content_details() {
465 465
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
466 466
     $cart_items = wpinv_get_cart_contents();
467 467
     
468
-    if ( empty( $cart_items ) ) {
468
+    if (empty($cart_items)) {
469 469
         return false;
470 470
     }
471 471
     $invoice = wpinv_get_invoice_cart();
472 472
 
473 473
     $details = array();
474
-    $length  = count( $cart_items ) - 1;
474
+    $length  = count($cart_items) - 1;
475 475
     
476
-    if ( empty( $_POST['country'] ) ) {
476
+    if (empty($_POST['country'])) {
477 477
         $_POST['country'] = $invoice->country;
478 478
     }
479
-    if ( !isset( $_POST['state'] ) ) {
479
+    if (!isset($_POST['state'])) {
480 480
         $_POST['state'] = $invoice->state;
481 481
     }
482 482
 
483
-    foreach( $cart_items as $key => $item ) {
484
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
485
-        if ( empty( $item_id ) ) {
483
+    foreach ($cart_items as $key => $item) {
484
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
485
+        if (empty($item_id)) {
486 486
             continue;
487 487
         }
488 488
         
489 489
         $wpi_current_id         = $invoice->ID;
490 490
         $wpi_item_id            = $item_id;
491 491
         
492
-        $item_price         = wpinv_get_item_price( $item_id );
493
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
494
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
495
-        $quantity           = wpinv_get_cart_item_quantity( $item );
496
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
492
+        $item_price         = wpinv_get_item_price($item_id);
493
+        $discount           = wpinv_get_cart_item_discount_amount($item);
494
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
495
+        $quantity           = wpinv_get_cart_item_quantity($item);
496
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
497 497
         
498 498
         $subtotal           = $item_price * $quantity;
499
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
500
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
501
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
499
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
500
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
501
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
502 502
         
503
-        if ( wpinv_prices_include_tax() ) {
504
-            $subtotal -= wpinv_format_amount( $tax, NULL, true );
503
+        if (wpinv_prices_include_tax()) {
504
+            $subtotal -= wpinv_format_amount($tax, NULL, true);
505 505
         }
506 506
         
507
-        $total              = $subtotal - $discount + $tax;
507
+        $total = $subtotal - $discount + $tax;
508 508
         
509 509
         // Do not allow totals to go negatve
510
-        if( $total < 0 ) {
510
+        if ($total < 0) {
511 511
             $total = 0;
512 512
         }
513 513
         
514
-        $details[ $key ]  = array(
514
+        $details[$key] = array(
515 515
             'id'                => $item_id,
516
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
517
-            'item_price'        => wpinv_format_amount( $item_price, NULL, true ),
516
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
517
+            'item_price'        => wpinv_format_amount($item_price, NULL, true),
518 518
             'quantity'          => $quantity,
519
-            'discount'          => wpinv_format_amount( $discount, NULL, true ),
520
-            'subtotal'          => wpinv_format_amount( $subtotal, NULL, true ),
521
-            'tax'               => wpinv_format_amount( $tax, NULL, true ),
522
-            'price'             => wpinv_format_amount( $total, NULL, true ),
519
+            'discount'          => wpinv_format_amount($discount, NULL, true),
520
+            'subtotal'          => wpinv_format_amount($subtotal, NULL, true),
521
+            'tax'               => wpinv_format_amount($tax, NULL, true),
522
+            'price'             => wpinv_format_amount($total, NULL, true),
523 523
             'vat_rates_class'   => $tax_class,
524
-            'vat_rate'          => wpinv_format_amount( $tax_rate, NULL, true ),
525
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
524
+            'vat_rate'          => wpinv_format_amount($tax_rate, NULL, true),
525
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
526 526
             'fees'              => $fees,
527 527
         );
528 528
         
529
-        if ( $wpinv_is_last_cart_item ) {
529
+        if ($wpinv_is_last_cart_item) {
530 530
             $wpinv_is_last_cart_item   = false;
531 531
             $wpinv_flat_discount_total = 0.00;
532 532
         }
@@ -535,56 +535,56 @@  discard block
 block discarded – undo
535 535
     return $details;
536 536
 }
537 537
 
538
-function wpinv_get_cart_details( $invoice_id = 0 ) {
538
+function wpinv_get_cart_details($invoice_id = 0) {
539 539
     global $ajax_cart_details;
540 540
 
541
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
542
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
541
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
542
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
543 543
 
544 544
     $invoice_currency = $invoice->currency;
545 545
 
546
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
547
-        foreach ( $cart_details as $key => $cart_item ) {
548
-            $cart_details[ $key ]['currency'] = $invoice_currency;
546
+    if (!empty($cart_details) && is_array($cart_details)) {
547
+        foreach ($cart_details as $key => $cart_item) {
548
+            $cart_details[$key]['currency'] = $invoice_currency;
549 549
 
550
-            if ( ! isset( $cart_item['subtotal'] ) ) {
551
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
550
+            if (!isset($cart_item['subtotal'])) {
551
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
552 552
             }
553 553
         }
554 554
     }
555 555
 
556
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
556
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
557 557
 }
558 558
 
559
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
560
-    $invoice    = wpinv_get_invoice( $invoice_id );
559
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
560
+    $invoice    = wpinv_get_invoice($invoice_id);
561 561
     
562
-    $old_status = wpinv_status_nicename( $old_status );
563
-    $new_status = wpinv_status_nicename( $new_status );
562
+    $old_status = wpinv_status_nicename($old_status);
563
+    $new_status = wpinv_status_nicename($new_status);
564 564
 
565
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
565
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
566 566
     
567 567
     // Add note
568
-    return $invoice->add_note( $status_change, 0 );
568
+    return $invoice->add_note($status_change, 0);
569 569
 }
570
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
570
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
571 571
 
572
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
572
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
573 573
     global $wpi_has_free_trial;
574 574
     
575 575
     $wpi_has_free_trial = false;
576 576
     
577
-    if ( $old_status == 'publish' || $old_status == 'complete' ) {
577
+    if ($old_status == 'publish' || $old_status == 'complete') {
578 578
         return; // Make sure that payments are only paid once
579 579
     }
580 580
 
581 581
     // Make sure the payment completion is only processed when new status is paid
582
-    if ( $new_status != 'publish' && $new_status != 'complete' ) {
582
+    if ($new_status != 'publish' && $new_status != 'complete') {
583 583
         return;
584 584
     }
585 585
 
586
-    $invoice = new WPInv_Invoice( $invoice_id );
587
-    if ( empty( $invoice ) ) {
586
+    $invoice = new WPInv_Invoice($invoice_id);
587
+    if (empty($invoice)) {
588 588
         return;
589 589
     }
590 590
 
@@ -592,58 +592,58 @@  discard block
 block discarded – undo
592 592
     $completed_date = $invoice->completed_date;
593 593
     $cart_details   = $invoice->cart_details;
594 594
 
595
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
595
+    do_action('wpinv_pre_complete_payment', $invoice_id);
596 596
 
597
-    if ( is_array( $cart_details ) ) {
597
+    if (is_array($cart_details)) {
598 598
         // Increase purchase count and earnings
599
-        foreach ( $cart_details as $cart_index => $item ) {
599
+        foreach ($cart_details as $cart_index => $item) {
600 600
             // Ensure these actions only run once, ever
601
-            if ( empty( $completed_date ) ) {
602
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
601
+            if (empty($completed_date)) {
602
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
603 603
             }
604 604
         }
605 605
     }
606 606
     
607 607
     // Check for discount codes and increment their use counts
608
-    if ( $discounts = $invoice->get_discounts( true ) ) {
609
-        if( ! empty( $discounts ) ) {
610
-            foreach( $discounts as $code ) {
611
-                wpinv_increase_discount_usage( $code );
608
+    if ($discounts = $invoice->get_discounts(true)) {
609
+        if (!empty($discounts)) {
610
+            foreach ($discounts as $code) {
611
+                wpinv_increase_discount_usage($code);
612 612
             }
613 613
         }
614 614
     }
615 615
     
616 616
     // Ensure this action only runs once ever
617
-    if( empty( $completed_date ) ) {
617
+    if (empty($completed_date)) {
618 618
         // Save the completed date
619
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
619
+        $invoice->set('completed_date', current_time('mysql', 0));
620 620
         $invoice->save();
621 621
 
622
-        do_action( 'wpinv_complete_payment', $invoice_id );
622
+        do_action('wpinv_complete_payment', $invoice_id);
623 623
     }
624 624
 
625 625
     // Empty the shopping cart
626 626
     wpinv_empty_cart();
627 627
 }
628
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
628
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
629 629
 
630
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
631
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
630
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
631
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
632 632
     
633
-    if ( empty( $invoice ) ) {
633
+    if (empty($invoice)) {
634 634
         return false;
635 635
     }
636 636
     
637
-    return $invoice->update_status( $new_status );
637
+    return $invoice->update_status($new_status);
638 638
 }
639 639
 
640
-function wpinv_cart_has_fees( $type = 'all' ) {
640
+function wpinv_cart_has_fees($type = 'all') {
641 641
     return false;
642 642
 }
643 643
 
644 644
 function wpinv_validate_checkout_fields() {    
645 645
     // Check if there is $_POST
646
-    if ( empty( $_POST ) ) {
646
+    if (empty($_POST)) {
647 647
         return false;
648 648
     }
649 649
     
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
     );
656 656
     
657 657
     // Validate agree to terms
658
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
658
+    if (wpinv_get_option('show_agree_to_terms', false)) {
659 659
         wpinv_checkout_validate_agree_to_terms();
660 660
     }
661 661
     
662
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
662
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
663 663
     
664 664
     // Return collected data
665 665
     return $valid_data;
@@ -671,20 +671,20 @@  discard block
 block discarded – undo
671 671
     $has_subscription = wpinv_cart_has_recurring_item();
672 672
 
673 673
     // Check if a gateway value is present
674
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
675
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
674
+    if (!empty($_REQUEST['wpi-gateway'])) {
675
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
676 676
 
677
-        if ( '0.00' == wpinv_get_cart_total() ) {
677
+        if ('0.00' == wpinv_get_cart_total()) {
678 678
             $gateway = 'manual';
679
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
680
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
681
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
682
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
679
+        } elseif (!wpinv_is_gateway_active($gateway)) {
680
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
681
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
682
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
683 683
         }
684 684
     }
685 685
 
686
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
687
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
686
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
687
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
688 688
     }
689 689
 
690 690
     return $gateway;
@@ -696,10 +696,10 @@  discard block
 block discarded – undo
696 696
     
697 697
     $error = false;
698 698
     // If we have discounts, loop through them
699
-    if ( ! empty( $discounts ) ) {
700
-        foreach ( $discounts as $discount ) {
699
+    if (!empty($discounts)) {
700
+        foreach ($discounts as $discount) {
701 701
             // Check if valid
702
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
702
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
703 703
                 // Discount is not valid
704 704
                 $error = true;
705 705
             }
@@ -709,20 +709,20 @@  discard block
 block discarded – undo
709 709
         return NULL;
710 710
     }
711 711
 
712
-    if ( $error && !wpinv_get_errors() ) {
713
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
712
+    if ($error && !wpinv_get_errors()) {
713
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
714 714
     }
715 715
 
716
-    return implode( ',', $discounts );
716
+    return implode(',', $discounts);
717 717
 }
718 718
 
719 719
 function wpinv_checkout_validate_cc() {
720 720
     $card_data = wpinv_checkout_get_cc_info();
721 721
 
722 722
     // Validate the card zip
723
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
724
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
725
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
723
+    if (!empty($card_data['wpinv_zip'])) {
724
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
725
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
726 726
         }
727 727
     }
728 728
 
@@ -732,28 +732,28 @@  discard block
 block discarded – undo
732 732
 
733 733
 function wpinv_checkout_get_cc_info() {
734 734
 	$cc_info = array();
735
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
736
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
737
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
738
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
739
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
740
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
741
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
742
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
743
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
744
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
735
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
736
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
737
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
738
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
739
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
740
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
741
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
742
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
743
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
744
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
745 745
 
746 746
 	// Return cc info
747 747
 	return $cc_info;
748 748
 }
749 749
 
750
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
750
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
751 751
     $ret = false;
752 752
 
753
-    if ( empty( $zip ) || empty( $country_code ) )
753
+    if (empty($zip) || empty($country_code))
754 754
         return $ret;
755 755
 
756
-    $country_code = strtoupper( $country_code );
756
+    $country_code = strtoupper($country_code);
757 757
 
758 758
     $zip_regex = array(
759 759
         "AD" => "AD\d{3}",
@@ -913,17 +913,17 @@  discard block
 block discarded – undo
913 913
         "ZM" => "\d{5}"
914 914
     );
915 915
 
916
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
916
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
917 917
         $ret = true;
918 918
 
919
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
919
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
920 920
 }
921 921
 
922 922
 function wpinv_checkout_validate_agree_to_terms() {
923 923
     // Validate agree to terms
924
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
924
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
925 925
         // User did not agree
926
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
926
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
927 927
     }
928 928
 }
929 929
 
@@ -936,36 +936,36 @@  discard block
 block discarded – undo
936 936
     );
937 937
     
938 938
     // Verify there is a user_ID
939
-    if ( $user_ID > 0 ) {
939
+    if ($user_ID > 0) {
940 940
         // Get the logged in user data
941
-        $user_data = get_userdata( $user_ID );
942
-        $required_fields  = wpinv_checkout_required_fields();
941
+        $user_data = get_userdata($user_ID);
942
+        $required_fields = wpinv_checkout_required_fields();
943 943
 
944 944
         // Loop through required fields and show error messages
945
-         if ( !empty( $required_fields ) ) {
946
-            foreach ( $required_fields as $field_name => $value ) {
947
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
948
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
945
+         if (!empty($required_fields)) {
946
+            foreach ($required_fields as $field_name => $value) {
947
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
948
+                    wpinv_set_error($value['error_id'], $value['error_message']);
949 949
                 }
950 950
             }
951 951
         }
952 952
 
953 953
         // Verify data
954
-        if ( $user_data ) {
954
+        if ($user_data) {
955 955
             // Collected logged in user data
956 956
             $valid_user_data = array(
957 957
                 'user_id'     => $user_ID,
958
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
959
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
960
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
958
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
959
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
960
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
961 961
             );
962 962
 
963
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
964
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
963
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
964
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
965 965
             }
966 966
         } else {
967 967
             // Set invalid user error
968
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
968
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
969 969
         }
970 970
     }
971 971
 
@@ -973,21 +973,21 @@  discard block
 block discarded – undo
973 973
     return $valid_user_data;
974 974
 }
975 975
 
976
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
976
+function wpinv_checkout_form_get_user($valid_data = array()) {
977 977
     // Initialize user
978 978
     $user    = false;
979
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
979
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
980 980
 
981 981
     /*if ( $is_ajax ) {
982 982
         // Do not create or login the user during the ajax submission (check for errors only)
983 983
         return true;
984
-    } else */if ( is_user_logged_in() ) {
984
+    } else */if (is_user_logged_in()) {
985 985
         // Set the valid user as the logged in collected data
986 986
         $user = $valid_data['logged_in_user'];
987 987
     }
988 988
 
989 989
     // Verify we have an user
990
-    if ( false === $user || empty( $user ) ) {
990
+    if (false === $user || empty($user)) {
991 991
         // Return false
992 992
         return false;
993 993
     }
@@ -1006,11 +1006,11 @@  discard block
 block discarded – undo
1006 1006
         'zip',
1007 1007
     );
1008 1008
     
1009
-    foreach ( $address_fields as $field ) {
1010
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1009
+    foreach ($address_fields as $field) {
1010
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1011 1011
         
1012
-        if ( !empty( $user['user_id'] ) ) {
1013
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1012
+        if (!empty($user['user_id'])) {
1013
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1014 1014
         }
1015 1015
     }
1016 1016
 
@@ -1018,28 +1018,28 @@  discard block
 block discarded – undo
1018 1018
     return $user;
1019 1019
 }
1020 1020
 
1021
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1021
+function wpinv_set_checkout_session($invoice_data = array()) {
1022 1022
     global $wpi_session;
1023 1023
     
1024
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1024
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1025 1025
 }
1026 1026
 
1027 1027
 function wpinv_get_checkout_session() {
1028 1028
 	global $wpi_session;
1029 1029
     
1030
-    return $wpi_session->get( 'wpinv_checkout' );
1030
+    return $wpi_session->get('wpinv_checkout');
1031 1031
 }
1032 1032
 
1033 1033
 function wpinv_empty_cart() {
1034 1034
     global $wpi_session;
1035 1035
 
1036 1036
     // Remove cart contents
1037
-    $wpi_session->set( 'wpinv_checkout', NULL );
1037
+    $wpi_session->set('wpinv_checkout', NULL);
1038 1038
 
1039 1039
     // Remove all cart fees
1040
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1040
+    $wpi_session->set('wpi_cart_fees', NULL);
1041 1041
 
1042
-    do_action( 'wpinv_empty_cart' );
1042
+    do_action('wpinv_empty_cart');
1043 1043
 }
1044 1044
 
1045 1045
 function wpinv_process_checkout() {
@@ -1051,42 +1051,42 @@  discard block
 block discarded – undo
1051 1051
     
1052 1052
     $wpi_checkout_id = $invoice->ID;
1053 1053
     
1054
-    do_action( 'wpinv_pre_process_checkout' );
1054
+    do_action('wpinv_pre_process_checkout');
1055 1055
     
1056
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1056
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1057 1057
         $valid_data = false;
1058
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1058
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1059 1059
     } else {
1060 1060
         // Validate the form $_POST data
1061 1061
         $valid_data = wpinv_validate_checkout_fields();
1062 1062
         
1063 1063
         // Allow themes and plugins to hook to errors
1064
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1064
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1065 1065
     }
1066 1066
     
1067
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1067
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1068 1068
     
1069 1069
     // Validate the user
1070
-    $user = wpinv_checkout_form_get_user( $valid_data );
1070
+    $user = wpinv_checkout_form_get_user($valid_data);
1071 1071
 
1072 1072
     // Let extensions validate fields after user is logged in if user has used login/registration form
1073
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1073
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1074 1074
     
1075
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1076
-        if ( $is_ajax ) {
1077
-            do_action( 'wpinv_ajax_checkout_errors' );
1075
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1076
+        if ($is_ajax) {
1077
+            do_action('wpinv_ajax_checkout_errors');
1078 1078
             die();
1079 1079
         } else {
1080 1080
             return false;
1081 1081
         }
1082 1082
     }
1083 1083
 
1084
-    if ( $is_ajax ) {
1084
+    if ($is_ajax) {
1085 1085
         // Save address fields.
1086
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1087
-        foreach ( $address_fields as $field ) {
1088
-            if ( isset( $user[$field] ) ) {
1089
-                $invoice->set( $field, $user[$field] );
1086
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1087
+        foreach ($address_fields as $field) {
1088
+            if (isset($user[$field])) {
1089
+                $invoice->set($field, $user[$field]);
1090 1090
             }
1091 1091
             
1092 1092
             $invoice->save();
@@ -1094,15 +1094,15 @@  discard block
 block discarded – undo
1094 1094
 
1095 1095
         $response['success']            = true;
1096 1096
         $response['data']['subtotal']   = $invoice->get_subtotal();
1097
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1097
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1098 1098
         $response['data']['discount']   = $invoice->get_discount();
1099
-        $response['data']['discountf']  = $invoice->get_discount( true );
1099
+        $response['data']['discountf']  = $invoice->get_discount(true);
1100 1100
         $response['data']['tax']        = $invoice->get_tax();
1101
-        $response['data']['taxf']       = $invoice->get_tax( true );
1101
+        $response['data']['taxf']       = $invoice->get_tax(true);
1102 1102
         $response['data']['total']      = $invoice->get_total();
1103
-        $response['data']['totalf']     = $invoice->get_total( true );
1103
+        $response['data']['totalf']     = $invoice->get_total(true);
1104 1104
         
1105
-        wp_send_json( $response );
1105
+        wp_send_json($response);
1106 1106
     }
1107 1107
     
1108 1108
     $user_info = array(
@@ -1124,42 +1124,42 @@  discard block
 block discarded – undo
1124 1124
     
1125 1125
     // Setup invoice information
1126 1126
     $invoice_data = array(
1127
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1127
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1128 1128
         'items'             => $cart_items,
1129 1129
         'cart_discounts'    => $discounts,
1130
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1131
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1132
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1133
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1134
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1130
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1131
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1132
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1133
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1134
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1135 1135
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1136 1136
         'user_email'        => $user['email'],
1137
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1138
-        'user_info'         => stripslashes_deep( $user_info ),
1137
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1138
+        'user_info'         => stripslashes_deep($user_info),
1139 1139
         'post_data'         => $_POST,
1140 1140
         'cart_details'      => $cart_items,
1141 1141
         'gateway'           => $valid_data['gateway'],
1142 1142
         'card_info'         => $valid_data['cc_info']
1143 1143
     );
1144 1144
     
1145
-    $vat_info   = $wpinv_euvat->current_vat_data();
1146
-    if ( is_array( $vat_info ) ) {
1145
+    $vat_info = $wpinv_euvat->current_vat_data();
1146
+    if (is_array($vat_info)) {
1147 1147
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1148 1148
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1149
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1149
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1150 1150
 
1151 1151
         // Add the VAT rate to each item in the cart
1152
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1152
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1153 1153
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1154
-            $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 );
1154
+            $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3);
1155 1155
         }
1156 1156
     }
1157 1157
     
1158 1158
     // Save vat fields.
1159
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1160
-    foreach ( $address_fields as $field ) {
1161
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1162
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1159
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1160
+    foreach ($address_fields as $field) {
1161
+        if (isset($invoice_data['user_info'][$field])) {
1162
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1163 1163
         }
1164 1164
         
1165 1165
         $invoice->save();
@@ -1169,49 +1169,49 @@  discard block
 block discarded – undo
1169 1169
     $valid_data['user'] = $user;
1170 1170
     
1171 1171
     // Allow themes and plugins to hook before the gateway
1172
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1172
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1173 1173
     
1174 1174
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1175
-    if ( !$invoice_data['price'] ) {
1175
+    if (!$invoice_data['price']) {
1176 1176
         // Revert to manual
1177 1177
         $invoice_data['gateway'] = 'manual';
1178 1178
         $_POST['wpi-gateway'] = 'manual';
1179 1179
     }
1180 1180
     
1181 1181
     // Allow the invoice data to be modified before it is sent to the gateway
1182
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1182
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1183 1183
     
1184 1184
     // Setup the data we're storing in the purchase session
1185 1185
     $session_data = $invoice_data;
1186 1186
     // Make sure credit card numbers are never stored in sessions
1187
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1188
-        unset( $session_data['card_info']['card_number'] );
1187
+    if (!empty($session_data['card_info']['card_number'])) {
1188
+        unset($session_data['card_info']['card_number']);
1189 1189
     }
1190 1190
     
1191 1191
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1192
-    wpinv_set_checkout_session( $invoice_data );
1192
+    wpinv_set_checkout_session($invoice_data);
1193 1193
     
1194 1194
     // Set gateway
1195
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1196
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1197
-    $invoice->update_meta( '_wpinv_checkout', true );
1195
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1196
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1197
+    $invoice->update_meta('_wpinv_checkout', true);
1198 1198
     
1199
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1199
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1200 1200
 
1201 1201
     // Send info to the gateway for payment processing
1202
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1202
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1203 1203
     die();
1204 1204
 }
1205
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1205
+add_action('wpinv_payment', 'wpinv_process_checkout');
1206 1206
 
1207
-function wpinv_get_invoices( $args ) {
1208
-    $args = wp_parse_args( $args, array(
1209
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1207
+function wpinv_get_invoices($args) {
1208
+    $args = wp_parse_args($args, array(
1209
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1210 1210
         'type'     => 'wpi_invoice',
1211 1211
         'parent'   => null,
1212 1212
         'user'     => null,
1213 1213
         'email'    => '',
1214
-        'limit'    => get_option( 'posts_per_page' ),
1214
+        'limit'    => get_option('posts_per_page'),
1215 1215
         'offset'   => null,
1216 1216
         'page'     => 1,
1217 1217
         'exclude'  => array(),
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
         'order'    => 'DESC',
1220 1220
         'return'   => 'objects',
1221 1221
         'paginate' => false,
1222
-    ) );
1222
+    ));
1223 1223
     
1224 1224
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1225 1225
     $map_legacy = array(
@@ -1232,18 +1232,18 @@  discard block
 block discarded – undo
1232 1232
         'paged'          => 'page',
1233 1233
     );
1234 1234
 
1235
-    foreach ( $map_legacy as $from => $to ) {
1236
-        if ( isset( $args[ $from ] ) ) {
1237
-            $args[ $to ] = $args[ $from ];
1235
+    foreach ($map_legacy as $from => $to) {
1236
+        if (isset($args[$from])) {
1237
+            $args[$to] = $args[$from];
1238 1238
         }
1239 1239
     }
1240 1240
     
1241
-    if ( get_query_var( 'paged' ) )
1241
+    if (get_query_var('paged'))
1242 1242
         $args['page'] = get_query_var('paged');
1243
-    else if ( get_query_var( 'page' ) )
1244
-        $args['page'] = get_query_var( 'page' );
1245
-    else if ( !empty( $args[ 'page' ] ) )
1246
-        $args['page'] = $args[ 'page' ];
1243
+    else if (get_query_var('page'))
1244
+        $args['page'] = get_query_var('page');
1245
+    else if (!empty($args['page']))
1246
+        $args['page'] = $args['page'];
1247 1247
     else
1248 1248
         $args['page'] = 1;
1249 1249
 
@@ -1256,47 +1256,47 @@  discard block
 block discarded – undo
1256 1256
         'post_status'    => $args['status'],
1257 1257
         'posts_per_page' => $args['limit'],
1258 1258
         'meta_query'     => array(),
1259
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1259
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1260 1260
         'fields'         => 'ids',
1261 1261
         'orderby'        => $args['orderby'],
1262 1262
         'order'          => $args['order'],
1263 1263
     );
1264 1264
     
1265
-    if ( !empty( $args['user'] ) ) {
1266
-        $wp_query_args['author'] = absint( $args['user'] );
1265
+    if (!empty($args['user'])) {
1266
+        $wp_query_args['author'] = absint($args['user']);
1267 1267
     }
1268 1268
 
1269
-    if ( ! is_null( $args['parent'] ) ) {
1270
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1269
+    if (!is_null($args['parent'])) {
1270
+        $wp_query_args['post_parent'] = absint($args['parent']);
1271 1271
     }
1272 1272
 
1273
-    if ( ! is_null( $args['offset'] ) ) {
1274
-        $wp_query_args['offset'] = absint( $args['offset'] );
1273
+    if (!is_null($args['offset'])) {
1274
+        $wp_query_args['offset'] = absint($args['offset']);
1275 1275
     } else {
1276
-        $wp_query_args['paged'] = absint( $args['page'] );
1276
+        $wp_query_args['paged'] = absint($args['page']);
1277 1277
     }
1278 1278
 
1279
-    if ( ! empty( $args['exclude'] ) ) {
1280
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1279
+    if (!empty($args['exclude'])) {
1280
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1281 1281
     }
1282 1282
 
1283
-    if ( ! $args['paginate' ] ) {
1283
+    if (!$args['paginate']) {
1284 1284
         $wp_query_args['no_found_rows'] = true;
1285 1285
     }
1286 1286
 
1287 1287
     // Get results.
1288
-    $invoices = new WP_Query( $wp_query_args );
1288
+    $invoices = new WP_Query($wp_query_args);
1289 1289
 
1290
-    if ( 'objects' === $args['return'] ) {
1291
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1292
-    } elseif ( 'self' === $args['return'] ) {
1290
+    if ('objects' === $args['return']) {
1291
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1292
+    } elseif ('self' === $args['return']) {
1293 1293
         return $invoices;
1294 1294
     } else {
1295 1295
         $return = $invoices->posts;
1296 1296
     }
1297 1297
 
1298
-    if ( $args['paginate' ] ) {
1299
-        return (object) array(
1298
+    if ($args['paginate']) {
1299
+        return (object)array(
1300 1300
             'invoices'      => $return,
1301 1301
             'total'         => $invoices->found_posts,
1302 1302
             'max_num_pages' => $invoices->max_num_pages,
@@ -1308,21 +1308,21 @@  discard block
 block discarded – undo
1308 1308
 
1309 1309
 function wpinv_get_user_invoices_columns() {
1310 1310
     $columns = array(
1311
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1312
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1313
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1314
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1315
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1311
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1312
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1313
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1314
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1315
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1316 1316
         );
1317 1317
 
1318
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1318
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1319 1319
 }
1320 1320
 
1321
-function wpinv_payment_receipt( $atts, $content = null ) {
1321
+function wpinv_payment_receipt($atts, $content = null) {
1322 1322
     global $wpinv_receipt_args;
1323 1323
 
1324
-    $wpinv_receipt_args = shortcode_atts( array(
1325
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1324
+    $wpinv_receipt_args = shortcode_atts(array(
1325
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1326 1326
         'price'           => true,
1327 1327
         'discount'        => true,
1328 1328
         'items'           => true,
@@ -1331,185 +1331,185 @@  discard block
 block discarded – undo
1331 1331
         'invoice_key'     => false,
1332 1332
         'payment_method'  => true,
1333 1333
         'invoice_id'      => true
1334
-    ), $atts, 'wpinv_receipt' );
1334
+    ), $atts, 'wpinv_receipt');
1335 1335
 
1336 1336
     $session = wpinv_get_checkout_session();
1337
-    if ( isset( $_GET['invoice_key'] ) ) {
1338
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1339
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1337
+    if (isset($_GET['invoice_key'])) {
1338
+        $invoice_key = urldecode($_GET['invoice_key']);
1339
+    } else if ($session && isset($session['invoice_key'])) {
1340 1340
         $invoice_key = $session['invoice_key'];
1341
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1341
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1342 1342
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1343
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1344
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1343
+    } else if (isset($_GET['invoice-id'])) {
1344
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1345 1345
     }
1346 1346
 
1347 1347
     // No key found
1348
-    if ( ! isset( $invoice_key ) ) {
1348
+    if (!isset($invoice_key)) {
1349 1349
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1350 1350
     }
1351 1351
 
1352
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1353
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1354
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1352
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1353
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1354
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1355 1355
         $invoice_id     = (int)$_GET['invoice-id'];
1356
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1356
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1357 1357
     }
1358 1358
 
1359 1359
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1360
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1360
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1361 1361
         // login redirect
1362
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1362
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1363 1363
     }
1364 1364
 
1365
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1365
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1366 1366
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1367 1367
     }
1368 1368
 
1369 1369
     ob_start();
1370 1370
 
1371
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1371
+    wpinv_get_template_part('wpinv-invoice-receipt');
1372 1372
 
1373 1373
     $display = ob_get_clean();
1374 1374
 
1375 1375
     return $display;
1376 1376
 }
1377 1377
 
1378
-function wpinv_get_invoice_id_by_key( $key ) {
1378
+function wpinv_get_invoice_id_by_key($key) {
1379 1379
 	global $wpdb;
1380 1380
 
1381
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1381
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1382 1382
 
1383
-	if ( $invoice_id != NULL )
1383
+	if ($invoice_id != NULL)
1384 1384
 		return $invoice_id;
1385 1385
 
1386 1386
 	return 0;
1387 1387
 }
1388 1388
 
1389
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1389
+function wpinv_can_view_receipt($invoice_key = '') {
1390 1390
 	$return = false;
1391 1391
 
1392
-	if ( empty( $invoice_key ) ) {
1392
+	if (empty($invoice_key)) {
1393 1393
 		return $return;
1394 1394
 	}
1395 1395
 
1396 1396
 	global $wpinv_receipt_args;
1397 1397
 
1398
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1399
-	if ( isset( $_GET['invoice-id'] ) ) {
1400
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1398
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1399
+	if (isset($_GET['invoice-id'])) {
1400
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1401 1401
 	}
1402 1402
 
1403
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1404
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1403
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1404
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1405 1405
 
1406
-	if ( is_user_logged_in() ) {
1407
-		if ( $user_id === (int) get_current_user_id() ) {
1406
+	if (is_user_logged_in()) {
1407
+		if ($user_id === (int)get_current_user_id()) {
1408 1408
 			$return = true;
1409 1409
 		}
1410 1410
 	}
1411 1411
 
1412 1412
 	$session = wpinv_get_checkout_session();
1413
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1414
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1413
+	if (!empty($session) && !is_user_logged_in()) {
1414
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1415 1415
 			$return = true;
1416 1416
 		}
1417 1417
 	}
1418 1418
 
1419
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1419
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1420 1420
 }
1421 1421
 
1422 1422
 function wpinv_pay_for_invoice() {
1423 1423
     global $wpinv_euvat;
1424 1424
     
1425
-    if ( isset( $_GET['invoice_key'] ) ) {
1425
+    if (isset($_GET['invoice_key'])) {
1426 1426
         $checkout_uri   = wpinv_get_checkout_uri();
1427
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1427
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1428 1428
         
1429
-        if ( empty( $invoice_key ) ) {
1430
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1431
-            wp_redirect( $checkout_uri );
1429
+        if (empty($invoice_key)) {
1430
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1431
+            wp_redirect($checkout_uri);
1432 1432
             wpinv_die();
1433 1433
         }
1434 1434
         
1435
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1435
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1436 1436
 
1437
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1438
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1439
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1437
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1438
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1439
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1440 1440
             $invoice_id     = (int)$_GET['invoice-id'];
1441
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1441
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1442 1442
         }
1443 1443
         
1444
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1445
-            if ( $invoice->needs_payment() ) {
1444
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1445
+            if ($invoice->needs_payment()) {
1446 1446
                 $data                   = array();
1447 1447
                 $data['invoice_id']     = $invoice_id;
1448
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1448
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1449 1449
                 
1450
-                wpinv_set_checkout_session( $data );
1450
+                wpinv_set_checkout_session($data);
1451 1451
                 
1452
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1452
+                if (wpinv_get_option('vat_ip_country_default')) {
1453 1453
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1454 1454
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1455 1455
                     
1456
-                    wpinv_recalculate_tax( true );
1456
+                    wpinv_recalculate_tax(true);
1457 1457
                 }
1458 1458
                 
1459 1459
             } else {
1460 1460
                 $checkout_uri = $invoice->get_view_url();
1461 1461
             }
1462 1462
         } else {
1463
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1463
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1464 1464
             
1465
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1465
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1466 1466
         }
1467 1467
         
1468
-        wp_redirect( $checkout_uri );
1468
+        wp_redirect($checkout_uri);
1469 1469
         wpinv_die();
1470 1470
     }
1471 1471
 }
1472
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1472
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1473 1473
 
1474
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1475
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1476
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1474
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1475
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1476
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1477 1477
             $user_id = $invoice->get_user_id();
1478
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1478
+            $secret = sanitize_text_field($_GET['_wpipay']);
1479 1479
             
1480
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1481
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1480
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1481
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1482 1482
                 
1483
-                wpinv_guest_redirect( $redirect_to, $user_id );
1483
+                wpinv_guest_redirect($redirect_to, $user_id);
1484 1484
                 wpinv_die();
1485 1485
             }
1486 1486
         }
1487 1487
     }
1488 1488
 }
1489
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1489
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1490 1490
 
1491
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1492
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1491
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1492
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1493 1493
     
1494
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1494
+    if (empty($invoice_id) && $invoice_id > 0) {
1495 1495
         return false;
1496 1496
     }
1497 1497
     
1498
-    if ( empty( $transaction_id ) ) {
1498
+    if (empty($transaction_id)) {
1499 1499
         $transaction_id = $invoice_id;
1500 1500
     }
1501 1501
 
1502
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1502
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1503 1503
     
1504
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1504
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1505 1505
 }
1506 1506
 
1507
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1508
-    if ( empty( $status_display ) ) {
1509
-        $status_display = wpinv_status_nicename( $status );
1507
+function wpinv_invoice_status_label($status, $status_display = '') {
1508
+    if (empty($status_display)) {
1509
+        $status_display = wpinv_status_nicename($status);
1510 1510
     }
1511 1511
     
1512
-    switch ( $status ) {
1512
+    switch ($status) {
1513 1513
         case 'publish' :
1514 1514
         case 'complete' :
1515 1515
         case 'renewal' :
@@ -1535,28 +1535,28 @@  discard block
 block discarded – undo
1535 1535
     
1536 1536
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1537 1537
     
1538
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1538
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1539 1539
 }
1540 1540
 
1541
-function wpinv_format_invoice_number( $number ) {
1542
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1541
+function wpinv_format_invoice_number($number) {
1542
+    $padd = wpinv_get_option('invoice_number_padd');
1543 1543
     
1544 1544
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1545
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1546
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1545
+    if ($padd === '' || $padd === false || $padd === NULL) {
1546
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1547 1547
     }
1548 1548
     
1549
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1550
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1549
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1550
+    $postfix = wpinv_get_option('invoice_number_postfix');
1551 1551
     
1552
-    $padd = absint( $padd );
1553
-    $formatted_number = absint( $number );
1552
+    $padd = absint($padd);
1553
+    $formatted_number = absint($number);
1554 1554
     
1555
-    if ( $padd > 0 ) {
1556
-        $formatted_number = zeroise( $formatted_number, $padd );
1555
+    if ($padd > 0) {
1556
+        $formatted_number = zeroise($formatted_number, $padd);
1557 1557
     }    
1558 1558
 
1559 1559
     $formatted_number = $prefix . $formatted_number . $postfix;
1560 1560
 
1561
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1561
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1562 1562
 }
1563 1563
\ No newline at end of file
Please login to merge, or discard this patch.
invoicing.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@  discard block
 block discarded – undo
11 11
 */
12 12
 
13 13
 // MUST have WordPress.
14
-if ( !defined( 'WPINC' ) ) {
15
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
14
+if (!defined('WPINC')) {
15
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
16 16
 }
17 17
 
18
-if ( !defined( 'WPINV_VERSION' ) ) {
19
-    define( 'WPINV_VERSION', '0.0.4' );
18
+if (!defined('WPINV_VERSION')) {
19
+    define('WPINV_VERSION', '0.0.4');
20 20
 }
21 21
 
22
-if ( !defined( 'WPINV_PLUGIN_FILE' ) ) {
23
-    define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+if (!defined('WPINV_PLUGIN_FILE')) {
23
+    define('WPINV_PLUGIN_FILE', __FILE__);
24 24
 }
25 25
 
26
-require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php';
26
+require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php';
27 27
 
28 28
 function wpinv_run() {
29 29
     global $invoicing;
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
 /**
41 41
  * Show update plugin admin notification.
42 42
  */
43
-if(is_admin()){
43
+if (is_admin()) {
44 44
     if (!function_exists('ayecode_show_update_plugin_requirement')) {//only load the update file if needed
45 45
         function ayecode_show_update_plugin_requirement() {
46
-            if ( !defined( 'WP_EASY_UPDATES_ACTIVE' ) ) {
46
+            if (!defined('WP_EASY_UPDATES_ACTIVE')) {
47 47
                 ?>
48 48
                 <div class="notice notice-warning is-dismissible">
49 49
                     <p>
50 50
                         <strong>
51 51
                             <?php
52
-                            echo sprintf( __( 'The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory' ), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>' );
52
+                            echo sprintf(__('The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory'), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>');
53 53
                             ?>
54 54
                         </strong>
55 55
                     </p>
@@ -58,6 +58,6 @@  discard block
 block discarded – undo
58 58
             }
59 59
         }
60 60
 
61
-        add_action( 'admin_notices', 'ayecode_show_update_plugin_requirement' );
61
+        add_action('admin_notices', 'ayecode_show_update_plugin_requirement');
62 62
     }
63 63
 }
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
         
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
         
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
     
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
     
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81 81
             <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
@@ -90,97 +90,97 @@  discard block
 block discarded – undo
90 90
     
91 91
     public function export() {
92 92
         $statuses = wpinv_get_invoice_statuses();
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => '',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,130 +188,130 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !current_user_can('manage_options')) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201 201
         $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array(
258
-            'id'   => __( 'ID',   'invoicing' ),
259
-            'date' => __( 'Date', 'invoicing' )
258
+            'id'   => __('ID', 'invoicing'),
259
+            'date' => __('Date', 'invoicing')
260 260
         );
261 261
         
262
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
262
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
263 263
     }
264 264
     
265 265
     protected function get_export_file() {
266 266
         $file = '';
267 267
 
268
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
269
-            $file = $this->wp_filesystem->get_contents( $this->file );
268
+        if ($this->wp_filesystem->exists($this->file)) {
269
+            $file = $this->wp_filesystem->get_contents($this->file);
270 270
         } else {
271
-            $this->wp_filesystem->put_contents( $this->file, '' );
271
+            $this->wp_filesystem->put_contents($this->file, '');
272 272
         }
273 273
 
274 274
         return $file;
275 275
     }
276 276
     
277
-    protected function attach_export_data( $data = '' ) {
278
-        $filedata   = $this->get_export_file();
279
-        $filedata   .= $data;
277
+    protected function attach_export_data($data = '') {
278
+        $filedata = $this->get_export_file();
279
+        $filedata .= $data;
280 280
         
281
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
281
+        $this->wp_filesystem->put_contents($this->file, $filedata);
282 282
 
283
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
         $columns    = $this->get_columns();
285
-        $columns    = empty( $columns ) ? 0 : 1;
285
+        $columns    = empty($columns) ? 0 : 1;
286 286
 
287
-        $this->empty = count( $rows ) == $columns ? true : false;
287
+        $this->empty = count($rows) == $columns ? true : false;
288 288
     }
289 289
     
290 290
     public function print_columns() {
291 291
         $column_data    = '';
292 292
         $columns        = $this->get_columns();
293 293
         $i              = 1;
294
-        foreach( $columns as $key => $column ) {
295
-            $column_data .= '"' . addslashes( $column ) . '"';
296
-            $column_data .= $i == count( $columns ) ? '' : ',';
294
+        foreach ($columns as $key => $column) {
295
+            $column_data .= '"' . addslashes($column) . '"';
296
+            $column_data .= $i == count($columns) ? '' : ',';
297 297
             $i++;
298 298
         }
299 299
         $column_data .= "\r\n";
300 300
 
301
-        $this->attach_export_data( $column_data );
301
+        $this->attach_export_data($column_data);
302 302
 
303 303
         return $column_data;
304 304
     }
305 305
     
306 306
     public function process_export_step() {
307
-        if ( $this->step < 2 ) {
308
-            @unlink( $this->file );
307
+        if ($this->step < 2) {
308
+            @unlink($this->file);
309 309
             $this->print_columns();
310 310
         }
311 311
         
312 312
         $return = $this->print_rows();
313 313
         
314
-        if ( $return ) {
314
+        if ($return) {
315 315
             return true;
316 316
         } else {
317 317
             return false;
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
     
321 321
     public function get_export_status() {
322 322
         $status = 100;
323
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
323
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
324 324
     }
325 325
     
326 326
     public function get_export_data() {
327 327
         $data = array(
328 328
             0 => array(
329 329
                 'id'   => '',
330
-                'data' => date( 'F j, Y' )
330
+                'data' => date('F j, Y')
331 331
             ),
332 332
             1 => array(
333 333
                 'id'   => '',
334
-                'data' => date( 'F j, Y' )
334
+                'data' => date('F j, Y')
335 335
             )
336 336
         );
337 337
 
338
-        $data = apply_filters( 'wpinv_export_get_data', $data );
339
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
338
+        $data = apply_filters('wpinv_export_get_data', $data);
339
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
340 340
 
341 341
         return $data;
342 342
     }
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
         $data       = $this->get_export_data();
347 347
         $columns    = $this->get_columns();
348 348
 
349
-        if ( $data ) {
350
-            foreach ( $data as $row ) {
349
+        if ($data) {
350
+            foreach ($data as $row) {
351 351
                 $i = 1;
352
-                foreach ( $row as $key => $column ) {
353
-                    if ( array_key_exists( $key, $columns ) ) {
354
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
355
-                        $row_data .= $i == count( $columns ) ? '' : ',';
352
+                foreach ($row as $key => $column) {
353
+                    if (array_key_exists($key, $columns)) {
354
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
355
+                        $row_data .= $i == count($columns) ? '' : ',';
356 356
                         $i++;
357 357
                     }
358 358
                 }
359 359
                 $row_data .= "\r\n";
360 360
             }
361 361
 
362
-            $this->attach_export_data( $row_data );
362
+            $this->attach_export_data($row_data);
363 363
 
364 364
             return $row_data;
365 365
         }
@@ -368,46 +368,46 @@  discard block
 block discarded – undo
368 368
     }
369 369
     
370 370
     // Export Invoices.
371
-    public function set_invoices_export( $request ) {
372
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
373
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
374
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publich';
371
+    public function set_invoices_export($request) {
372
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
373
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
374
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publich';
375 375
     }
376 376
     
377
-    public function get_invoices_columns( $columns = array() ) {
377
+    public function get_invoices_columns($columns = array()) {
378 378
         $columns = array(
379
-            'id'            => __( 'ID',   'invoicing' ),
380
-            'number'        => __( 'Number',   'invoicing' ),
381
-            'date'          => __( 'Date', 'invoicing' ),
382
-            'amount'        => __( 'Amount', 'invoicing' ),
383
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
384
-            'status'        => __( 'Status', 'invoicing' ),
385
-            'tax'           => __( 'Tax', 'invoicing' ),
386
-            'discount'      => __( 'Discount', 'invoicing' ),
387
-            'user_id'       => __( 'User ID', 'invoicing' ),
388
-            'email'         => __( 'Email', 'invoicing' ),
389
-            'first_name'    => __( 'First Name', 'invoicing' ),
390
-            'last_name'     => __( 'Last Name', 'invoicing' ),
391
-            'address'       => __( 'Address', 'invoicing' ),
392
-            'city'          => __( 'City', 'invoicing' ),
393
-            'state'         => __( 'State', 'invoicing' ),
394
-            'country'       => __( 'Country', 'invoicing' ),
395
-            'zip'           => __( 'Zipcode', 'invoicing' ),
396
-            'phone'         => __( 'Phone', 'invoicing' ),
397
-            'company'       => __( 'Company', 'invoicing' ),
398
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
399
-            'ip'            => __( 'IP', 'invoicing' ),
400
-            'gateway'       => __( 'Gateway', 'invoicing' ),
401
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
402
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
403
-            'currency'      => __( 'Currency', 'invoicing' ),
404
-            'due_date'      => __( 'Due Date', 'invoicing' ),
379
+            'id'            => __('ID', 'invoicing'),
380
+            'number'        => __('Number', 'invoicing'),
381
+            'date'          => __('Date', 'invoicing'),
382
+            'amount'        => __('Amount', 'invoicing'),
383
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
384
+            'status'        => __('Status', 'invoicing'),
385
+            'tax'           => __('Tax', 'invoicing'),
386
+            'discount'      => __('Discount', 'invoicing'),
387
+            'user_id'       => __('User ID', 'invoicing'),
388
+            'email'         => __('Email', 'invoicing'),
389
+            'first_name'    => __('First Name', 'invoicing'),
390
+            'last_name'     => __('Last Name', 'invoicing'),
391
+            'address'       => __('Address', 'invoicing'),
392
+            'city'          => __('City', 'invoicing'),
393
+            'state'         => __('State', 'invoicing'),
394
+            'country'       => __('Country', 'invoicing'),
395
+            'zip'           => __('Zipcode', 'invoicing'),
396
+            'phone'         => __('Phone', 'invoicing'),
397
+            'company'       => __('Company', 'invoicing'),
398
+            'vat_number'    => __('Vat Number', 'invoicing'),
399
+            'ip'            => __('IP', 'invoicing'),
400
+            'gateway'       => __('Gateway', 'invoicing'),
401
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
402
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
403
+            'currency'      => __('Currency', 'invoicing'),
404
+            'due_date'      => __('Due Date', 'invoicing'),
405 405
         );
406 406
 
407 407
         return $columns;
408 408
     }
409 409
         
410
-    public function get_invoices_data( $response = array() ) {
410
+    public function get_invoices_data($response = array()) {
411 411
         $args = array(
412 412
             'limit'    => $this->per_page,
413 413
             'page'     => $this->step,
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
             'orderby'  => 'date',
416 416
         );
417 417
         
418
-        if ( $this->status != 'any' ) {
418
+        if ($this->status != 'any') {
419 419
             $args['status'] = $this->status;
420 420
         }
421 421
 
422
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
422
+        if (!empty($this->from_date) || !empty($this->to_date)) {
423 423
             $args['date_query'] = array(
424 424
                 array(
425
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
426
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
425
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
426
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
427 427
                     'inclusive' => true
428 428
                 )
429 429
             );
430 430
         }
431 431
 
432
-        $invoices = wpinv_get_invoices( $args );
432
+        $invoices = wpinv_get_invoices($args);
433 433
         
434 434
         $data = array();
435 435
         
436
-        if ( !empty( $invoices ) ) {
437
-            foreach ( $invoices as $invoice ) {
436
+        if (!empty($invoices)) {
437
+            foreach ($invoices as $invoice) {
438 438
                 $row = array(
439 439
                     'id'            => $invoice->ID,
440 440
                     'number'        => $invoice->get_number(),
441
-                    'date'          => $invoice->get_invoice_date( false ),
442
-                    'amount'        => wpinv_format_amount( $invoice->get_total(), NULL, true ),
443
-                    'status_nicename' => $invoice->get_status( true ),
441
+                    'date'          => $invoice->get_invoice_date(false),
442
+                    'amount'        => wpinv_format_amount($invoice->get_total(), NULL, true),
443
+                    'status_nicename' => $invoice->get_status(true),
444 444
                     'status'        => $invoice->get_status(),
445
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_format_amount( $invoice->get_tax(), NULL, true ) : '',
446
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_format_amount( $invoice->get_discount(), NULL, true ) : '',
445
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_format_amount($invoice->get_tax(), NULL, true) : '',
446
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_format_amount($invoice->get_discount(), NULL, true) : '',
447 447
                     'user_id'       => $invoice->get_user_id(),
448 448
                     'email'         => $invoice->get_email(),
449 449
                     'first_name'    => $invoice->get_first_name(),
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                     'due_date'      => $invoice->needs_payment() ? $invoice->get_due_date() : '',
465 465
                 );
466 466
                 
467
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
467
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
468 468
             }
469 469
 
470 470
             return $data;
@@ -480,29 +480,29 @@  discard block
 block discarded – undo
480 480
             'return'   => 'ids',
481 481
         );
482 482
         
483
-        if ( $this->status != 'any' ) {
483
+        if ($this->status != 'any') {
484 484
             $args['status'] = $this->status;
485 485
         }
486 486
 
487
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
487
+        if (!empty($this->from_date) || !empty($this->to_date)) {
488 488
             $args['date_query'] = array(
489 489
                 array(
490
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
491
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
490
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
491
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
492 492
                     'inclusive' => true
493 493
                 )
494 494
             );
495 495
         }
496 496
 
497
-        $invoices   = wpinv_get_invoices( $args );
498
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
497
+        $invoices   = wpinv_get_invoices($args);
498
+        $total      = !empty($invoices) ? count($invoices) : 0;
499 499
         $status     = 100;
500 500
 
501
-        if ( $total > 0 ) {
502
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
501
+        if ($total > 0) {
502
+            $status = (($this->per_page * $this->step) / $total) * 100;
503 503
         }
504 504
 
505
-        if ( $status > 100 ) {
505
+        if ($status > 100) {
506 506
             $status = 100;
507 507
         }
508 508
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( current_user_can( 'manage_options' ) ) {
12
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
11
+    if (current_user_can('manage_options')) {
12
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
13 13
     }
14 14
     
15
-    $wpi_invoice            = get_post_type_object( 'wpi_invoice' );
15
+    $wpi_invoice = get_post_type_object('wpi_invoice');
16 16
 
17
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
17
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
18 18
     
19
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), 'manage_options', 'wpinv-settings', 'wpinv_options_page' );
19
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), 'manage_options', 'wpinv-settings', 'wpinv_options_page');
20 20
 }
21 21
 
22
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
22
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
23 23
 function wpinv_remove_admin_submenus() {
24
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
24
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
25 25
 }
26 26
 
27
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
28
-function wpinv_discount_columns( $existing_columns ) {
27
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
28
+function wpinv_discount_columns($existing_columns) {
29 29
     $columns                = array();
30 30
     $columns['cb']          = $existing_columns['cb'];
31
-    $columns['name']        = __( 'Name', 'invoicing' );
32
-    $columns['code']        = __( 'Code', 'invoicing' );
33
-    $columns['amount']      = __( 'Amount', 'invoicing' );
34
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
35
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
36
-    $columns['status']      = __( 'Status', 'invoicing' );
31
+    $columns['name']        = __('Name', 'invoicing');
32
+    $columns['code']        = __('Code', 'invoicing');
33
+    $columns['amount']      = __('Amount', 'invoicing');
34
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
35
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
36
+    $columns['status']      = __('Status', 'invoicing');
37 37
 
38 38
     return $columns;
39 39
 }
40 40
 
41
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
42
-function wpinv_discount_custom_column( $column ) {
41
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
42
+function wpinv_discount_custom_column($column) {
43 43
     global $post;
44 44
     
45 45
     $discount = $post;
46 46
 
47
-    switch ( $column ) {
47
+    switch ($column) {
48 48
         case 'name' :
49
-            echo get_the_title( $discount->ID );
49
+            echo get_the_title($discount->ID);
50 50
         break;
51 51
         case 'code' :
52
-            echo wpinv_get_discount_code( $discount->ID );
52
+            echo wpinv_get_discount_code($discount->ID);
53 53
         break;
54 54
         case 'amount' :
55
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
55
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
56 56
         break;
57 57
         case 'usage_limit' :
58
-            echo wpinv_get_discount_uses( $discount->ID );
58
+            echo wpinv_get_discount_uses($discount->ID);
59 59
         break;
60 60
         case 'usage' :
61
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
62
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
63
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
61
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
62
+            if (wpinv_get_discount_max_uses($discount->ID)) {
63
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
64 64
             } else {
65 65
                 $usage .= ' &infin;';
66 66
             }
@@ -68,162 +68,162 @@  discard block
 block discarded – undo
68 68
             echo $usage;
69 69
         break;
70 70
         case 'expiry_date' :
71
-            if ( wpinv_get_discount_expiration( $discount->ID ) ) {
72
-                $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) );
71
+            if (wpinv_get_discount_expiration($discount->ID)) {
72
+                $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID)));
73 73
             } else {
74
-                $expiration = __( 'Never', 'invoicing' );
74
+                $expiration = __('Never', 'invoicing');
75 75
             }
76 76
                 
77 77
             echo $expiration;
78 78
         break;
79 79
         case 'description' :
80
-            echo wp_kses_post( $post->post_excerpt );
80
+            echo wp_kses_post($post->post_excerpt);
81 81
         break;
82 82
         case 'status' :
83
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
83
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
84 84
             
85
-            echo wpinv_discount_status( $status );
85
+            echo wpinv_discount_status($status);
86 86
         break;
87 87
     }
88 88
 }
89 89
 
90
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
91
-function wpinv_post_row_actions( $actions, $post ) {
92
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
90
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
91
+function wpinv_post_row_actions($actions, $post) {
92
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
93 93
     
94
-    if ( $post_type == 'wpi_invoice' ) {
94
+    if ($post_type == 'wpi_invoice') {
95 95
         $actions = array();
96 96
     }
97 97
     
98
-    if ( $post_type == 'wpi_discount' ) {
99
-        $actions = wpinv_discount_row_actions( $post, $actions );
98
+    if ($post_type == 'wpi_discount') {
99
+        $actions = wpinv_discount_row_actions($post, $actions);
100 100
     }
101 101
     
102 102
     return $actions;
103 103
 }
104 104
 
105
-function wpinv_discount_row_actions( $discount, $row_actions ) {
106
-    $row_actions  = array();
107
-    $edit_link = get_edit_post_link( $discount->ID );
108
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
105
+function wpinv_discount_row_actions($discount, $row_actions) {
106
+    $row_actions = array();
107
+    $edit_link = get_edit_post_link($discount->ID);
108
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
109 109
 
110
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
111
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
112
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
113
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
110
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
111
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
112
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
113
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
114 114
     }
115 115
 
116
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
117
-        if ( isset( $row_actions['delete'] ) ) {
118
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
116
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
117
+        if (isset($row_actions['delete'])) {
118
+            unset($row_actions['delete']); // Don't delete used discounts.
119 119
         }
120 120
     } else {
121
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
121
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
122 122
     }
123 123
     
124 124
 
125
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
125
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
126 126
 
127 127
     return $row_actions;
128 128
 }
129 129
 
130
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
131
-function wpinv_table_primary_column( $default, $screen_id ) {
132
-    if ( 'edit-wpi_invoice' === $screen_id ) {
130
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
131
+function wpinv_table_primary_column($default, $screen_id) {
132
+    if ('edit-wpi_invoice' === $screen_id) {
133 133
         return 'name';
134 134
     }
135 135
     
136 136
     return $default;
137 137
 }
138 138
 
139
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
140
-    if ( !$display ) {
139
+function wpinv_discount_bulk_actions($actions, $display = false) {    
140
+    if (!$display) {
141 141
         return array();
142 142
     }
143 143
     
144 144
     $actions = array(
145
-        'activate'   => __( 'Activate', 'invoicing' ),
146
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
147
-        'delete'     => __( 'Delete', 'invoicing' ),
145
+        'activate'   => __('Activate', 'invoicing'),
146
+        'deactivate' => __('Deactivate', 'invoicing'),
147
+        'delete'     => __('Delete', 'invoicing'),
148 148
     );
149 149
     $two = '';
150 150
     $which = 'top';
151 151
     echo '</div><div class="alignleft actions bulkactions">';
152
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
153
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
154
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
152
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
153
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
154
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
155 155
 
156
-    foreach ( $actions as $name => $title ) {
156
+    foreach ($actions as $name => $title) {
157 157
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
158 158
 
159 159
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
160 160
     }
161 161
     echo "</select>";
162 162
 
163
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
163
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
164 164
     
165 165
     echo '</div><div class="alignleft actions">';
166 166
 }
167
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
167
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
168 168
 
169
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
170
-    if ( $post_type == 'wpi_discount' ) {
169
+function wpinv_disable_months_dropdown($disable, $post_type) {
170
+    if ($post_type == 'wpi_discount') {
171 171
         $disable = true;
172 172
     }
173 173
     
174 174
     return $disable;
175 175
 }
176
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
176
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
177 177
 
178 178
 function wpinv_restrict_manage_posts() {
179 179
     global $typenow;
180 180
 
181
-    if( 'wpi_discount' == $typenow ) {
181
+    if ('wpi_discount' == $typenow) {
182 182
         wpinv_discount_filters();
183 183
     }
184 184
 }
185
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
185
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
186 186
 
187 187
 function wpinv_discount_filters() {
188
-    echo wpinv_discount_bulk_actions( array(), true );
188
+    echo wpinv_discount_bulk_actions(array(), true);
189 189
     
190 190
     ?>
191 191
     <select name="discount_type" id="dropdown_wpinv_discount_type">
192
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
192
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
193 193
         <?php
194 194
             $types = wpinv_get_discount_types();
195 195
 
196
-            foreach ( $types as $name => $type ) {
197
-                echo '<option value="' . esc_attr( $name ) . '"';
196
+            foreach ($types as $name => $type) {
197
+                echo '<option value="' . esc_attr($name) . '"';
198 198
 
199
-                if ( isset( $_GET['discount_type'] ) )
200
-                    selected( $name, $_GET['discount_type'] );
199
+                if (isset($_GET['discount_type']))
200
+                    selected($name, $_GET['discount_type']);
201 201
 
202
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
202
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
203 203
             }
204 204
         ?>
205 205
     </select>
206 206
     <?php
207 207
 }
208 208
 
209
-function wpinv_request( $vars ) {
209
+function wpinv_request($vars) {
210 210
     global $typenow, $wp_query, $wp_post_statuses;
211 211
 
212
-    if ( 'wpi_invoice' === $typenow ) {
213
-        if ( !isset( $vars['post_status'] ) ) {
212
+    if ('wpi_invoice' === $typenow) {
213
+        if (!isset($vars['post_status'])) {
214 214
             $post_statuses = wpinv_get_invoice_statuses();
215 215
 
216
-            foreach ( $post_statuses as $status => $value ) {
217
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
218
-                    unset( $post_statuses[ $status ] );
216
+            foreach ($post_statuses as $status => $value) {
217
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
218
+                    unset($post_statuses[$status]);
219 219
                 }
220 220
             }
221 221
 
222
-            $vars['post_status'] = array_keys( $post_statuses );
222
+            $vars['post_status'] = array_keys($post_statuses);
223 223
         }
224 224
         
225
-        if ( isset( $vars['orderby'] ) ) {
226
-            if ( 'amount' == $vars['orderby'] ) {
225
+        if (isset($vars['orderby'])) {
226
+            if ('amount' == $vars['orderby']) {
227 227
                 $vars = array_merge(
228 228
                     $vars,
229 229
                     array(
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
                         'orderby'  => 'meta_value_num'
232 232
                     )
233 233
                 );
234
-            } else if ( 'customer' == $vars['orderby'] ) {
234
+            } else if ('customer' == $vars['orderby']) {
235 235
                 $vars = array_merge(
236 236
                     $vars,
237 237
                     array(
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
                 );
242 242
             }
243 243
         }
244
-    } else if ( 'wpi_item' == $typenow ) {
244
+    } else if ('wpi_item' == $typenow) {
245 245
         // Check if 'orderby' is set to "price"
246
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
246
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
247 247
             $vars = array_merge(
248 248
                 $vars,
249 249
                 array(
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         }
255 255
 
256 256
         // Check if "orderby" is set to "vat_rule"
257
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
257
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
258 258
             $vars = array_merge(
259 259
                 $vars,
260 260
                 array(
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
         }
266 266
 
267 267
         // Check if "orderby" is set to "vat_class"
268
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
268
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
269 269
             $vars = array_merge(
270 270
                 $vars,
271 271
                 array(
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         }
277 277
         
278 278
         // Check if "orderby" is set to "type"
279
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
279
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
280 280
             $vars = array_merge(
281 281
                 $vars,
282 282
                 array(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         }
288 288
         
289 289
         // Check if "orderby" is set to "recurring"
290
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
290
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
291 291
             $vars = array_merge(
292 292
                 $vars,
293 293
                 array(
@@ -297,120 +297,120 @@  discard block
 block discarded – undo
297 297
             );
298 298
         }
299 299
 
300
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
300
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
301 301
         // Filter vat rule type
302
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
302
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
303 303
             $meta_query[] = array(
304 304
                     'key'   => '_wpinv_vat_rule',
305
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
305
+                    'value' => sanitize_text_field($_GET['vat_rule']),
306 306
                     'compare' => '='
307 307
                 );
308 308
         }
309 309
         
310 310
         // Filter vat class
311
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
311
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
312 312
             $meta_query[] = array(
313 313
                     'key'   => '_wpinv_vat_class',
314
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
314
+                    'value' => sanitize_text_field($_GET['vat_class']),
315 315
                     'compare' => '='
316 316
                 );
317 317
         }
318 318
         
319 319
         // Filter item type
320
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
320
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
321 321
             $meta_query[] = array(
322 322
                     'key'   => '_wpinv_type',
323
-                    'value' => sanitize_text_field( $_GET['type'] ),
323
+                    'value' => sanitize_text_field($_GET['type']),
324 324
                     'compare' => '='
325 325
                 );
326 326
         }
327 327
         
328
-        if ( !empty( $meta_query ) ) {
328
+        if (!empty($meta_query)) {
329 329
             $vars['meta_query'] = $meta_query;
330 330
         }
331
-    } else if ( 'wpi_discount' == $typenow ) {
332
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
331
+    } else if ('wpi_discount' == $typenow) {
332
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
333 333
         // Filter vat rule type
334
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
334
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
335 335
             $meta_query[] = array(
336 336
                     'key'   => '_wpi_discount_type',
337
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
337
+                    'value' => sanitize_text_field($_GET['discount_type']),
338 338
                     'compare' => '='
339 339
                 );
340 340
         }
341 341
         
342
-        if ( !empty( $meta_query ) ) {
342
+        if (!empty($meta_query)) {
343 343
             $vars['meta_query'] = $meta_query;
344 344
         }
345 345
     }
346 346
 
347 347
     return $vars;
348 348
 }
349
-add_filter( 'request', 'wpinv_request' );
349
+add_filter('request', 'wpinv_request');
350 350
 
351 351
 function wpinv_options_page() {
352
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
352
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
353 353
     
354
-    if ( $page !== 'wpinv-settings' ) {
354
+    if ($page !== 'wpinv-settings') {
355 355
         return;
356 356
     }
357 357
     
358 358
     $settings_tabs = wpinv_get_settings_tabs();
359 359
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
360
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
361
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
360
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
361
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
362 362
     $key           = 'main';
363 363
 
364
-    if ( is_array( $sections ) ) {
365
-        $key = key( $sections );
364
+    if (is_array($sections)) {
365
+        $key = key($sections);
366 366
     }
367 367
 
368
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
369
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
368
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
369
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
370 370
     ob_start();
371 371
     ?>
372 372
     <div class="wrap">
373 373
         <h1 class="nav-tab-wrapper">
374 374
             <?php
375
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
376
-                $tab_url = add_query_arg( array(
375
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
376
+                $tab_url = add_query_arg(array(
377 377
                     'settings-updated' => false,
378 378
                     'tab' => $tab_id,
379
-                ) );
379
+                ));
380 380
 
381 381
                 // Remove the section from the tabs so we always end up at the main section
382
-                $tab_url = remove_query_arg( 'section', $tab_url );
383
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
382
+                $tab_url = remove_query_arg('section', $tab_url);
383
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
384 384
 
385 385
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
386 386
 
387
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
388
-                    echo esc_html( $tab_name );
387
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
388
+                    echo esc_html($tab_name);
389 389
                 echo '</a>';
390 390
             }
391 391
             ?>
392 392
         </h1>
393 393
         <?php
394
-        $number_of_sections = count( $sections );
394
+        $number_of_sections = count($sections);
395 395
         $number = 0;
396
-        if ( $number_of_sections > 1 ) {
396
+        if ($number_of_sections > 1) {
397 397
             echo '<div><ul class="subsubsub">';
398
-            foreach( $sections as $section_id => $section_name ) {
398
+            foreach ($sections as $section_id => $section_name) {
399 399
                 echo '<li>';
400 400
                 $number++;
401
-                $tab_url = add_query_arg( array(
401
+                $tab_url = add_query_arg(array(
402 402
                     'settings-updated' => false,
403 403
                     'tab' => $active_tab,
404 404
                     'section' => $section_id
405
-                ) );
406
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
405
+                ));
406
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
407 407
                 $class = '';
408
-                if ( $section == $section_id ) {
408
+                if ($section == $section_id) {
409 409
                     $class = 'current';
410 410
                 }
411
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
411
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
412 412
 
413
-                if ( $number != $number_of_sections ) {
413
+                if ($number != $number_of_sections) {
414 414
                     echo ' | ';
415 415
                 }
416 416
                 echo '</li>';
@@ -422,19 +422,19 @@  discard block
 block discarded – undo
422 422
             <form method="post" action="options.php">
423 423
                 <table class="form-table">
424 424
                 <?php
425
-                settings_fields( 'wpinv_settings' );
425
+                settings_fields('wpinv_settings');
426 426
 
427
-                if ( 'main' === $section ) {
428
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
427
+                if ('main' === $section) {
428
+                    do_action('wpinv_settings_tab_top', $active_tab);
429 429
                 }
430 430
 
431
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section );
432
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section );
433
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section  );
431
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section);
432
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section);
433
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section);
434 434
 
435 435
                 // For backwards compatibility
436
-                if ( 'main' === $section ) {
437
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
436
+                if ('main' === $section) {
437
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
438 438
                 }
439 439
                 ?>
440 440
                 </table>
@@ -447,12 +447,12 @@  discard block
 block discarded – undo
447 447
     echo $content;
448 448
 }
449 449
 
450
-function wpinv_item_type_class( $classes, $class, $post_id ) {
450
+function wpinv_item_type_class($classes, $class, $post_id) {
451 451
     global $pagenow, $typenow;
452 452
 
453
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
454
-        $classes[] = 'wpi-type-' . sanitize_html_class( $type );
453
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && $type = get_post_meta($post_id, '_wpinv_type', true)) {
454
+        $classes[] = 'wpi-type-' . sanitize_html_class($type);
455 455
     }
456 456
     return $classes;
457 457
 }
458
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
459 458
\ No newline at end of file
459
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
460 460
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -7,228 +7,228 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'ID'                => __( 'ID', 'invoicing' ),
18
-        'details'           => __( 'Details', 'invoicing' ),
17
+        'ID'                => __('ID', 'invoicing'),
18
+        'details'           => __('Details', 'invoicing'),
19 19
         //'email'             => __( 'Email', 'invoicing' ),
20
-        'customer'          => __( 'Customer', 'invoicing' ),
21
-        'amount'            => __( 'Amount', 'invoicing' ),
22
-        'invoice_date'      => __( 'Date', 'invoicing' ),
23
-        'status'            => __( 'Status', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
20
+        'customer'          => __('Customer', 'invoicing'),
21
+        'amount'            => __('Amount', 'invoicing'),
22
+        'invoice_date'      => __('Date', 'invoicing'),
23
+        'status'            => __('Status', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39 39
 
40
-function wpinv_sortable_columns( $columns ) {
40
+function wpinv_sortable_columns($columns) {
41 41
     $columns = array(
42
-        'ID'     => array( 'ID', true ),
43
-        'amount' => array( 'amount', false ),
44
-        'invoice_date'   => array( 'date', false ),
45
-        'customer'   => array( 'customer', false ),
42
+        'ID'     => array('ID', true),
43
+        'amount' => array('amount', false),
44
+        'invoice_date'   => array('date', false),
45
+        'customer'   => array('customer', false),
46 46
         ///'email'   => array( 'email', false ),
47
-        'status'   => array( 'status', false ),
47
+        'status'   => array('status', false),
48 48
     );
49 49
     
50
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
50
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
51 51
 }
52
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
52
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
53 53
 
54
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
54
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
56 56
     global $post, $wpi_invoice;
57 57
     
58
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
59
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
58
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
59
+        $wpi_invoice = new WPInv_Invoice($post->ID);
60 60
     }
61 61
 
62 62
     $value = NULL;
63 63
     
64
-    switch ( $column_name ) {
64
+    switch ($column_name) {
65 65
         case 'email' :
66
-            $value   = $wpi_invoice->get_email();
66
+            $value = $wpi_invoice->get_email();
67 67
             break;
68 68
         case 'customer' :
69 69
             $customer_name = $wpi_invoice->get_user_full_name();
70
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
71
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
72
-            if ( $email = $wpi_invoice->get_email() ) {
70
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
71
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
72
+            if ($email = $wpi_invoice->get_email()) {
73 73
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
74 74
             }
75 75
             break;
76 76
         case 'amount' :
77
-            echo $wpi_invoice->get_total( true );
77
+            echo $wpi_invoice->get_total(true);
78 78
             break;
79 79
         case 'invoice_date' :
80
-            $date_format = get_option( 'date_format' );
81
-            $time_format = get_option( 'time_format' );
82
-            $date_time_format = $date_format . ' '. $time_format;
80
+            $date_format = get_option('date_format');
81
+            $time_format = get_option('time_format');
82
+            $date_time_format = $date_format . ' ' . $time_format;
83 83
             
84
-            $t_time = get_the_time( $date_time_format );
84
+            $t_time = get_the_time($date_time_format);
85 85
             $m_time = $post->post_date;
86
-            $h_time = mysql2date( $date_format, $m_time );
86
+            $h_time = mysql2date($date_format, $m_time);
87 87
             
88 88
             $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
89 89
             break;
90 90
         case 'status' :
91
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
91
+            $value   = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
92 92
             break;
93 93
         case 'details' :
94
-            $edit_link = get_edit_post_link( $post->ID );
95
-            $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>';
94
+            $edit_link = get_edit_post_link($post->ID);
95
+            $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>';
96 96
             break;
97 97
         case 'wpi_actions' :
98 98
             $value = '';
99
-            if ( !empty( $post->post_name ) ) {
100
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
99
+            if (!empty($post->post_name)) {
100
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
101 101
             }
102 102
             
103
-            if ( $email = $wpi_invoice->get_email() ) {
104
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
103
+            if ($email = $wpi_invoice->get_email()) {
104
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
105 105
             }
106 106
             
107 107
             break;
108 108
         default:
109
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
109
+            $value = isset($post->$column_name) ? $post->$column_name : '';
110 110
             break;
111 111
 
112 112
     }
113
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
113
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
114 114
     
115
-    if ( $value !== NULL ) {
115
+    if ($value !== NULL) {
116 116
         echo $value;
117 117
     }
118 118
 }
119 119
 
120
-function wpinv_admin_post_id( $id = 0 ) {
120
+function wpinv_admin_post_id($id = 0) {
121 121
     global $post;
122 122
 
123
-    if ( isset( $id ) && ! empty( $id ) ) {
123
+    if (isset($id) && !empty($id)) {
124 124
         return (int)$id;
125
-    } else if ( get_the_ID() ) {
126
-        return (int) get_the_ID();
127
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
128
-        return (int) $post->ID;
129
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
130
-        return (int) $_GET['post'];
131
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
132
-        return (int) $_GET['id'];
133
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
134
-        return (int) $_POST['id'];
125
+    } else if (get_the_ID()) {
126
+        return (int)get_the_ID();
127
+    } else if (isset($post->ID) && !empty($post->ID)) {
128
+        return (int)$post->ID;
129
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
130
+        return (int)$_GET['post'];
131
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
132
+        return (int)$_GET['id'];
133
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
134
+        return (int)$_POST['id'];
135 135
     } 
136 136
 
137 137
     return null;
138 138
 }
139 139
     
140
-function wpinv_admin_post_type( $id = 0 ) {
141
-    if ( !$id ) {
140
+function wpinv_admin_post_type($id = 0) {
141
+    if (!$id) {
142 142
         $id = wpinv_admin_post_id();
143 143
     }
144 144
     
145
-    $type = get_post_type( $id );
145
+    $type = get_post_type($id);
146 146
     
147
-    if ( !$type ) {
148
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
147
+    if (!$type) {
148
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
149 149
     }
150 150
     
151
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
151
+    return apply_filters('wpinv_admin_post_type', $type, $id);
152 152
 }
153 153
 
154 154
 function wpinv_admin_messages() {
155 155
 	global $wpinv_options;
156 156
 
157
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
158
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
157
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
158
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
159 159
 	}
160 160
 
161
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
162
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
161
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
162
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
163 163
 	}
164 164
 
165
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
166
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
165
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
166
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
167 167
 	}
168 168
 
169
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
170
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
169
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
170
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
171 171
 	}
172 172
 
173
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
174
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
173
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
174
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
175 175
 	}
176 176
 
177
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
178
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
177
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
178
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
179 179
 	}
180 180
 
181
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
182
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
181
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
182
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
183 183
     }
184 184
     
185
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
186
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
185
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
186
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
187 187
     }
188 188
 
189
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
190
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
189
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
190
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
191 191
     }
192 192
 
193
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
194
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
193
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
194
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
195 195
 	}
196 196
 
197
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
198
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
197
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
198
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
199 199
 	}
200 200
 
201
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
202
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
201
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
202
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
203 203
 	}
204 204
 
205
-	settings_errors( 'wpinv-notices' );
205
+	settings_errors('wpinv-notices');
206 206
 }
207
-add_action( 'admin_notices', 'wpinv_admin_messages' );
207
+add_action('admin_notices', 'wpinv_admin_messages');
208 208
 
209
-function wpinv_items_columns( $existing_columns ) {
209
+function wpinv_items_columns($existing_columns) {
210 210
     global $wpinv_euvat;
211 211
     
212 212
     $columns                = array();
213 213
     $columns['cb']          = $existing_columns['cb'];
214
-    $columns['title']       = __( 'Title', 'invoicing' );
215
-    $columns['price']       = __( 'Price', 'invoicing' );
216
-    if ( $wpinv_euvat->allow_vat_rules() ) {
217
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
214
+    $columns['title']       = __('Title', 'invoicing');
215
+    $columns['price']       = __('Price', 'invoicing');
216
+    if ($wpinv_euvat->allow_vat_rules()) {
217
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
218 218
     }
219
-    if ( $wpinv_euvat->allow_vat_classes() ) {
220
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
219
+    if ($wpinv_euvat->allow_vat_classes()) {
220
+        $columns['vat_class']   = __('VAT class', 'invoicing');
221 221
     }
222
-    $columns['type']        = __( 'Type', 'invoicing' );
223
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
224
-    $columns['date']        = __( 'Date', 'invoicing' );
225
-    $columns['id']          = __( 'ID', 'invoicing' );
222
+    $columns['type']        = __('Type', 'invoicing');
223
+    $columns['recurring']   = __('Recurring', 'invoicing');
224
+    $columns['date']        = __('Date', 'invoicing');
225
+    $columns['id']          = __('ID', 'invoicing');
226 226
 
227
-    return apply_filters( 'wpinv_items_columns', $columns );
227
+    return apply_filters('wpinv_items_columns', $columns);
228 228
 }
229
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
229
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
230 230
 
231
-function wpinv_items_sortable_columns( $columns ) {
231
+function wpinv_items_sortable_columns($columns) {
232 232
     $columns['price']       = 'price';
233 233
     $columns['vat_rule']    = 'vat_rule';
234 234
     $columns['vat_class']   = 'vat_class';
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 
239 239
     return $columns;
240 240
 }
241
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
241
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
242 242
 
243
-function wpinv_item_quick_edit( $column_name, $post_type ) {
244
-    if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) {
243
+function wpinv_item_quick_edit($column_name, $post_type) {
244
+    if (!($post_type == 'wpi_item' && $column_name == 'price')) {
245 245
         return;
246 246
     }
247 247
     global $wpinv_euvat, $post;
@@ -249,23 +249,23 @@  discard block
 block discarded – undo
249 249
     $symbol    = wpinv_currency_symbol();
250 250
     $position  = wpinv_currency_position();
251 251
 
252
-    $price     = wpinv_get_item_price( $post->ID );
253
-    $item_type = wpinv_get_item_type( $post->ID );
252
+    $price     = wpinv_get_item_price($post->ID);
253
+    $item_type = wpinv_get_item_type($post->ID);
254 254
     ?>
255 255
     <fieldset class="inline-edit-col-right wpi-inline-item-col">
256 256
         <div class="inline-edit-col">
257 257
             <div class="inline-edit-group wp-clearfix">
258 258
                 <label class="inline-edit-wpinv-price">
259
-                    <span class="title"><?php _e( 'Item price', 'invoicing' );?></span>
260
-                    <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" placeholder="<?php echo wpinv_format_amount( 0 ); ?>" value="<?php echo wpinv_format_amount( $price );?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . '&nbsp;' : '' );?></span>
259
+                    <span class="title"><?php _e('Item price', 'invoicing'); ?></span>
260
+                    <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" placeholder="<?php echo wpinv_format_amount(0); ?>" value="<?php echo wpinv_format_amount($price); ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . '&nbsp;' : ''); ?></span>
261 261
                 </label>
262 262
             </div>
263
-            <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?>
263
+            <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?>
264 264
             <div class="inline-edit-group wp-clearfix">
265 265
                 <label class="inline-edit-wpinv-vat-rate">
266
-                    <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span>
266
+                    <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span>
267 267
                     <span class="input-text-wrap">
268
-                        <?php echo wpinv_html_select( array(
268
+                        <?php echo wpinv_html_select(array(
269 269
                             'options'          => $wpinv_euvat->get_rules(),
270 270
                             'name'             => '_wpinv_vat_rules',
271 271
                             'id'               => 'wpinv_vat_rules-' . $post->ID,
@@ -273,16 +273,16 @@  discard block
 block discarded – undo
273 273
                             'show_option_all'  => false,
274 274
                             'show_option_none' => false,
275 275
                             'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                        ) ); ?>
276
+                        )); ?>
277 277
                     </span>
278 278
                 </label>
279 279
             </div>
280
-            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?>
280
+            <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?>
281 281
             <div class="inline-edit-group wp-clearfix">
282 282
                 <label class="inline-edit-wpinv-vat-class">
283
-                    <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span>
283
+                    <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span>
284 284
                     <span class="input-text-wrap">
285
-                        <?php echo wpinv_html_select( array(
285
+                        <?php echo wpinv_html_select(array(
286 286
                             'options'          => $wpinv_euvat->get_all_classes(),
287 287
                             'name'             => '_wpinv_vat_class',
288 288
                             'id'               => 'wpinv_vat_class-' . $post->ID,
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
                             'show_option_all'  => false,
291 291
                             'show_option_none' => false,
292 292
                             'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                        ) ); ?>
293
+                        )); ?>
294 294
                     </span>
295 295
                 </label>
296 296
             </div>
297 297
             <?php } ?>
298 298
             <div class="inline-edit-group wp-clearfix">
299 299
                 <label class="inline-edit-wpinv-type">
300
-                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
300
+                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
301 301
                     <span class="input-text-wrap">
302
-                        <?php echo wpinv_html_select( array(
302
+                        <?php echo wpinv_html_select(array(
303 303
                             'options'          => wpinv_get_item_types(),
304 304
                             'name'             => '_wpinv_item_type',
305 305
                             'id'               => 'wpinv_item_type-' . $post->ID,
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
                             'show_option_all'  => false,
308 308
                             'show_option_none' => false,
309 309
                             'class'            => 'gdmbx2-text-medium wpinv-item-type',
310
-                        ) ); ?>
310
+                        )); ?>
311 311
                     </span>
312 312
                 </label>
313 313
             </div>
@@ -315,150 +315,150 @@  discard block
 block discarded – undo
315 315
     </fieldset>
316 316
     <?php
317 317
 }
318
-add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
319
-add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
318
+add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
319
+add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
320 320
 
321
-function wpinv_items_table_custom_column( $column ) {
321
+function wpinv_items_table_custom_column($column) {
322 322
     global $wpinv_euvat, $post, $wpi_item;
323 323
     
324
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
325
-        $wpi_item = new WPInv_Item( $post->ID );
324
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
325
+        $wpi_item = new WPInv_Item($post->ID);
326 326
     }
327 327
 
328
-    switch ( $column ) {
328
+    switch ($column) {
329 329
         case 'price' :
330
-            echo wpinv_item_price( $post->ID );
330
+            echo wpinv_item_price($post->ID);
331 331
         break;
332 332
         case 'vat_rule' :
333
-            echo $wpinv_euvat->item_rule_label( $post->ID );
333
+            echo $wpinv_euvat->item_rule_label($post->ID);
334 334
         break;
335 335
         case 'vat_class' :
336
-            echo $wpinv_euvat->item_class_label( $post->ID );
336
+            echo $wpinv_euvat->item_class_label($post->ID);
337 337
         break;
338 338
         case 'type' :
339
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>';
339
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>';
340 340
         break;
341 341
         case 'recurring' :
342
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
342
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
343 343
         break;
344 344
         case 'id' :
345 345
            echo $post->ID;
346 346
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
347
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
348
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
349
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
347
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
348
+                    if ($wpinv_euvat->allow_vat_rules()) {
349
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
350 350
                     }
351
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
352
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
351
+                    if ($wpinv_euvat->allow_vat_classes()) {
352
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
353 353
                     }
354
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
354
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
355 355
                 </div>';
356 356
         break;
357 357
     }
358 358
     
359
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
359
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
360 360
 }
361
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
361
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
362 362
 
363 363
 function wpinv_add_items_filters() {
364 364
     global $wpinv_euvat, $typenow;
365 365
 
366 366
     // Checks if the current post type is 'item'
367
-    if ( $typenow == 'wpi_item') {
368
-        if ( $wpinv_euvat->allow_vat_rules() ) {
369
-            echo wpinv_html_select( array(
370
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
367
+    if ($typenow == 'wpi_item') {
368
+        if ($wpinv_euvat->allow_vat_rules()) {
369
+            echo wpinv_html_select(array(
370
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
371 371
                     'name'             => 'vat_rule',
372 372
                     'id'               => 'vat_rule',
373
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
373
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
374 374
                     'show_option_all'  => false,
375 375
                     'show_option_none' => false,
376 376
                     'class'            => 'gdmbx2-text-medium',
377
-                ) );
377
+                ));
378 378
         }
379 379
         
380
-        if ( $wpinv_euvat->allow_vat_classes() ) {
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
380
+        if ($wpinv_euvat->allow_vat_classes()) {
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
385
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium',
389
-                ) );
389
+                ));
390 390
         }
391 391
             
392
-        echo wpinv_html_select( array(
393
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
392
+        echo wpinv_html_select(array(
393
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
394 394
                 'name'             => 'type',
395 395
                 'id'               => 'type',
396
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
396
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
397 397
                 'show_option_all'  => false,
398 398
                 'show_option_none' => false,
399 399
                 'class'            => 'gdmbx2-text-medium',
400
-            ) );
400
+            ));
401 401
 
402
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
402
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
403 403
             echo '<input type="hidden" name="all_posts" value="1" />';
404 404
         }
405 405
     }
406 406
 }
407
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
407
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
408 408
 
409
-function wpinv_send_invoice_after_save( $post_id ) {
409
+function wpinv_send_invoice_after_save($post_id) {
410 410
     // If this is just a revision, don't send the email.
411
-    if ( wp_is_post_revision( $post_id ) ) {
411
+    if (wp_is_post_revision($post_id)) {
412 412
         return;
413 413
     }
414 414
     
415
-    if ( !current_user_can( 'manage_options' ) || get_post_type( $post_id ) != 'wpi_invoice' ) {
415
+    if (!current_user_can('manage_options') || get_post_type($post_id) != 'wpi_invoice') {
416 416
         return;
417 417
     }
418 418
     
419
-    if ( !empty( $_POST['wpi_save_send'] ) ) {
420
-        wpinv_user_invoice_notification( $post_id );
419
+    if (!empty($_POST['wpi_save_send'])) {
420
+        wpinv_user_invoice_notification($post_id);
421 421
     }
422 422
 }
423
-add_action( 'save_post', 'wpinv_send_invoice_after_save', 100, 1 );
423
+add_action('save_post', 'wpinv_send_invoice_after_save', 100, 1);
424 424
 
425
-function wpinv_send_register_new_user( $data, $postarr ) {
426
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && $data['post_type'] == 'wpi_invoice' ) {
427
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
428
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
425
+function wpinv_send_register_new_user($data, $postarr) {
426
+    if (current_user_can('manage_options') && !empty($data['post_type']) && $data['post_type'] == 'wpi_invoice') {
427
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
428
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
429 429
         
430
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
431
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
432
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
433
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
434
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
435
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
430
+        if ($is_new_user && $email && !email_exists($email)) {
431
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
432
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
433
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
434
+            $user_nicename = $display_name ? trim($display_name) : $email;
435
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
436 436
             
437
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
438
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
439
-                $user_login = sanitize_user( str_replace( ' ', '', $user_company ), true );
437
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
438
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
439
+                $user_login = sanitize_user(str_replace(' ', '', $user_company), true);
440 440
                 
441
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
441
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
442 442
                     $user_login = $email;
443 443
                 }
444 444
             }
445 445
             
446 446
             $userdata = array(
447 447
                 'user_login' => $user_login,
448
-                'user_pass' => wp_generate_password( 12, false ),
449
-                'user_email' => sanitize_text_field( $email ),
448
+                'user_pass' => wp_generate_password(12, false),
449
+                'user_email' => sanitize_text_field($email),
450 450
                 'first_name' => $first_name,
451 451
                 'last_name' => $last_name,
452
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
452
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
453 453
                 'nickname' => $display_name,
454 454
                 'display_name' => $display_name,
455 455
             );
456 456
 
457
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
457
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
458 458
             
459
-            $new_user_id = wp_insert_user( $userdata );
459
+            $new_user_id = wp_insert_user($userdata);
460 460
             
461
-            if ( !is_wp_error( $new_user_id ) ) {
461
+            if (!is_wp_error($new_user_id)) {
462 462
                 $data['post_author'] = $new_user_id;
463 463
                 $_POST['post_author'] = $new_user_id;
464 464
                 $_POST['post_author_override'] = $new_user_id;
@@ -479,27 +479,27 @@  discard block
 block discarded – undo
479 479
                 
480 480
                 $meta = array();
481 481
                 ///$meta['_wpinv_user_id'] = $new_user_id;
482
-                foreach ( $meta_fields as $field ) {
483
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
482
+                foreach ($meta_fields as $field) {
483
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
484 484
                 }
485 485
                 
486
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
486
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
487 487
 
488 488
                 // Update user meta.
489
-                foreach ( $meta as $key => $value ) {
490
-                    update_user_meta( $new_user_id, $key, $value );
489
+                foreach ($meta as $key => $value) {
490
+                    update_user_meta($new_user_id, $key, $value);
491 491
                 }
492 492
                 
493
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
493
+                if (function_exists('wp_send_new_user_notifications')) {
494 494
                     // Send email notifications related to the creation of new user.
495
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
495
+                    wp_send_new_user_notifications($new_user_id, 'user');
496 496
                 }
497 497
             } else {
498
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
498
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
499 499
             }
500 500
         }
501 501
     }
502 502
     
503 503
     return $data;
504 504
 }
505
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
506 505
\ No newline at end of file
506
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
507 507
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +775 added lines, -775 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     
18 18
     public $pending;
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
     public $full_name = '';
65 65
     public $parent_invoice = 0;
66 66
     
67
-    public function __construct( $invoice_id = false ) {
68
-        if( empty( $invoice_id ) ) {
67
+    public function __construct($invoice_id = false) {
68
+        if (empty($invoice_id)) {
69 69
             return false;
70 70
         }
71 71
 
72
-        $this->setup_invoice( $invoice_id );
72
+        $this->setup_invoice($invoice_id);
73 73
     }
74 74
 
75
-    public function get( $key ) {
76
-        if ( method_exists( $this, 'get_' . $key ) ) {
77
-            $value = call_user_func( array( $this, 'get_' . $key ) );
75
+    public function get($key) {
76
+        if (method_exists($this, 'get_' . $key)) {
77
+            $value = call_user_func(array($this, 'get_' . $key));
78 78
         } else {
79 79
             $value = $this->$key;
80 80
         }
@@ -82,51 +82,51 @@  discard block
 block discarded – undo
82 82
         return $value;
83 83
     }
84 84
 
85
-    public function set( $key, $value ) {
86
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
85
+    public function set($key, $value) {
86
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
87 87
 
88
-        if ( $key === 'status' ) {
88
+        if ($key === 'status') {
89 89
             $this->old_status = $this->status;
90 90
         }
91 91
 
92
-        if ( ! in_array( $key, $ignore ) ) {
93
-            $this->pending[ $key ] = $value;
92
+        if (!in_array($key, $ignore)) {
93
+            $this->pending[$key] = $value;
94 94
         }
95 95
 
96
-        if( '_ID' !== $key ) {
96
+        if ('_ID' !== $key) {
97 97
             $this->$key = $value;
98 98
         }
99 99
     }
100 100
 
101
-    public function _isset( $name ) {
102
-        if ( property_exists( $this, $name) ) {
103
-            return false === empty( $this->$name );
101
+    public function _isset($name) {
102
+        if (property_exists($this, $name)) {
103
+            return false === empty($this->$name);
104 104
         } else {
105 105
             return null;
106 106
         }
107 107
     }
108 108
 
109
-    private function setup_invoice( $invoice_id ) {
109
+    private function setup_invoice($invoice_id) {
110 110
         $this->pending = array();
111 111
 
112
-        if ( empty( $invoice_id ) ) {
112
+        if (empty($invoice_id)) {
113 113
             return false;
114 114
         }
115 115
 
116
-        $invoice = get_post( $invoice_id );
116
+        $invoice = get_post($invoice_id);
117 117
 
118
-        if( !$invoice || is_wp_error( $invoice ) ) {
118
+        if (!$invoice || is_wp_error($invoice)) {
119 119
             return false;
120 120
         }
121 121
 
122
-        if( 'wpi_invoice' !== $invoice->post_type ) {
122
+        if ('wpi_invoice' !== $invoice->post_type) {
123 123
             return false;
124 124
         }
125 125
 
126
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
126
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
127 127
         
128 128
         // Primary Identifier
129
-        $this->ID              = absint( $invoice_id );
129
+        $this->ID              = absint($invoice_id);
130 130
         
131 131
         // We have a payment, get the generic payment_meta item to reduce calls to it
132 132
         $this->payment_meta    = $this->get_meta();
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         $this->post_status     = $this->status;
138 138
         $this->mode            = $this->setup_mode();
139 139
         $this->parent_invoice  = $invoice->post_parent;
140
-        $this->post_name       = $this->setup_post_name( $invoice );
140
+        $this->post_name       = $this->setup_post_name($invoice);
141 141
         $this->status_nicename = $this->setup_status_nicename();
142 142
 
143 143
         // Items
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
         
160 160
         // User based
161 161
         $this->ip              = $this->setup_ip();
162
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
163
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
162
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
163
+        $this->email           = get_the_author_meta('email', $this->user_id);
164 164
         
165 165
         $this->user_info       = $this->setup_user_info();
166 166
                 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         $this->company         = $this->user_info['company'];
170 170
         $this->vat_number      = $this->user_info['vat_number'];
171 171
         $this->vat_rate        = $this->user_info['vat_rate'];
172
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
172
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
173 173
         $this->address         = $this->user_info['address'];
174 174
         $this->city            = $this->user_info['city'];
175 175
         $this->country         = $this->user_info['country'];
@@ -184,48 +184,48 @@  discard block
 block discarded – undo
184 184
         // Other Identifiers
185 185
         $this->key             = $this->setup_invoice_key();
186 186
         $this->number          = $this->setup_invoice_number();
187
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
187
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
188 188
         
189
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
189
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
190 190
         
191 191
         // Allow extensions to add items to this object via hook
192
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
192
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
193 193
 
194 194
         return true;
195 195
     }
196 196
     
197 197
     private function setup_status_nicename() {
198
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
198
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
199 199
         
200
-        $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status );
200
+        $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status);
201 201
 
202 202
         return $status;
203 203
     }
204 204
     
205
-    private function setup_post_name( $post = NULL ) {
205
+    private function setup_post_name($post = NULL) {
206 206
         $post_name = '';
207 207
         
208
-        if ( !empty( $post ) ) {
209
-            if( !empty( $post->post_name ) ) {
208
+        if (!empty($post)) {
209
+            if (!empty($post->post_name)) {
210 210
                 $post_name = $post->post_name;
211
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
212
-                $post_name = sanitize_title( $post->post_title );
211
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
212
+                $post_name = sanitize_title($post->post_title);
213 213
                 
214 214
                 global $wpdb;
215
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
215
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
216 216
             }
217 217
         }
218 218
 
219
-        $this->post_name   = $post_name;
219
+        $this->post_name = $post_name;
220 220
     }
221 221
     
222 222
     private function setup_due_date() {
223
-        $due_date = $this->get_meta( '_wpinv_due_date' );
223
+        $due_date = $this->get_meta('_wpinv_due_date');
224 224
         
225
-        if ( empty( $due_date ) ) {
226
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
227
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
228
-        } else if ( $due_date == 'none' ) {
225
+        if (empty($due_date)) {
226
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
227
+            $due_date = date_i18n('Y-m-d', $overdue_time);
228
+        } else if ($due_date == 'none') {
229 229
             $due_date = '';
230 230
         }
231 231
         
@@ -233,63 +233,63 @@  discard block
 block discarded – undo
233 233
     }
234 234
     
235 235
     private function setup_completed_date() {
236
-        $invoice = get_post( $this->ID );
236
+        $invoice = get_post($this->ID);
237 237
 
238
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
238
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
239 239
             return false; // This invoice was never paid
240 240
         }
241 241
 
242
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
242
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
243 243
 
244 244
         return $date;
245 245
     }
246 246
     
247 247
     private function setup_cart_details() {
248
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
248
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
249 249
         return $cart_details;
250 250
     }
251 251
     
252 252
     public function array_convert() {
253
-        return get_object_vars( $this );
253
+        return get_object_vars($this);
254 254
     }
255 255
     
256 256
     private function setup_items() {
257
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
257
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
258 258
         return $items;
259 259
     }
260 260
     
261 261
     private function setup_fees() {
262
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
262
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
263 263
         return $payment_fees;
264 264
     }
265 265
         
266 266
     private function setup_currency() {
267
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
267
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
268 268
         return $currency;
269 269
     }
270 270
     
271 271
     private function setup_discount() {
272 272
         //$discount = $this->get_meta( '_wpinv_discount', true );
273
-        $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total );
274
-        if ( $discount < 0 ) {
273
+        $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total);
274
+        if ($discount < 0) {
275 275
             $discount = 0;
276 276
         }
277
-        $discount = wpinv_format_amount( $discount, NULL, true );
277
+        $discount = wpinv_format_amount($discount, NULL, true);
278 278
         
279 279
         return $discount;
280 280
     }
281 281
     
282 282
     private function setup_discount_code() {
283
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
283
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
284 284
         return $discount_code;
285 285
     }
286 286
     
287 287
     private function setup_tax() {
288
-        $tax = $this->get_meta( '_wpinv_tax', true );
288
+        $tax = $this->get_meta('_wpinv_tax', true);
289 289
 
290 290
         // We don't have tax as it's own meta and no meta was passed
291
-        if ( '' === $tax ) {            
292
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
291
+        if ('' === $tax) {            
292
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
293 293
         }
294 294
 
295 295
         return $tax;
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
         $subtotal     = 0;
304 304
         $cart_details = $this->cart_details;
305 305
 
306
-        if ( is_array( $cart_details ) ) {
307
-            foreach ( $cart_details as $item ) {
308
-                if ( isset( $item['subtotal'] ) ) {
306
+        if (is_array($cart_details)) {
307
+            foreach ($cart_details as $item) {
308
+                if (isset($item['subtotal'])) {
309 309
                     $subtotal += $item['subtotal'];
310 310
                 }
311 311
             }
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
     }
320 320
     
321 321
     private function setup_discounts() {
322
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
322
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
323 323
         return $discounts;
324 324
     }
325 325
     
326 326
     private function setup_total() {
327
-        $amount = $this->get_meta( '_wpinv_total', true );
327
+        $amount = $this->get_meta('_wpinv_total', true);
328 328
 
329
-        if ( empty( $amount ) && '0.00' != $amount ) {
330
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
331
-            $meta   = maybe_unserialize( $meta );
329
+        if (empty($amount) && '0.00' != $amount) {
330
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
331
+            $meta   = maybe_unserialize($meta);
332 332
 
333
-            if ( isset( $meta['amount'] ) ) {
333
+            if (isset($meta['amount'])) {
334 334
                 $amount = $meta['amount'];
335 335
             }
336 336
         }
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
     }
340 340
     
341 341
     private function setup_mode() {
342
-        return $this->get_meta( '_wpinv_mode' );
342
+        return $this->get_meta('_wpinv_mode');
343 343
     }
344 344
 
345 345
     private function setup_gateway() {
346
-        $gateway = $this->get_meta( '_wpinv_gateway' );
346
+        $gateway = $this->get_meta('_wpinv_gateway');
347 347
         
348
-        if ( empty( $gateway ) && 'publish' === $this->status || 'complete' === $this->status ) {
348
+        if (empty($gateway) && 'publish' === $this->status || 'complete' === $this->status) {
349 349
             $gateway = 'manual';
350 350
         }
351 351
         
@@ -353,23 +353,23 @@  discard block
 block discarded – undo
353 353
     }
354 354
     
355 355
     private function setup_gateway_title() {
356
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
356
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
357 357
         return $gateway_title;
358 358
     }
359 359
 
360 360
     private function setup_transaction_id() {
361
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
361
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
362 362
 
363
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
363
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
364 364
             $gateway        = $this->gateway;
365
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
365
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
366 366
         }
367 367
 
368 368
         return $transaction_id;
369 369
     }
370 370
 
371 371
     private function setup_ip() {
372
-        $ip = $this->get_meta( '_wpinv_user_ip' );
372
+        $ip = $this->get_meta('_wpinv_user_ip');
373 373
         return $ip;
374 374
     }
375 375
 
@@ -379,62 +379,62 @@  discard block
 block discarded – undo
379 379
     ///}
380 380
         
381 381
     private function setup_first_name() {
382
-        $first_name = $this->get_meta( '_wpinv_first_name' );
382
+        $first_name = $this->get_meta('_wpinv_first_name');
383 383
         return $first_name;
384 384
     }
385 385
     
386 386
     private function setup_last_name() {
387
-        $last_name = $this->get_meta( '_wpinv_last_name' );
387
+        $last_name = $this->get_meta('_wpinv_last_name');
388 388
         return $last_name;
389 389
     }
390 390
     
391 391
     private function setup_company() {
392
-        $company = $this->get_meta( '_wpinv_company' );
392
+        $company = $this->get_meta('_wpinv_company');
393 393
         return $company;
394 394
     }
395 395
     
396 396
     private function setup_vat_number() {
397
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
397
+        $vat_number = $this->get_meta('_wpinv_vat_number');
398 398
         return $vat_number;
399 399
     }
400 400
     
401 401
     private function setup_vat_rate() {
402
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
402
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
403 403
         return $vat_rate;
404 404
     }
405 405
     
406 406
     private function setup_adddress_confirmed() {
407
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
407
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
408 408
         return $adddress_confirmed;
409 409
     }
410 410
     
411 411
     private function setup_phone() {
412
-        $phone = $this->get_meta( '_wpinv_phone' );
412
+        $phone = $this->get_meta('_wpinv_phone');
413 413
         return $phone;
414 414
     }
415 415
     
416 416
     private function setup_address() {
417
-        $address = $this->get_meta( '_wpinv_address', true );
417
+        $address = $this->get_meta('_wpinv_address', true);
418 418
         return $address;
419 419
     }
420 420
     
421 421
     private function setup_city() {
422
-        $city = $this->get_meta( '_wpinv_city', true );
422
+        $city = $this->get_meta('_wpinv_city', true);
423 423
         return $city;
424 424
     }
425 425
     
426 426
     private function setup_country() {
427
-        $country = $this->get_meta( '_wpinv_country', true );
427
+        $country = $this->get_meta('_wpinv_country', true);
428 428
         return $country;
429 429
     }
430 430
     
431 431
     private function setup_state() {
432
-        $state = $this->get_meta( '_wpinv_state', true );
432
+        $state = $this->get_meta('_wpinv_state', true);
433 433
         return $state;
434 434
     }
435 435
     
436 436
     private function setup_zip() {
437
-        $zip = $this->get_meta( '_wpinv_zip', true );
437
+        $zip = $this->get_meta('_wpinv_zip', true);
438 438
         return $zip;
439 439
     }
440 440
 
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
             'user_id'        => $this->user_id,
444 444
             'first_name'     => $this->first_name,
445 445
             'last_name'      => $this->last_name,
446
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
446
+            'email'          => get_the_author_meta('email', $this->user_id),
447 447
             'phone'          => $this->phone,
448 448
             'address'        => $this->address,
449 449
             'city'           => $this->city,
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
         );
459 459
         
460 460
         $user_info = array();
461
-        if ( isset( $this->payment_meta['user_info'] ) ) {
462
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
461
+        if (isset($this->payment_meta['user_info'])) {
462
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
463 463
             
464
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
464
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
465 465
                 $this->user_id = $post->post_author;
466
-                $this->email = get_the_author_meta( 'email', $this->user_id );
466
+                $this->email = get_the_author_meta('email', $this->user_id);
467 467
                 
468 468
                 $user_info['user_id'] = $this->user_id;
469 469
                 $user_info['email'] = $this->email;
@@ -472,13 +472,13 @@  discard block
 block discarded – undo
472 472
             }
473 473
         }
474 474
         
475
-        $user_info    = wp_parse_args( $user_info, $defaults );
475
+        $user_info = wp_parse_args($user_info, $defaults);
476 476
         
477 477
         // Get the user, but only if it's been created
478
-        $user = get_userdata( $this->user_id );
478
+        $user = get_userdata($this->user_id);
479 479
         
480
-        if ( !empty( $user ) && $user->ID > 0 ) {
481
-            if ( empty( $user_info ) ) {
480
+        if (!empty($user) && $user->ID > 0) {
481
+            if (empty($user_info)) {
482 482
                 $user_info = array(
483 483
                     'user_id'    => $user->ID,
484 484
                     'first_name' => $user->first_name,
@@ -487,23 +487,23 @@  discard block
 block discarded – undo
487 487
                     'discount'   => '',
488 488
                 );
489 489
             } else {
490
-                foreach ( $user_info as $key => $value ) {
491
-                    if ( ! empty( $value ) ) {
490
+                foreach ($user_info as $key => $value) {
491
+                    if (!empty($value)) {
492 492
                         continue;
493 493
                     }
494 494
 
495
-                    switch( $key ) {
495
+                    switch ($key) {
496 496
                         case 'user_id':
497
-                            $user_info[ $key ] = $user->ID;
497
+                            $user_info[$key] = $user->ID;
498 498
                             break;
499 499
                         case 'first_name':
500
-                            $user_info[ $key ] = $user->first_name;
500
+                            $user_info[$key] = $user->first_name;
501 501
                             break;
502 502
                         case 'last_name':
503
-                            $user_info[ $key ] = $user->last_name;
503
+                            $user_info[$key] = $user->last_name;
504 504
                             break;
505 505
                         case 'email':
506
-                            $user_info[ $key ] = $user->user_email;
506
+                            $user_info[$key] = $user->user_email;
507 507
                             break;
508 508
                     }
509 509
                 }
@@ -514,16 +514,16 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     private function setup_invoice_key() {
517
-        $key = $this->get_meta( '_wpinv_key', true );
517
+        $key = $this->get_meta('_wpinv_key', true);
518 518
         
519 519
         return $key;
520 520
     }
521 521
 
522 522
     private function setup_invoice_number() {
523
-        $number = $this->get_meta( '_wpinv_number', true );
523
+        $number = $this->get_meta('_wpinv_number', true);
524 524
 
525
-        if ( !$number ) {
526
-            $number = wpinv_format_invoice_number( $this->ID );
525
+        if (!$number) {
526
+            $number = wpinv_format_invoice_number($this->ID);
527 527
         }
528 528
 
529 529
         return $number;
@@ -534,18 +534,18 @@  discard block
 block discarded – undo
534 534
 
535 535
         if ($number = $this->get_number()) {
536 536
             $invoice_title = $number;
537
-        } else if ( ! empty( $this->ID ) ) {
538
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
537
+        } else if (!empty($this->ID)) {
538
+            $invoice_title = wpinv_format_invoice_number($this->ID);
539 539
         } else {
540
-            $invoice_title = wpinv_format_invoice_number( 0 );
540
+            $invoice_title = wpinv_format_invoice_number(0);
541 541
         }
542 542
 
543
-        if ( empty( $this->key ) ) {
543
+        if (empty($this->key)) {
544 544
             $this->key = self::generate_key();
545 545
             $this->pending['key'] = $this->key;
546 546
         }
547 547
 
548
-        if ( empty( $this->ip ) ) {
548
+        if (empty($this->ip)) {
549 549
             $this->ip = wpinv_get_ip();
550 550
             $this->pending['ip'] = $this->ip;
551 551
         }
@@ -577,75 +577,75 @@  discard block
 block discarded – undo
577 577
             'fees'         => $this->fees,
578 578
         );
579 579
         
580
-        $post_name      = sanitize_title( $invoice_title );
580
+        $post_name = sanitize_title($invoice_title);
581 581
 
582 582
         $post_data = array(
583 583
                         'post_title'    => $invoice_title,
584 584
                         'post_status'   => $this->status,
585 585
                         'post_author'   => $this->user_id,
586 586
                         'post_type'     => 'wpi_invoice',
587
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
588
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
587
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
588
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
589 589
                         'post_parent'   => $this->parent_invoice,
590 590
                     );
591
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
591
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
592 592
 
593 593
         // Create a blank invoice
594
-        if ( !empty( $this->ID ) ) {
594
+        if (!empty($this->ID)) {
595 595
             $args['ID']         = $this->ID;
596 596
             $args['post_name']  = $post_name;
597 597
             
598
-            $invoice_id = wp_update_post( $args );
598
+            $invoice_id = wp_update_post($args);
599 599
         } else {
600
-            $invoice_id = wp_insert_post( $args );
600
+            $invoice_id = wp_insert_post($args);
601 601
             
602
-            $post_title = wpinv_format_invoice_number( $invoice_id );
602
+            $post_title = wpinv_format_invoice_number($invoice_id);
603 603
             global $wpdb;
604
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
605
-            clean_post_cache( $invoice_id );
604
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
605
+            clean_post_cache($invoice_id);
606 606
         }
607 607
 
608
-        if ( !empty( $invoice_id ) ) {             
608
+        if (!empty($invoice_id)) {             
609 609
             $this->ID  = $invoice_id;
610 610
             $this->_ID = $invoice_id;
611 611
             
612 612
             ///$this->pending['user_id'] = $this->user_id;
613
-            if ( isset( $this->pending['number'] ) ) {
613
+            if (isset($this->pending['number'])) {
614 614
                 $this->pending['number'] = $post_name;
615 615
             }
616 616
             
617
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
618
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
619
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
620
-                foreach( $this->fees as $fee ) {
621
-                    $this->increase_fees( $fee['amount'] );
617
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
618
+            if (!empty($this->payment_meta['fees'])) {
619
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
620
+                foreach ($this->fees as $fee) {
621
+                    $this->increase_fees($fee['amount']);
622 622
                 }
623 623
             }
624 624
 
625
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
625
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
626 626
             $this->new = true;
627 627
         }
628 628
 
629 629
         return $this->ID;
630 630
     }
631 631
 
632
-    public function save( $setup = false ) {
632
+    public function save($setup = false) {
633 633
         global $wpi_session;
634 634
         
635 635
         $saved = false;
636
-        if ( empty( $this->items ) ) {
636
+        if (empty($this->items)) {
637 637
             return $saved; // Don't save empty invoice.
638 638
         }
639 639
         
640
-        if ( empty( $this->key ) ) {
640
+        if (empty($this->key)) {
641 641
             $this->key = self::generate_key();
642 642
             $this->pending['key'] = $this->key;
643 643
         }
644 644
         
645
-        if ( empty( $this->ID ) ) {
645
+        if (empty($this->ID)) {
646 646
             $invoice_id = $this->insert_invoice();
647 647
 
648
-            if ( false === $invoice_id ) {
648
+            if (false === $invoice_id) {
649 649
                 $saved = false;
650 650
             } else {
651 651
                 $this->ID = $invoice_id;
@@ -653,27 +653,27 @@  discard block
 block discarded – undo
653 653
         }        
654 654
 
655 655
         // If we have something pending, let's save it
656
-        if ( !empty( $this->pending ) ) {
656
+        if (!empty($this->pending)) {
657 657
             $total_increase = 0;
658 658
             $total_decrease = 0;
659 659
 
660
-            foreach ( $this->pending as $key => $value ) {
661
-                switch( $key ) {
660
+            foreach ($this->pending as $key => $value) {
661
+                switch ($key) {
662 662
                     case 'items':
663 663
                         // Update totals for pending items
664
-                        foreach ( $this->pending[ $key ] as $item ) {
665
-                            switch( $item['action'] ) {
664
+                        foreach ($this->pending[$key] as $item) {
665
+                            switch ($item['action']) {
666 666
                                 case 'add':
667 667
                                     $price = $item['price'];
668 668
                                     $taxes = $item['tax'];
669 669
 
670
-                                    if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) {
670
+                                    if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) {
671 671
                                         $total_increase += $price;
672 672
                                     }
673 673
                                     break;
674 674
 
675 675
                                 case 'remove':
676
-                                    if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) {
676
+                                    if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) {
677 677
                                         $total_decrease += $item['price'];
678 678
                                     }
679 679
                                     break;
@@ -681,16 +681,16 @@  discard block
 block discarded – undo
681 681
                         }
682 682
                         break;
683 683
                     case 'fees':
684
-                        if ( 'publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status ) {
684
+                        if ('publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status) {
685 685
                             break;
686 686
                         }
687 687
 
688
-                        if ( empty( $this->pending[ $key ] ) ) {
688
+                        if (empty($this->pending[$key])) {
689 689
                             break;
690 690
                         }
691 691
 
692
-                        foreach ( $this->pending[ $key ] as $fee ) {
693
-                            switch( $fee['action'] ) {
692
+                        foreach ($this->pending[$key] as $fee) {
693
+                            switch ($fee['action']) {
694 694
                                 case 'add':
695 695
                                     $total_increase += $fee['amount'];
696 696
                                     break;
@@ -702,86 +702,86 @@  discard block
 block discarded – undo
702 702
                         }
703 703
                         break;
704 704
                     case 'status':
705
-                        $this->update_status( $this->status );
705
+                        $this->update_status($this->status);
706 706
                         break;
707 707
                     case 'gateway':
708
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
708
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
709 709
                         break;
710 710
                     case 'mode':
711
-                        $this->update_meta( '_wpinv_mode', $this->mode );
711
+                        $this->update_meta('_wpinv_mode', $this->mode);
712 712
                         break;
713 713
                     case 'transaction_id':
714
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
714
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
715 715
                         break;
716 716
                     case 'ip':
717
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
717
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
718 718
                         break;
719 719
                     ///case 'user_id':
720 720
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
721 721
                         ///$this->user_info['user_id'] = $this->user_id;
722 722
                         ///break;
723 723
                     case 'first_name':
724
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
724
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
725 725
                         $this->user_info['first_name'] = $this->first_name;
726 726
                         break;
727 727
                     case 'last_name':
728
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
728
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
729 729
                         $this->user_info['last_name'] = $this->last_name;
730 730
                         break;
731 731
                     case 'phone':
732
-                        $this->update_meta( '_wpinv_phone', $this->phone );
732
+                        $this->update_meta('_wpinv_phone', $this->phone);
733 733
                         $this->user_info['phone'] = $this->phone;
734 734
                         break;
735 735
                     case 'address':
736
-                        $this->update_meta( '_wpinv_address', $this->address );
736
+                        $this->update_meta('_wpinv_address', $this->address);
737 737
                         $this->user_info['address'] = $this->address;
738 738
                         break;
739 739
                     case 'city':
740
-                        $this->update_meta( '_wpinv_city', $this->city );
740
+                        $this->update_meta('_wpinv_city', $this->city);
741 741
                         $this->user_info['city'] = $this->city;
742 742
                         break;
743 743
                     case 'country':
744
-                        $this->update_meta( '_wpinv_country', $this->country );
744
+                        $this->update_meta('_wpinv_country', $this->country);
745 745
                         $this->user_info['country'] = $this->country;
746 746
                         break;
747 747
                     case 'state':
748
-                        $this->update_meta( '_wpinv_state', $this->state );
748
+                        $this->update_meta('_wpinv_state', $this->state);
749 749
                         $this->user_info['state'] = $this->state;
750 750
                         break;
751 751
                     case 'zip':
752
-                        $this->update_meta( '_wpinv_zip', $this->zip );
752
+                        $this->update_meta('_wpinv_zip', $this->zip);
753 753
                         $this->user_info['zip'] = $this->zip;
754 754
                         break;
755 755
                     case 'company':
756
-                        $this->update_meta( '_wpinv_company', $this->company );
756
+                        $this->update_meta('_wpinv_company', $this->company);
757 757
                         $this->user_info['company'] = $this->company;
758 758
                         break;
759 759
                     case 'vat_number':
760
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
760
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
761 761
                         $this->user_info['vat_number'] = $this->vat_number;
762 762
                         
763
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
764
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
765
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
766
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
763
+                        $vat_info = $wpi_session->get('user_vat_data');
764
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
765
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
766
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
767 767
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
768 768
                         }
769 769
     
770 770
                         break;
771 771
                     case 'vat_rate':
772
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
772
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
773 773
                         $this->user_info['vat_rate'] = $this->vat_rate;
774 774
                         break;
775 775
                     case 'adddress_confirmed':
776
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
776
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
777 777
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
778 778
                         break;
779 779
                     
780 780
                     case 'key':
781
-                        $this->update_meta( '_wpinv_key', $this->key );
781
+                        $this->update_meta('_wpinv_key', $this->key);
782 782
                         break;
783 783
                     case 'number':
784
-                        $this->update_meta( '_wpinv_number', $this->number );
784
+                        $this->update_meta('_wpinv_number', $this->number);
785 785
                         break;
786 786
                     case 'date':
787 787
                         $args = array(
@@ -790,34 +790,34 @@  discard block
 block discarded – undo
790 790
                             'edit_date' => true,
791 791
                         );
792 792
 
793
-                        wp_update_post( $args );
793
+                        wp_update_post($args);
794 794
                         break;
795 795
                     case 'due_date':
796
-                        if ( empty( $this->due_date ) ) {
796
+                        if (empty($this->due_date)) {
797 797
                             $this->due_date = 'none';
798 798
                         }
799 799
                         
800
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
800
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
801 801
                         break;
802 802
                     case 'completed_date':
803
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
803
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
804 804
                         break;
805 805
                     case 'discounts':
806
-                        if ( ! is_array( $this->discounts ) ) {
807
-                            $this->discounts = explode( ',', $this->discounts );
806
+                        if (!is_array($this->discounts)) {
807
+                            $this->discounts = explode(',', $this->discounts);
808 808
                         }
809 809
 
810
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
810
+                        $this->user_info['discount'] = implode(',', $this->discounts);
811 811
                         break;
812 812
                         
813 813
                     //case 'tax':
814 814
                         //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
815 815
                         //break;
816 816
                     case 'discount':
817
-                        $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) );
817
+                        $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true));
818 818
                         break;
819 819
                     case 'discount_code':
820
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
820
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
821 821
                         break;
822 822
                     //case 'fees':
823 823
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -827,19 +827,19 @@  discard block
 block discarded – undo
827 827
                             'ID'          => $this->ID,
828 828
                             'post_parent' => $this->parent_invoice,
829 829
                         );
830
-                        wp_update_post( $args );
830
+                        wp_update_post($args);
831 831
                         break;
832 832
                     default:
833
-                        do_action( 'wpinv_save', $this, $key );
833
+                        do_action('wpinv_save', $this, $key);
834 834
                         break;
835 835
                 }
836 836
             }       
837 837
 
838
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
839
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
840
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
838
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
839
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
840
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
841 841
             
842
-            $this->items    = array_values( $this->items );
842
+            $this->items = array_values($this->items);
843 843
             
844 844
             $new_meta = array(
845 845
                 'items'         => $this->items,
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
             );
851 851
             
852 852
             $meta        = $this->get_meta();
853
-            $merged_meta = array_merge( $meta, $new_meta );
853
+            $merged_meta = array_merge($meta, $new_meta);
854 854
 
855 855
             // Only save the payment meta if it's changed
856
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
857
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
858
-                if ( false !== $updated ) {
856
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
857
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
858
+                if (false !== $updated) {
859 859
                     $saved = true;
860 860
                 }
861 861
             }
@@ -863,15 +863,15 @@  discard block
 block discarded – undo
863 863
             $this->pending = array();
864 864
             $saved         = true;
865 865
         } else {
866
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
867
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
868
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
866
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
867
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
868
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
869 869
         }
870 870
         
871
-        do_action( 'wpinv_invoice_save', $this, $saved );
871
+        do_action('wpinv_invoice_save', $this, $saved);
872 872
 
873
-        if ( true === $saved || $setup ) {
874
-            $this->setup_invoice( $this->ID );
873
+        if (true === $saved || $setup) {
874
+            $this->setup_invoice($this->ID);
875 875
         }
876 876
         
877 877
         $this->refresh_item_ids();
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
         return $saved;
880 880
     }
881 881
     
882
-    public function add_fee( $args, $global = true ) {
882
+    public function add_fee($args, $global = true) {
883 883
         $default_args = array(
884 884
             'label'       => '',
885 885
             'amount'      => 0,
@@ -889,75 +889,75 @@  discard block
 block discarded – undo
889 889
             'item_id'     => 0,
890 890
         );
891 891
 
892
-        $fee = wp_parse_args( $args, $default_args );
892
+        $fee = wp_parse_args($args, $default_args);
893 893
         
894
-        if ( !empty( $fee['label'] ) ) {
894
+        if (!empty($fee['label'])) {
895 895
             return false;
896 896
         }
897 897
         
898
-        $fee['id']  = sanitize_title( $fee['label'] );
898
+        $fee['id'] = sanitize_title($fee['label']);
899 899
         
900
-        $this->fees[]               = $fee;
900
+        $this->fees[] = $fee;
901 901
         
902 902
         $added_fee               = $fee;
903 903
         $added_fee['action']     = 'add';
904 904
         $this->pending['fees'][] = $added_fee;
905
-        reset( $this->fees );
905
+        reset($this->fees);
906 906
 
907
-        $this->increase_fees( $fee['amount'] );
907
+        $this->increase_fees($fee['amount']);
908 908
         return true;
909 909
     }
910 910
 
911
-    public function remove_fee( $key ) {
911
+    public function remove_fee($key) {
912 912
         $removed = false;
913 913
 
914
-        if ( is_numeric( $key ) ) {
915
-            $removed = $this->remove_fee_by( 'index', $key );
914
+        if (is_numeric($key)) {
915
+            $removed = $this->remove_fee_by('index', $key);
916 916
         }
917 917
 
918 918
         return $removed;
919 919
     }
920 920
 
921
-    public function remove_fee_by( $key, $value, $global = false ) {
922
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
921
+    public function remove_fee_by($key, $value, $global = false) {
922
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
923 923
             'index', 'label', 'amount', 'type',
924
-        ) );
924
+        ));
925 925
 
926
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
926
+        if (!in_array($key, $allowed_fee_keys)) {
927 927
             return false;
928 928
         }
929 929
 
930 930
         $removed = false;
931
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
932
-            $removed_fee             = $this->fees[ $value ];
931
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
932
+            $removed_fee             = $this->fees[$value];
933 933
             $removed_fee['action']   = 'remove';
934 934
             $this->pending['fees'][] = $removed_fee;
935 935
 
936
-            $this->decrease_fees( $removed_fee['amount'] );
936
+            $this->decrease_fees($removed_fee['amount']);
937 937
 
938
-            unset( $this->fees[ $value ] );
938
+            unset($this->fees[$value]);
939 939
             $removed = true;
940
-        } else if ( 'index' !== $key ) {
941
-            foreach ( $this->fees as $index => $fee ) {
942
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
940
+        } else if ('index' !== $key) {
941
+            foreach ($this->fees as $index => $fee) {
942
+                if (isset($fee[$key]) && $fee[$key] == $value) {
943 943
                     $removed_fee             = $fee;
944 944
                     $removed_fee['action']   = 'remove';
945 945
                     $this->pending['fees'][] = $removed_fee;
946 946
 
947
-                    $this->decrease_fees( $removed_fee['amount'] );
947
+                    $this->decrease_fees($removed_fee['amount']);
948 948
 
949
-                    unset( $this->fees[ $index ] );
949
+                    unset($this->fees[$index]);
950 950
                     $removed = true;
951 951
 
952
-                    if ( false === $global ) {
952
+                    if (false === $global) {
953 953
                         break;
954 954
                     }
955 955
                 }
956 956
             }
957 957
         }
958 958
 
959
-        if ( true === $removed ) {
960
-            $this->fees = array_values( $this->fees );
959
+        if (true === $removed) {
960
+            $this->fees = array_values($this->fees);
961 961
         }
962 962
 
963 963
         return $removed;
@@ -965,35 +965,35 @@  discard block
 block discarded – undo
965 965
 
966 966
     
967 967
 
968
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
968
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
969 969
         // Bail if no note specified
970
-        if( !$note ) {
970
+        if (!$note) {
971 971
             return false;
972 972
         }
973 973
 
974
-        if ( empty( $this->ID ) )
974
+        if (empty($this->ID))
975 975
             return false;
976 976
         
977
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
978
-            $user                 = get_user_by( 'id', get_current_user_id() );
977
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
978
+            $user                 = get_user_by('id', get_current_user_id());
979 979
             $comment_author       = $user->display_name;
980 980
             $comment_author_email = $user->user_email;
981 981
         } else {
982
-            $comment_author       = __( 'System', 'invoicing' );
983
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
984
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
985
-            $comment_author_email = sanitize_email( $comment_author_email );
982
+            $comment_author       = __('System', 'invoicing');
983
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
984
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
985
+            $comment_author_email = sanitize_email($comment_author_email);
986 986
         }
987 987
 
988
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
988
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
989 989
 
990
-        $note_id = wp_insert_comment( wp_filter_comment( array(
990
+        $note_id = wp_insert_comment(wp_filter_comment(array(
991 991
             'comment_post_ID'      => $this->ID,
992 992
             'comment_content'      => $note,
993 993
             'comment_agent'        => 'GeoDirectory',
994 994
             'user_id'              => is_admin() ? get_current_user_id() : 0,
995
-            'comment_date'         => current_time( 'mysql' ),
996
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
995
+            'comment_date'         => current_time('mysql'),
996
+            'comment_date_gmt'     => current_time('mysql', 1),
997 997
             'comment_approved'     => 1,
998 998
             'comment_parent'       => 0,
999 999
             'comment_author'       => $comment_author,
@@ -1001,53 +1001,53 @@  discard block
 block discarded – undo
1001 1001
             'comment_author_url'   => '',
1002 1002
             'comment_author_email' => $comment_author_email,
1003 1003
             'comment_type'         => 'wpinv_note'
1004
-        ) ) );
1004
+        )));
1005 1005
 
1006
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1006
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1007 1007
         
1008
-        if ( $customer_type ) {
1009
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1008
+        if ($customer_type) {
1009
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1010 1010
 
1011
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1011
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1012 1012
         }
1013 1013
 
1014 1014
         return $note_id;
1015 1015
     }
1016 1016
 
1017
-    private function increase_subtotal( $amount = 0.00 ) {
1018
-        $amount          = (float) $amount;
1017
+    private function increase_subtotal($amount = 0.00) {
1018
+        $amount          = (float)$amount;
1019 1019
         $this->subtotal += $amount;
1020
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1020
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1021 1021
 
1022 1022
         $this->recalculate_total();
1023 1023
     }
1024 1024
 
1025
-    private function decrease_subtotal( $amount = 0.00 ) {
1026
-        $amount          = (float) $amount;
1025
+    private function decrease_subtotal($amount = 0.00) {
1026
+        $amount          = (float)$amount;
1027 1027
         $this->subtotal -= $amount;
1028
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1028
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1029 1029
 
1030
-        if ( $this->subtotal < 0 ) {
1030
+        if ($this->subtotal < 0) {
1031 1031
             $this->subtotal = 0;
1032 1032
         }
1033 1033
 
1034 1034
         $this->recalculate_total();
1035 1035
     }
1036 1036
 
1037
-    private function increase_fees( $amount = 0.00 ) {
1037
+    private function increase_fees($amount = 0.00) {
1038 1038
         $amount            = (float)$amount;
1039 1039
         $this->fees_total += $amount;
1040
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1040
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1041 1041
 
1042 1042
         $this->recalculate_total();
1043 1043
     }
1044 1044
 
1045
-    private function decrease_fees( $amount = 0.00 ) {
1046
-        $amount            = (float) $amount;
1045
+    private function decrease_fees($amount = 0.00) {
1046
+        $amount            = (float)$amount;
1047 1047
         $this->fees_total -= $amount;
1048
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1048
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1049 1049
 
1050
-        if ( $this->fees_total < 0 ) {
1050
+        if ($this->fees_total < 0) {
1051 1051
             $this->fees_total = 0;
1052 1052
         }
1053 1053
 
@@ -1058,54 +1058,54 @@  discard block
 block discarded – undo
1058 1058
         global $wpi_nosave;
1059 1059
         
1060 1060
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1061
-        $this->total = wpinv_format_amount( $this->total, NULL, true );
1061
+        $this->total = wpinv_format_amount($this->total, NULL, true);
1062 1062
         
1063
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1063
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1064 1064
     }
1065 1065
     
1066
-    public function increase_tax( $amount = 0.00 ) {
1067
-        $amount       = (float) $amount;
1066
+    public function increase_tax($amount = 0.00) {
1067
+        $amount       = (float)$amount;
1068 1068
         $this->tax   += $amount;
1069 1069
 
1070 1070
         $this->recalculate_total();
1071 1071
     }
1072 1072
 
1073
-    public function decrease_tax( $amount = 0.00 ) {
1074
-        $amount     = (float) $amount;
1073
+    public function decrease_tax($amount = 0.00) {
1074
+        $amount     = (float)$amount;
1075 1075
         $this->tax -= $amount;
1076 1076
 
1077
-        if ( $this->tax < 0 ) {
1077
+        if ($this->tax < 0) {
1078 1078
             $this->tax = 0;
1079 1079
         }
1080 1080
 
1081 1081
         $this->recalculate_total();
1082 1082
     }
1083 1083
 
1084
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1085
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1084
+    public function update_status($new_status = false, $note = '', $manual = false) {
1085
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1086 1086
         
1087
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1087
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1088 1088
             return false; // Don't permit status changes that aren't changes
1089 1089
         }
1090 1090
 
1091
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1091
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1092 1092
         $updated = false;
1093 1093
 
1094
-        if ( $do_change ) {
1095
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1094
+        if ($do_change) {
1095
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1096 1096
 
1097 1097
             $update_post_data                   = array();
1098 1098
             $update_post_data['ID']             = $this->ID;
1099 1099
             $update_post_data['post_status']    = $new_status;
1100
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1101
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1100
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1101
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1102 1102
             
1103
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1103
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1104 1104
 
1105
-            $updated = wp_update_post( $update_post_data );     
1105
+            $updated = wp_update_post($update_post_data);     
1106 1106
            
1107 1107
             // Process any specific status functions
1108
-            switch( $new_status ) {
1108
+            switch ($new_status) {
1109 1109
                 case 'refunded':
1110 1110
                     $this->process_refund();
1111 1111
                     break;
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
             }
1119 1119
             
1120 1120
             // Status was changed.
1121
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1122
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1123
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1121
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1122
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1123
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1124 1124
         }
1125 1125
 
1126 1126
         return $updated;
@@ -1134,72 +1134,72 @@  discard block
 block discarded – undo
1134 1134
         $this->save();
1135 1135
     }
1136 1136
 
1137
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1138
-        if ( empty( $meta_key ) ) {
1137
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1138
+        if (empty($meta_key)) {
1139 1139
             return false;
1140 1140
         }
1141 1141
 
1142
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1142
+        if ($meta_key == 'key' || $meta_key == 'date') {
1143 1143
             $current_meta = $this->get_meta();
1144
-            $current_meta[ $meta_key ] = $meta_value;
1144
+            $current_meta[$meta_key] = $meta_value;
1145 1145
 
1146 1146
             $meta_key     = '_wpinv_payment_meta';
1147 1147
             $meta_value   = $current_meta;
1148 1148
         }
1149 1149
 
1150
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1150
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1151 1151
         
1152
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1152
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1153 1153
             $args = array(
1154 1154
                 'ID'                => $this->ID,
1155 1155
                 'post_date'         => $meta_value,
1156 1156
                 'edit_date'         => true,
1157
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1157
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1158 1158
                 'post_modified'     => $meta_value,
1159
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1159
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1160 1160
             );
1161
-            wp_update_post( $args );
1161
+            wp_update_post($args);
1162 1162
         }
1163 1163
         
1164
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1164
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1165 1165
     }
1166 1166
 
1167 1167
     private function process_refund() {
1168 1168
         $process_refund = true;
1169 1169
 
1170 1170
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1171
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'refunded' != $this->status ) {
1171
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'refunded' != $this->status) {
1172 1172
             $process_refund = false;
1173 1173
         }
1174 1174
 
1175 1175
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1176
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1176
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1177 1177
 
1178
-        if ( false === $process_refund ) {
1178
+        if (false === $process_refund) {
1179 1179
             return;
1180 1180
         }
1181 1181
 
1182
-        do_action( 'wpinv_pre_refund_invoice', $this );
1182
+        do_action('wpinv_pre_refund_invoice', $this);
1183 1183
         
1184
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1185
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1186
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1184
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1185
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1186
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1187 1187
         
1188
-        do_action( 'wpinv_post_refund_invoice', $this );
1188
+        do_action('wpinv_post_refund_invoice', $this);
1189 1189
     }
1190 1190
 
1191 1191
     private function process_failure() {
1192 1192
         $discounts = $this->discounts;
1193
-        if ( empty( $discounts ) ) {
1193
+        if (empty($discounts)) {
1194 1194
             return;
1195 1195
         }
1196 1196
 
1197
-        if ( ! is_array( $discounts ) ) {
1198
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1197
+        if (!is_array($discounts)) {
1198
+            $discounts = array_map('trim', explode(',', $discounts));
1199 1199
         }
1200 1200
 
1201
-        foreach ( $discounts as $discount ) {
1202
-            wpinv_decrease_discount_usage( $discount );
1201
+        foreach ($discounts as $discount) {
1202
+            wpinv_decrease_discount_usage($discount);
1203 1203
         }
1204 1204
     }
1205 1205
     
@@ -1207,92 +1207,92 @@  discard block
 block discarded – undo
1207 1207
         $process_pending = true;
1208 1208
 
1209 1209
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1210
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1210
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1211 1211
             $process_pending = false;
1212 1212
         }
1213 1213
 
1214 1214
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1215
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1215
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1216 1216
 
1217
-        if ( false === $process_pending ) {
1217
+        if (false === $process_pending) {
1218 1218
             return;
1219 1219
         }
1220 1220
 
1221
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1222
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1223
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1221
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1222
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1223
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1224 1224
 
1225 1225
         $this->completed_date = '';
1226
-        $this->update_meta( '_wpinv_completed_date', '' );
1226
+        $this->update_meta('_wpinv_completed_date', '');
1227 1227
     }
1228 1228
     
1229 1229
     // get data
1230
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1231
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1230
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1231
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1232 1232
 
1233
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1233
+        if ($meta_key === '_wpinv_payment_meta') {
1234 1234
 
1235
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1235
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1236 1236
 
1237
-            if ( empty( $meta['key'] ) ) {
1237
+            if (empty($meta['key'])) {
1238 1238
                 $meta['key'] = $this->setup_invoice_key();
1239 1239
             }
1240 1240
 
1241
-            if ( empty( $meta['date'] ) ) {
1242
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1241
+            if (empty($meta['date'])) {
1242
+                $meta['date'] = get_post_field('post_date', $this->ID);
1243 1243
             }
1244 1244
         }
1245 1245
 
1246
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1246
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1247 1247
 
1248
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1248
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1249 1249
     }
1250 1250
     
1251 1251
     public function get_description() {
1252
-        $post = get_post( $this->ID );
1252
+        $post = get_post($this->ID);
1253 1253
         
1254
-        $description = !empty( $post ) ? $post->post_content : '';
1255
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1254
+        $description = !empty($post) ? $post->post_content : '';
1255
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1256 1256
     }
1257 1257
     
1258
-    public function get_status( $nicename = false ) {
1259
-        if ( !$nicename ) {
1258
+    public function get_status($nicename = false) {
1259
+        if (!$nicename) {
1260 1260
             $status = $this->status;
1261 1261
         } else {
1262 1262
             $status = $this->status_nicename;
1263 1263
         }
1264 1264
         
1265
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1265
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1266 1266
     }
1267 1267
     
1268 1268
     public function get_cart_details() {
1269
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1269
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1270 1270
     }
1271 1271
     
1272
-    public function get_subtotal( $currency = false ) {
1273
-        $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency );
1272
+    public function get_subtotal($currency = false) {
1273
+        $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency);
1274 1274
         
1275
-        if ( $currency ) {
1276
-            $subtotal = wpinv_price( $subtotal, $this->get_currency() );
1275
+        if ($currency) {
1276
+            $subtotal = wpinv_price($subtotal, $this->get_currency());
1277 1277
         }
1278 1278
         
1279
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1279
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1280 1280
     }
1281 1281
     
1282
-    public function get_total( $currency = false ) {        
1283
-        if ( $this->is_free_trial() ) {
1284
-            $total = wpinv_format_amount( 0, NULL, !$currency );
1282
+    public function get_total($currency = false) {        
1283
+        if ($this->is_free_trial()) {
1284
+            $total = wpinv_format_amount(0, NULL, !$currency);
1285 1285
         } else {
1286
-            $total = wpinv_format_amount( $this->total, NULL, !$currency );
1286
+            $total = wpinv_format_amount($this->total, NULL, !$currency);
1287 1287
         }
1288
-        if ( $currency ) {
1289
-            $total = wpinv_price( $total, $this->get_currency() );
1288
+        if ($currency) {
1289
+            $total = wpinv_price($total, $this->get_currency());
1290 1290
         }
1291 1291
         
1292
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1292
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1293 1293
     }
1294 1294
     
1295
-    public function get_recurring_details( $field = '', $currency = false ) {        
1295
+    public function get_recurring_details($field = '', $currency = false) {        
1296 1296
         $data                 = array();
1297 1297
         $data['cart_details'] = $this->cart_details;
1298 1298
         $data['subtotal']     = $this->get_subtotal();
@@ -1300,45 +1300,45 @@  discard block
 block discarded – undo
1300 1300
         $data['tax']          = $this->get_tax();
1301 1301
         $data['total']        = $this->get_total();
1302 1302
     
1303
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1303
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1304 1304
             $is_free_trial = $this->is_free_trial();
1305
-            $discounts = $this->get_discounts( true );
1305
+            $discounts = $this->get_discounts(true);
1306 1306
             
1307
-            if ( $is_free_trial || !empty( $discounts ) ) {
1307
+            if ($is_free_trial || !empty($discounts)) {
1308 1308
                 $first_use_only = false;
1309 1309
                 
1310
-                if ( !empty( $discounts ) ) {
1311
-                    foreach ( $discounts as $key => $code ) {
1312
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1310
+                if (!empty($discounts)) {
1311
+                    foreach ($discounts as $key => $code) {
1312
+                        if (wpinv_discount_is_recurring($code, true)) {
1313 1313
                             $first_use_only = true;
1314 1314
                             break;
1315 1315
                         }
1316 1316
                     }
1317 1317
                 }
1318 1318
                     
1319
-                if ( !$first_use_only ) {
1320
-                    $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true );
1321
-                    $data['discount'] = wpinv_format_amount( $this->discount, NULL, true );
1322
-                    $data['tax']      = wpinv_format_amount( $this->tax, NULL, true );
1323
-                    $data['total']    = wpinv_format_amount( $this->total, NULL, true );
1319
+                if (!$first_use_only) {
1320
+                    $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true);
1321
+                    $data['discount'] = wpinv_format_amount($this->discount, NULL, true);
1322
+                    $data['tax']      = wpinv_format_amount($this->tax, NULL, true);
1323
+                    $data['total']    = wpinv_format_amount($this->total, NULL, true);
1324 1324
                 } else {
1325 1325
                     $cart_subtotal   = 0;
1326 1326
                     $cart_discount   = 0;
1327 1327
                     $cart_tax        = 0;
1328 1328
 
1329
-                    foreach ( $this->cart_details as $key => $item ) {
1330
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1331
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1329
+                    foreach ($this->cart_details as $key => $item) {
1330
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1331
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1332 1332
                         $item_discount  = 0;
1333
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1333
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1334 1334
                         
1335
-                        if ( wpinv_prices_include_tax() ) {
1336
-                            $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true );
1335
+                        if (wpinv_prices_include_tax()) {
1336
+                            $item_subtotal -= wpinv_format_amount($item_tax, NULL, true);
1337 1337
                         }
1338 1338
                         
1339 1339
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1340 1340
                         // Do not allow totals to go negative
1341
-                        if ( $item_total < 0 ) {
1341
+                        if ($item_total < 0) {
1342 1342
                             $item_total = 0;
1343 1343
                         }
1344 1344
                         
@@ -1346,107 +1346,107 @@  discard block
 block discarded – undo
1346 1346
                         $cart_discount  += (float)($item_discount);
1347 1347
                         $cart_tax       += (float)($item_tax);
1348 1348
                         
1349
-                        $data['cart_details'][$key]['discount']   = wpinv_format_amount( $item_discount, NULL, true );
1350
-                        $data['cart_details'][$key]['tax']        = wpinv_format_amount( $item_tax, NULL, true );
1351
-                        $data['cart_details'][$key]['price']      = wpinv_format_amount( $item_total, NULL, true );
1349
+                        $data['cart_details'][$key]['discount']   = wpinv_format_amount($item_discount, NULL, true);
1350
+                        $data['cart_details'][$key]['tax']        = wpinv_format_amount($item_tax, NULL, true);
1351
+                        $data['cart_details'][$key]['price']      = wpinv_format_amount($item_total, NULL, true);
1352 1352
                     }
1353 1353
                     
1354
-                    $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true );
1355
-                    $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true );
1356
-                    $data['tax']      = wpinv_format_amount( $cart_tax, NULL, true );
1357
-                    $data['total']    = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true );
1354
+                    $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true);
1355
+                    $data['discount'] = wpinv_format_amount($cart_discount, NULL, true);
1356
+                    $data['tax']      = wpinv_format_amount($cart_tax, NULL, true);
1357
+                    $data['total']    = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true);
1358 1358
                 }
1359 1359
             }
1360 1360
         }
1361 1361
         
1362
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1362
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1363 1363
 
1364
-        if ( isset( $data[$field] ) ) {
1365
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1364
+        if (isset($data[$field])) {
1365
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1366 1366
         }
1367 1367
         
1368 1368
         return $data;
1369 1369
     }
1370 1370
     
1371
-    public function get_final_tax( $currency = false ) {        
1372
-        $final_total = wpinv_format_amount( $this->tax, NULL, !$currency );
1373
-        if ( $currency ) {
1374
-            $final_total = wpinv_price( $final_total, $this->get_currency() );
1371
+    public function get_final_tax($currency = false) {        
1372
+        $final_total = wpinv_format_amount($this->tax, NULL, !$currency);
1373
+        if ($currency) {
1374
+            $final_total = wpinv_price($final_total, $this->get_currency());
1375 1375
         }
1376 1376
         
1377
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1377
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1378 1378
     }
1379 1379
     
1380
-    public function get_discounts( $array = false ) {
1380
+    public function get_discounts($array = false) {
1381 1381
         $discounts = $this->discounts;
1382
-        if ( $array && $discounts ) {
1383
-            $discounts = explode( ',', $discounts );
1382
+        if ($array && $discounts) {
1383
+            $discounts = explode(',', $discounts);
1384 1384
         }
1385
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1385
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1386 1386
     }
1387 1387
     
1388
-    public function get_discount( $currency = false, $dash = false ) {
1389
-        if ( !empty( $this->discounts ) ) {
1388
+    public function get_discount($currency = false, $dash = false) {
1389
+        if (!empty($this->discounts)) {
1390 1390
             global $ajax_cart_details;
1391 1391
             $ajax_cart_details = $this->get_cart_details();
1392 1392
 
1393
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1393
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1394 1394
         }
1395
-        $discount   = wpinv_format_amount( $this->discount, NULL, !$currency );
1395
+        $discount   = wpinv_format_amount($this->discount, NULL, !$currency);
1396 1396
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1397 1397
         
1398
-        if ( $currency ) {
1399
-            $discount = wpinv_price( $discount, $this->get_currency() );
1398
+        if ($currency) {
1399
+            $discount = wpinv_price($discount, $this->get_currency());
1400 1400
         }
1401 1401
         
1402
-        $discount   = $dash . $discount;
1402
+        $discount = $dash . $discount;
1403 1403
         
1404
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1404
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1405 1405
     }
1406 1406
     
1407 1407
     public function get_discount_code() {
1408 1408
         return $this->discount_code;
1409 1409
     }
1410 1410
     
1411
-    public function get_tax( $currency = false ) {
1412
-        $tax = wpinv_format_amount( $this->tax, NULL, !$currency );
1411
+    public function get_tax($currency = false) {
1412
+        $tax = wpinv_format_amount($this->tax, NULL, !$currency);
1413 1413
         
1414
-        if ( $currency ) {
1415
-            $tax = wpinv_price( $tax, $this->get_currency() );
1414
+        if ($currency) {
1415
+            $tax = wpinv_price($tax, $this->get_currency());
1416 1416
         }
1417 1417
         
1418
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1418
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1419 1419
     }
1420 1420
     
1421
-    public function get_fees( $type = 'all' ) {
1422
-        $fees    = array();
1421
+    public function get_fees($type = 'all') {
1422
+        $fees = array();
1423 1423
 
1424
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1425
-            foreach ( $this->fees as $fee ) {
1426
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1424
+        if (!empty($this->fees) && is_array($this->fees)) {
1425
+            foreach ($this->fees as $fee) {
1426
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1427 1427
                     continue;
1428 1428
                 }
1429 1429
 
1430
-                $fee['label'] = stripslashes( $fee['label'] );
1431
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1432
-                $fees[]    = $fee;
1430
+                $fee['label'] = stripslashes($fee['label']);
1431
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1432
+                $fees[] = $fee;
1433 1433
             }
1434 1434
         }
1435 1435
 
1436
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1436
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1437 1437
     }
1438 1438
     
1439
-    public function get_fees_total( $type = 'all' ) {
1440
-        $fees_total = (float) 0.00;
1439
+    public function get_fees_total($type = 'all') {
1440
+        $fees_total = (float)0.00;
1441 1441
 
1442
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1443
-        if ( ! empty( $payment_fees ) ) {
1444
-            foreach ( $payment_fees as $fee ) {
1445
-                $fees_total += (float) $fee['amount'];
1442
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1443
+        if (!empty($payment_fees)) {
1444
+            foreach ($payment_fees as $fee) {
1445
+                $fees_total += (float)$fee['amount'];
1446 1446
             }
1447 1447
         }
1448 1448
 
1449
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1449
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1450 1450
         /*
1451 1451
         $fees = $this->get_fees( $type );
1452 1452
 
@@ -1466,116 +1466,116 @@  discard block
 block discarded – undo
1466 1466
     }
1467 1467
 
1468 1468
     public function get_user_id() {
1469
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1469
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1470 1470
     }
1471 1471
     
1472 1472
     public function get_first_name() {
1473
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1473
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1474 1474
     }
1475 1475
     
1476 1476
     public function get_last_name() {
1477
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1477
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1478 1478
     }
1479 1479
     
1480 1480
     public function get_user_full_name() {
1481
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1481
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1482 1482
     }
1483 1483
     
1484 1484
     public function get_user_info() {
1485
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1485
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1486 1486
     }
1487 1487
     
1488 1488
     public function get_email() {
1489
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1489
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1490 1490
     }
1491 1491
     
1492 1492
     public function get_address() {
1493
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1493
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1494 1494
     }
1495 1495
     
1496 1496
     public function get_phone() {
1497
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1497
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1498 1498
     }
1499 1499
     
1500 1500
     public function get_number() {
1501
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1501
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1502 1502
     }
1503 1503
     
1504 1504
     public function get_items() {
1505
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1505
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1506 1506
     }
1507 1507
     
1508 1508
     public function get_key() {
1509
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1509
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1510 1510
     }
1511 1511
     
1512 1512
     public function get_transaction_id() {
1513
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1513
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1514 1514
     }
1515 1515
     
1516 1516
     public function get_gateway() {
1517
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1517
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1518 1518
     }
1519 1519
     
1520 1520
     public function get_gateway_title() {
1521
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1521
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1522 1522
         
1523
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1523
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1524 1524
     }
1525 1525
     
1526 1526
     public function get_currency() {
1527
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1527
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1528 1528
     }
1529 1529
     
1530 1530
     public function get_created_date() {
1531
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1531
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1532 1532
     }
1533 1533
     
1534
-    public function get_due_date( $display = false ) {
1535
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1534
+    public function get_due_date($display = false) {
1535
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1536 1536
         
1537
-        if ( !$display || empty( $due_date ) ) {
1537
+        if (!$display || empty($due_date)) {
1538 1538
             return $due_date;
1539 1539
         }
1540 1540
         
1541
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1541
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1542 1542
     }
1543 1543
     
1544 1544
     public function get_completed_date() {
1545
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1545
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1546 1546
     }
1547 1547
     
1548
-    public function get_invoice_date( $formatted = true ) {
1548
+    public function get_invoice_date($formatted = true) {
1549 1549
         $date_completed = $this->completed_date;
1550 1550
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1551 1551
         
1552
-        if ( $invoice_date == '' ) {
1552
+        if ($invoice_date == '') {
1553 1553
             $date_created   = $this->date;
1554 1554
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1555 1555
         }
1556 1556
         
1557
-        if ( $formatted && $invoice_date ) {
1558
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1557
+        if ($formatted && $invoice_date) {
1558
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1559 1559
         }
1560 1560
 
1561
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1561
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1562 1562
     }
1563 1563
     
1564 1564
     public function get_ip() {
1565
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1565
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1566 1566
     }
1567 1567
         
1568
-    public function has_status( $status ) {
1569
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1568
+    public function has_status($status) {
1569
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1570 1570
     }
1571 1571
     
1572
-    public function add_item( $item_id = 0, $args = array() ) {
1572
+    public function add_item($item_id = 0, $args = array()) {
1573 1573
         global $wpi_current_id, $wpi_item_id;
1574 1574
         
1575
-        $item = new WPInv_Item( $item_id );
1575
+        $item = new WPInv_Item($item_id);
1576 1576
 
1577 1577
         // Bail if this post isn't a item
1578
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1578
+        if (!$item || $item->post_type !== 'wpi_item') {
1579 1579
             return false;
1580 1580
         }
1581 1581
         
@@ -1593,8 +1593,8 @@  discard block
 block discarded – undo
1593 1593
             'fees'      => array()
1594 1594
         );
1595 1595
 
1596
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1597
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1596
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1597
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1598 1598
 
1599 1599
         $wpi_current_id         = $this->ID;
1600 1600
         $wpi_item_id            = $item->ID;
@@ -1606,19 +1606,19 @@  discard block
 block discarded – undo
1606 1606
         $found_cart_key         = false;
1607 1607
         
1608 1608
         if ($has_quantities) {
1609
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1609
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1610 1610
             
1611
-            foreach ( $this->items as $key => $cart_item ) {
1612
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1611
+            foreach ($this->items as $key => $cart_item) {
1612
+                if ((int)$item_id !== (int)$cart_item['id']) {
1613 1613
                     continue;
1614 1614
                 }
1615 1615
 
1616
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1616
+                $this->items[$key]['quantity'] += $args['quantity'];
1617 1617
                 break;
1618 1618
             }
1619 1619
             
1620
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1621
-                if ( $item_id != $cart_item['id'] ) {
1620
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1621
+                if ($item_id != $cart_item['id']) {
1622 1622
                     continue;
1623 1623
                 }
1624 1624
 
@@ -1630,29 +1630,29 @@  discard block
 block discarded – undo
1630 1630
         if ($has_quantities && $found_cart_key !== false) {
1631 1631
             $cart_item          = $this->cart_details[$found_cart_key];
1632 1632
             $item_price         = $cart_item['item_price'];
1633
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1634
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1633
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1634
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1635 1635
             
1636 1636
             $new_quantity       = $quantity + $args['quantity'];
1637 1637
             $subtotal           = $item_price * $new_quantity;
1638 1638
             
1639 1639
             $args['quantity']   = $new_quantity;
1640
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1641
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1640
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1641
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1642 1642
             
1643 1643
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1644 1644
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1645 1645
             // The total increase equals the number removed * the item_price
1646
-            $total_increased    = wpinv_format_amount( $item_price, NULL, true );
1646
+            $total_increased    = wpinv_format_amount($item_price, NULL, true);
1647 1647
             
1648
-            if ( wpinv_prices_include_tax() ) {
1649
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1648
+            if (wpinv_prices_include_tax()) {
1649
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1650 1650
             }
1651 1651
 
1652
-            $total              = $subtotal - $discount + $tax;
1652
+            $total = $subtotal - $discount + $tax;
1653 1653
 
1654 1654
             // Do not allow totals to go negative
1655
-            if( $total < 0 ) {
1655
+            if ($total < 0) {
1656 1656
                 $total = 0;
1657 1657
             }
1658 1658
             
@@ -1668,20 +1668,20 @@  discard block
 block discarded – undo
1668 1668
             $this->cart_details[$found_cart_key] = $cart_item;
1669 1669
         } else {
1670 1670
             // Allow overriding the price
1671
-            if( false !== $args['item_price'] ) {
1671
+            if (false !== $args['item_price']) {
1672 1672
                 $item_price = $args['item_price'];
1673 1673
             } else {
1674
-                $item_price = wpinv_get_item_price( $item->ID );
1674
+                $item_price = wpinv_get_item_price($item->ID);
1675 1675
             }
1676 1676
 
1677 1677
             // Sanitizing the price here so we don't have a dozen calls later
1678
-            $item_price = wpinv_sanitize_amount( $item_price );
1679
-            $subtotal   = wpinv_format_amount( $item_price * $args['quantity'], NULL, true );
1678
+            $item_price = wpinv_sanitize_amount($item_price);
1679
+            $subtotal   = wpinv_format_amount($item_price * $args['quantity'], NULL, true);
1680 1680
         
1681
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1682
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1683
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1684
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1681
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1682
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1683
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1684
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1685 1685
 
1686 1686
             // Setup the items meta item
1687 1687
             $new_item = array(
@@ -1689,28 +1689,28 @@  discard block
 block discarded – undo
1689 1689
                 'quantity' => $args['quantity'],
1690 1690
             );
1691 1691
 
1692
-            $this->items[]  = $new_item;
1692
+            $this->items[] = $new_item;
1693 1693
 
1694
-            if ( wpinv_prices_include_tax() ) {
1695
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1694
+            if (wpinv_prices_include_tax()) {
1695
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1696 1696
             }
1697 1697
 
1698
-            $total      = $subtotal - $discount + $tax;
1698
+            $total = $subtotal - $discount + $tax;
1699 1699
 
1700 1700
             // Do not allow totals to go negative
1701
-            if( $total < 0 ) {
1701
+            if ($total < 0) {
1702 1702
                 $total = 0;
1703 1703
             }
1704 1704
         
1705 1705
             $this->cart_details[] = array(
1706 1706
                 'name'        => !empty($args['name']) ? $args['name'] : $item->get_name(),
1707 1707
                 'id'          => $item->ID,
1708
-                'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1708
+                'item_price'  => wpinv_format_amount($item_price, NULL, true),
1709 1709
                 'quantity'    => $args['quantity'],
1710 1710
                 'discount'    => $discount,
1711
-                'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1712
-                'tax'         => wpinv_format_amount( $tax, NULL, true ),
1713
-                'price'       => wpinv_format_amount( $total, NULL, true ),
1711
+                'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1712
+                'tax'         => wpinv_format_amount($tax, NULL, true),
1713
+                'price'       => wpinv_format_amount($total, NULL, true),
1714 1714
                 'vat_rate'    => $tax_rate,
1715 1715
                 'vat_class'   => $tax_class,
1716 1716
                 'meta'        => $args['meta'],
@@ -1720,69 +1720,69 @@  discard block
 block discarded – undo
1720 1720
             $subtotal = $subtotal - $discount;
1721 1721
         }
1722 1722
         
1723
-        $added_item = end( $this->cart_details );
1724
-        $added_item['action']  = 'add';
1723
+        $added_item = end($this->cart_details);
1724
+        $added_item['action'] = 'add';
1725 1725
         
1726 1726
         $this->pending['items'][] = $added_item;
1727 1727
         
1728
-        $this->increase_subtotal( $subtotal );
1729
-        $this->increase_tax( $tax );
1728
+        $this->increase_subtotal($subtotal);
1729
+        $this->increase_tax($tax);
1730 1730
 
1731 1731
         return true;
1732 1732
     }
1733 1733
     
1734
-    public function remove_item( $item_id, $args = array() ) {
1734
+    public function remove_item($item_id, $args = array()) {
1735 1735
         // Set some defaults
1736 1736
         $defaults = array(
1737 1737
             'quantity'   => 1,
1738 1738
             'item_price' => false,
1739 1739
             'cart_index' => false,
1740 1740
         );
1741
-        $args = wp_parse_args( $args, $defaults );
1741
+        $args = wp_parse_args($args, $defaults);
1742 1742
 
1743 1743
         // Bail if this post isn't a item
1744
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1744
+        if (get_post_type($item_id) !== 'wpi_item') {
1745 1745
             return false;
1746 1746
         }
1747 1747
         
1748
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1748
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1749 1749
 
1750
-        foreach ( $this->items as $key => $item ) {
1751
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1750
+        foreach ($this->items as $key => $item) {
1751
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1752 1752
                 continue;
1753 1753
             }
1754 1754
 
1755
-            if ( false !== $args['cart_index'] ) {
1756
-                $cart_index = absint( $args['cart_index'] );
1757
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1755
+            if (false !== $args['cart_index']) {
1756
+                $cart_index = absint($args['cart_index']);
1757
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1758 1758
 
1759
-                if ( ! empty( $cart_item ) ) {
1759
+                if (!empty($cart_item)) {
1760 1760
                     // If the cart index item isn't the same item ID, don't remove it
1761
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1761
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1762 1762
                         continue;
1763 1763
                     }
1764 1764
                 }
1765 1765
             }
1766 1766
 
1767
-            $item_quantity = $this->items[ $key ]['quantity'];
1768
-            if ( $item_quantity > $args['quantity'] ) {
1769
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1767
+            $item_quantity = $this->items[$key]['quantity'];
1768
+            if ($item_quantity > $args['quantity']) {
1769
+                $this->items[$key]['quantity'] -= $args['quantity'];
1770 1770
                 break;
1771 1771
             } else {
1772
-                unset( $this->items[ $key ] );
1772
+                unset($this->items[$key]);
1773 1773
                 break;
1774 1774
             }
1775 1775
         }
1776 1776
 
1777 1777
         $found_cart_key = false;
1778
-        if ( false === $args['cart_index'] ) {
1779
-            foreach ( $this->cart_details as $cart_key => $item ) {
1780
-                if ( $item_id != $item['id'] ) {
1778
+        if (false === $args['cart_index']) {
1779
+            foreach ($this->cart_details as $cart_key => $item) {
1780
+                if ($item_id != $item['id']) {
1781 1781
                     continue;
1782 1782
                 }
1783 1783
 
1784
-                if ( false !== $args['item_price'] ) {
1785
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1784
+                if (false !== $args['item_price']) {
1785
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1786 1786
                         continue;
1787 1787
                     }
1788 1788
                 }
@@ -1791,13 +1791,13 @@  discard block
 block discarded – undo
1791 1791
                 break;
1792 1792
             }
1793 1793
         } else {
1794
-            $cart_index = absint( $args['cart_index'] );
1794
+            $cart_index = absint($args['cart_index']);
1795 1795
 
1796
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1796
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1797 1797
                 return false; // Invalid cart index passed.
1798 1798
             }
1799 1799
 
1800
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1800
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1801 1801
                 return false; // We still need the proper Item ID to be sure.
1802 1802
             }
1803 1803
 
@@ -1805,41 +1805,41 @@  discard block
 block discarded – undo
1805 1805
         }
1806 1806
         
1807 1807
         $cart_item  = $this->cart_details[$found_cart_key];
1808
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1808
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1809 1809
         
1810
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1810
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1811 1811
             return false; // Invoice must contain at least one item.
1812 1812
         }
1813 1813
         
1814
-        $discounts  = $this->get_discounts();
1814
+        $discounts = $this->get_discounts();
1815 1815
         
1816
-        if ( $quantity > $args['quantity'] ) {
1816
+        if ($quantity > $args['quantity']) {
1817 1817
             $item_price         = $cart_item['item_price'];
1818
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1818
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1819 1819
             
1820
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1820
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1821 1821
             $subtotal           = $item_price * $new_quantity;
1822 1822
             
1823 1823
             $args['quantity']   = $new_quantity;
1824
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1825
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1824
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1825
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1826 1826
             
1827
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0;
1827
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0;
1828 1828
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1829
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0;
1829
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0;
1830 1830
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1831 1831
             
1832 1832
             // The total increase equals the number removed * the item_price
1833
-            $total_decrease     = wpinv_format_amount( $item_price, NULL, true );
1833
+            $total_decrease     = wpinv_format_amount($item_price, NULL, true);
1834 1834
             
1835
-            if ( wpinv_prices_include_tax() ) {
1836
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1835
+            if (wpinv_prices_include_tax()) {
1836
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1837 1837
             }
1838 1838
 
1839
-            $total              = $subtotal - $discount + $tax;
1839
+            $total = $subtotal - $discount + $tax;
1840 1840
 
1841 1841
             // Do not allow totals to go negative
1842
-            if( $total < 0 ) {
1842
+            if ($total < 0) {
1843 1843
                 $total = 0;
1844 1844
             }
1845 1845
             
@@ -1858,16 +1858,16 @@  discard block
 block discarded – undo
1858 1858
             
1859 1859
             $this->cart_details[$found_cart_key] = $cart_item;
1860 1860
             
1861
-            $remove_item = end( $this->cart_details );
1861
+            $remove_item = end($this->cart_details);
1862 1862
         } else {
1863 1863
             $item_price     = $cart_item['item_price'];
1864
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1865
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1864
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1865
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1866 1866
         
1867
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1867
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1868 1868
             $tax_decrease       = $tax;
1869 1869
 
1870
-            unset( $this->cart_details[$found_cart_key] );
1870
+            unset($this->cart_details[$found_cart_key]);
1871 1871
             
1872 1872
             $remove_item             = $args;
1873 1873
             $remove_item['id']       = $item_id;
@@ -1878,8 +1878,8 @@  discard block
 block discarded – undo
1878 1878
         $remove_item['action']      = 'remove';
1879 1879
         $this->pending['items'][]   = $remove_item;
1880 1880
                
1881
-        $this->decrease_subtotal( $subtotal_decrease );
1882
-        $this->decrease_tax( $tax_decrease );
1881
+        $this->decrease_subtotal($subtotal_decrease);
1882
+        $this->decrease_tax($tax_decrease);
1883 1883
         
1884 1884
         return true;
1885 1885
     }
@@ -1887,7 +1887,7 @@  discard block
 block discarded – undo
1887 1887
     public function update_items($temp = false) {
1888 1888
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1889 1889
         
1890
-        if ( !empty( $this->cart_details ) ) {
1890
+        if (!empty($this->cart_details)) {
1891 1891
             $wpi_nosave             = $temp;
1892 1892
             $cart_subtotal          = 0;
1893 1893
             $cart_discount          = 0;
@@ -1897,41 +1897,41 @@  discard block
 block discarded – undo
1897 1897
             $_POST['wpinv_country'] = $this->country;
1898 1898
             $_POST['wpinv_state']   = $this->state;
1899 1899
             
1900
-            foreach ( $this->cart_details as $key => $item ) {
1900
+            foreach ($this->cart_details as $key => $item) {
1901 1901
                 $item_price = $item['item_price'];
1902
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1903
-                $amount     = wpinv_format_amount( $item_price * $quantity, NULL, true );
1902
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1903
+                $amount     = wpinv_format_amount($item_price * $quantity, NULL, true);
1904 1904
                 $subtotal   = $item_price * $quantity;
1905 1905
                 
1906 1906
                 $wpi_current_id         = $this->ID;
1907 1907
                 $wpi_item_id            = $item['id'];
1908 1908
                 
1909
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1909
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1910 1910
                 
1911
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1912
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1913
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1911
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1912
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1913
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1914 1914
 
1915
-                if ( wpinv_prices_include_tax() ) {
1916
-                    $subtotal -= wpinv_format_amount( $tax, NULL, true );
1915
+                if (wpinv_prices_include_tax()) {
1916
+                    $subtotal -= wpinv_format_amount($tax, NULL, true);
1917 1917
                 }
1918 1918
 
1919
-                $total      = $subtotal - $discount + $tax;
1919
+                $total = $subtotal - $discount + $tax;
1920 1920
 
1921 1921
                 // Do not allow totals to go negative
1922
-                if( $total < 0 ) {
1922
+                if ($total < 0) {
1923 1923
                     $total = 0;
1924 1924
                 }
1925 1925
 
1926 1926
                 $cart_details[] = array(
1927 1927
                     'id'          => $item['id'],
1928 1928
                     'name'        => $item['name'],
1929
-                    'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1929
+                    'item_price'  => wpinv_format_amount($item_price, NULL, true),
1930 1930
                     'quantity'    => $quantity,
1931 1931
                     'discount'    => $discount,
1932
-                    'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1933
-                    'tax'         => wpinv_format_amount( $tax, NULL, true ),
1934
-                    'price'       => wpinv_format_amount( $total, NULL, true ),
1932
+                    'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1933
+                    'tax'         => wpinv_format_amount($tax, NULL, true),
1934
+                    'price'       => wpinv_format_amount($total, NULL, true),
1935 1935
                     'vat_rate'    => $tax_rate,
1936 1936
                     'vat_class'   => $tax_class,
1937 1937
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1942,9 +1942,9 @@  discard block
 block discarded – undo
1942 1942
                 $cart_discount  += (float)($discount);
1943 1943
                 $cart_tax       += (float)($tax);
1944 1944
             }
1945
-            $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true );
1946
-            $this->tax      = wpinv_format_amount( $cart_tax, NULL, true );
1947
-            $this->discount = wpinv_format_amount( $cart_discount, NULL, true );
1945
+            $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true);
1946
+            $this->tax      = wpinv_format_amount($cart_tax, NULL, true);
1947
+            $this->discount = wpinv_format_amount($cart_discount, NULL, true);
1948 1948
             
1949 1949
             $this->recalculate_total();
1950 1950
             
@@ -1956,221 +1956,221 @@  discard block
 block discarded – undo
1956 1956
     
1957 1957
     public function recalculate_totals($temp = false) {        
1958 1958
         $this->update_items($temp);
1959
-        $this->save( true );
1959
+        $this->save(true);
1960 1960
         
1961 1961
         return $this;
1962 1962
     }
1963 1963
     
1964 1964
     public function needs_payment() {
1965
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1965
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1966 1966
 
1967
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) {
1967
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) {
1968 1968
             $needs_payment = true;
1969 1969
         } else {
1970 1970
             $needs_payment = false;
1971 1971
         }
1972 1972
 
1973
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1973
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1974 1974
     }
1975 1975
     
1976
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1976
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1977 1977
         $pay_url = wpinv_get_checkout_uri();
1978 1978
 
1979
-        if ( is_ssl() ) {
1980
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1979
+        if (is_ssl()) {
1980
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1981 1981
         }
1982 1982
         
1983 1983
         $key = $this->get_key();
1984 1984
 
1985
-        if ( $on_checkout ) {
1986
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1985
+        if ($on_checkout) {
1986
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1987 1987
         } else {
1988
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1988
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1989 1989
         }
1990 1990
         
1991
-        if ( $secret ) {
1992
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1991
+        if ($secret) {
1992
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1993 1993
         }
1994 1994
 
1995
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
1995
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
1996 1996
     }
1997 1997
     
1998
-    public function get_view_url( $secret = false ) {
1999
-        $print_url = get_permalink( $this->ID );
1998
+    public function get_view_url($secret = false) {
1999
+        $print_url = get_permalink($this->ID);
2000 2000
         
2001
-        if ( $secret ) {
2002
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2001
+        if ($secret) {
2002
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2003 2003
         }
2004 2004
 
2005
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2005
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2006 2006
     }
2007 2007
     
2008
-    public function generate_key( $string = '' ) {
2009
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2010
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2008
+    public function generate_key($string = '') {
2009
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2010
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2011 2011
     }
2012 2012
     
2013 2013
     public function is_recurring() {
2014
-        if ( empty( $this->cart_details ) ) {
2014
+        if (empty($this->cart_details)) {
2015 2015
             return false;
2016 2016
         }
2017 2017
         
2018 2018
         $has_subscription = false;
2019
-        foreach( $this->cart_details as $cart_item ) {
2020
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2019
+        foreach ($this->cart_details as $cart_item) {
2020
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2021 2021
                 $has_subscription = true;
2022 2022
                 break;
2023 2023
             }
2024 2024
         }
2025 2025
         
2026
-        if ( count( $this->cart_details ) > 1 ) {
2026
+        if (count($this->cart_details) > 1) {
2027 2027
             $has_subscription = false;
2028 2028
         }
2029 2029
 
2030
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2030
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2031 2031
     }
2032 2032
     
2033 2033
     public function is_free_trial() {
2034 2034
         $is_free_trial = false;
2035 2035
         
2036
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2037
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2036
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2037
+            if (!empty($item) && $item->has_free_trial()) {
2038 2038
                 $is_free_trial = true;
2039 2039
             }
2040 2040
         }
2041 2041
 
2042
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2042
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2043 2043
     }
2044 2044
     
2045
-    public function get_recurring( $object = false ) {
2045
+    public function get_recurring($object = false) {
2046 2046
         $item = NULL;
2047 2047
         
2048
-        if ( empty( $this->cart_details ) ) {
2048
+        if (empty($this->cart_details)) {
2049 2049
             return $item;
2050 2050
         }
2051 2051
         
2052
-        foreach( $this->cart_details as $cart_item ) {
2053
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2052
+        foreach ($this->cart_details as $cart_item) {
2053
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2054 2054
                 $item = $cart_item['id'];
2055 2055
                 break;
2056 2056
             }
2057 2057
         }
2058 2058
         
2059
-        if ( $object ) {
2060
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2059
+        if ($object) {
2060
+            $item = $item ? new WPInv_Item($item) : NULL;
2061 2061
             
2062
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2062
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2063 2063
         }
2064 2064
 
2065
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2065
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2066 2066
     }
2067 2067
     
2068 2068
     public function get_subscription_name() {
2069
-        $item = $this->get_recurring( true );
2069
+        $item = $this->get_recurring(true);
2070 2070
         
2071
-        if ( empty( $item ) ) {
2071
+        if (empty($item)) {
2072 2072
             return NULL;
2073 2073
         }
2074 2074
         
2075
-        if ( !($name = $item->get_name()) ) {
2075
+        if (!($name = $item->get_name())) {
2076 2076
             $name = $item->post_name;
2077 2077
         }
2078 2078
 
2079
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2079
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2080 2080
     }
2081 2081
         
2082 2082
     public function get_expiration() {
2083
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2083
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2084 2084
         return $expiration;
2085 2085
     }
2086 2086
     
2087
-    public function get_cancelled_date( $formatted = true ) {
2088
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2087
+    public function get_cancelled_date($formatted = true) {
2088
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2089 2089
         
2090
-        if ( $formatted && $cancelled_date ) {
2091
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2090
+        if ($formatted && $cancelled_date) {
2091
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2092 2092
         }
2093 2093
         
2094 2094
         return $cancelled_date;
2095 2095
     }
2096 2096
     
2097
-    public function get_trial_end_date( $formatted = true ) {
2098
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2097
+    public function get_trial_end_date($formatted = true) {
2098
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2099 2099
             return NULL;
2100 2100
         }
2101 2101
         
2102
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2102
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2103 2103
         
2104
-        if ( empty( $trial_end_date ) ) {
2105
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2106
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2104
+        if (empty($trial_end_date)) {
2105
+            $trial_start_time = strtotime($this->get_subscription_start());
2106
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2107 2107
             
2108
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2108
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2109 2109
         }
2110 2110
         
2111
-        if ( $formatted && $trial_end_date ) {
2112
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2111
+        if ($formatted && $trial_end_date) {
2112
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2113 2113
         }
2114 2114
         
2115 2115
         return $trial_end_date;
2116 2116
     }
2117 2117
     
2118
-    public function get_subscription_created( $default = true ) {
2119
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2118
+    public function get_subscription_created($default = true) {
2119
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2120 2120
         
2121
-        if ( empty( $created ) && $default ) {
2121
+        if (empty($created) && $default) {
2122 2122
             $created = $this->date;
2123 2123
         }
2124 2124
         return $created;
2125 2125
     }
2126 2126
     
2127
-    public function get_subscription_start( $formatted = true ) {
2128
-        if ( !$this->is_paid() ) {
2127
+    public function get_subscription_start($formatted = true) {
2128
+        if (!$this->is_paid()) {
2129 2129
             return '-';
2130 2130
         }
2131
-        $start   = $this->get_subscription_created();
2131
+        $start = $this->get_subscription_created();
2132 2132
         
2133
-        if ( $formatted ) {
2134
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2133
+        if ($formatted) {
2134
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2135 2135
         } else {
2136
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2136
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2137 2137
         }
2138 2138
 
2139 2139
         return $date;
2140 2140
     }
2141 2141
     
2142
-    public function get_subscription_end( $formatted = true ) {
2143
-        if ( !$this->is_paid() ) {
2142
+    public function get_subscription_end($formatted = true) {
2143
+        if (!$this->is_paid()) {
2144 2144
             return '-';
2145 2145
         }
2146 2146
         $start          = $this->get_subscription_created();
2147 2147
         $interval       = $this->get_subscription_interval();
2148
-        $period         = $this->get_subscription_period( true );
2148
+        $period         = $this->get_subscription_period(true);
2149 2149
         $bill_times     = (int)$this->get_bill_times();
2150 2150
         
2151
-        if ( $bill_times == 0 ) {
2152
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2151
+        if ($bill_times == 0) {
2152
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2153 2153
         }
2154 2154
         
2155
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2155
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2156 2156
         
2157
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2157
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2158 2158
         
2159
-        if ( $this->is_free_trial() ) {
2160
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2159
+        if ($this->is_free_trial()) {
2160
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2161 2161
         }
2162 2162
         
2163
-        if ( $formatted ) {
2164
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2163
+        if ($formatted) {
2164
+            $date = date_i18n(get_option('date_format'), $end_time);
2165 2165
         } else {
2166
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2166
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2167 2167
         }
2168 2168
 
2169 2169
         return $date;
2170 2170
     }
2171 2171
     
2172 2172
     public function get_expiration_time() {
2173
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2173
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2174 2174
     }
2175 2175
     
2176 2176
     public function get_original_invoice_id() {        
@@ -2182,125 +2182,125 @@  discard block
 block discarded – undo
2182 2182
         return $subscription_data['bill_times'];
2183 2183
     }
2184 2184
 
2185
-    public function get_child_payments( $self = false ) {
2186
-        $invoices = get_posts( array(
2185
+    public function get_child_payments($self = false) {
2186
+        $invoices = get_posts(array(
2187 2187
             'post_type'         => 'wpi_invoice',
2188 2188
             'post_parent'       => (int)$this->ID,
2189 2189
             'posts_per_page'    => '999',
2190
-            'post_status'       => array( 'publish', 'complete', 'processing', 'renewal' ),
2190
+            'post_status'       => array('publish', 'complete', 'processing', 'renewal'),
2191 2191
             'orderby'           => 'ID',
2192 2192
             'order'             => 'DESC',
2193 2193
             'fields'            => 'ids'
2194
-        ) );
2194
+        ));
2195 2195
         
2196
-        if ( $this->is_free_trial() ) {
2196
+        if ($this->is_free_trial()) {
2197 2197
             $self = false;
2198 2198
         }
2199 2199
         
2200
-        if ( $self && $this->is_paid() ) {
2201
-            if ( !empty( $invoices ) ) {
2200
+        if ($self && $this->is_paid()) {
2201
+            if (!empty($invoices)) {
2202 2202
                 $invoices[] = (int)$this->ID;
2203 2203
             } else {
2204
-                $invoices = array( $this->ID );
2204
+                $invoices = array($this->ID);
2205 2205
             }
2206 2206
             
2207
-            $invoices = array_unique( $invoices );
2207
+            $invoices = array_unique($invoices);
2208 2208
         }
2209 2209
 
2210 2210
         return $invoices;
2211 2211
     }
2212 2212
 
2213
-    public function get_total_payments( $self = true ) {
2214
-        return count( $this->get_child_payments( $self ) );
2213
+    public function get_total_payments($self = true) {
2214
+        return count($this->get_child_payments($self));
2215 2215
     }
2216 2216
     
2217
-    public function get_subscriptions( $limit = -1 ) {
2218
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2217
+    public function get_subscriptions($limit = -1) {
2218
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2219 2219
 
2220 2220
         return $subscriptions;
2221 2221
     }
2222 2222
     
2223 2223
     public function get_subscription_id() {
2224
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2224
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2225 2225
         
2226
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2227
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2226
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2227
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2228 2228
             
2229
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2229
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2230 2230
         }
2231 2231
         
2232 2232
         return $subscription_id;
2233 2233
     }
2234 2234
     
2235 2235
     public function get_subscription_status() {
2236
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2236
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2237 2237
 
2238
-        if ( empty( $subscription_status ) ) {
2238
+        if (empty($subscription_status)) {
2239 2239
             $status = 'pending';
2240 2240
             
2241
-            if ( $this->is_paid() ) {        
2241
+            if ($this->is_paid()) {        
2242 2242
                 $bill_times   = (int)$this->get_bill_times();
2243 2243
                 $times_billed = (int)$this->get_total_payments();
2244
-                $expiration = $this->get_subscription_end( false );
2245
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2244
+                $expiration = $this->get_subscription_end(false);
2245
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2246 2246
                 
2247
-                if ( (int)$bill_times == 0 ) {
2247
+                if ((int)$bill_times == 0) {
2248 2248
                     $status = $expired ? 'expired' : 'active';
2249
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2249
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2250 2250
                     $status = 'completed';
2251
-                } else if ( $expired ) {
2251
+                } else if ($expired) {
2252 2252
                     $status = 'expired';
2253
-                } else if ( $bill_times > 0 ) {
2253
+                } else if ($bill_times > 0) {
2254 2254
                     $status = 'active';
2255 2255
                 } else {
2256 2256
                     $status = 'pending';
2257 2257
                 }
2258 2258
             }
2259 2259
             
2260
-            if ( $status && $status != $subscription_status ) {
2260
+            if ($status && $status != $subscription_status) {
2261 2261
                 $subscription_status = $status;
2262 2262
                 
2263
-                $this->update_meta( '_wpinv_subscr_status', $status );
2263
+                $this->update_meta('_wpinv_subscr_status', $status);
2264 2264
             }
2265 2265
         }
2266 2266
         
2267 2267
         return $subscription_status;
2268 2268
     }
2269 2269
     
2270
-    public function get_subscription_status_label( $status = '' ) {
2271
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2270
+    public function get_subscription_status_label($status = '') {
2271
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2272 2272
 
2273
-        switch( $status ) {
2273
+        switch ($status) {
2274 2274
             case 'active' :
2275
-                $status_label = __( 'Active', 'invoicing' );
2275
+                $status_label = __('Active', 'invoicing');
2276 2276
                 break;
2277 2277
 
2278 2278
             case 'cancelled' :
2279
-                $status_label = __( 'Cancelled', 'invoicing' );
2279
+                $status_label = __('Cancelled', 'invoicing');
2280 2280
                 break;
2281 2281
                 
2282 2282
             case 'completed' :
2283
-                $status_label = __( 'Completed', 'invoicing' );
2283
+                $status_label = __('Completed', 'invoicing');
2284 2284
                 break;
2285 2285
 
2286 2286
             case 'expired' :
2287
-                $status_label = __( 'Expired', 'invoicing' );
2287
+                $status_label = __('Expired', 'invoicing');
2288 2288
                 break;
2289 2289
 
2290 2290
             case 'pending' :
2291
-                $status_label = __( 'Pending', 'invoicing' );
2291
+                $status_label = __('Pending', 'invoicing');
2292 2292
                 break;
2293 2293
 
2294 2294
             case 'failing' :
2295
-                $status_label = __( 'Failing', 'invoicing' );
2295
+                $status_label = __('Failing', 'invoicing');
2296 2296
                 break;
2297 2297
                 
2298 2298
             case 'stopped' :
2299
-                $status_label = __( 'Stopped', 'invoicing' );
2299
+                $status_label = __('Stopped', 'invoicing');
2300 2300
                 break;
2301 2301
                 
2302 2302
             case 'trialing' :
2303
-                $status_label = __( 'Trialing', 'invoicing' );
2303
+                $status_label = __('Trialing', 'invoicing');
2304 2304
                 break;
2305 2305
 
2306 2306
             default:
@@ -2311,15 +2311,15 @@  discard block
 block discarded – undo
2311 2311
         return $status_label;
2312 2312
     }
2313 2313
     
2314
-    public function get_subscription_period( $full = false ) {
2315
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2314
+    public function get_subscription_period($full = false) {
2315
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2316 2316
         
2317
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2317
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2318 2318
             $period = 'D';
2319 2319
         }
2320 2320
         
2321
-        if ( $full ) {
2322
-            switch( $period ) {
2321
+        if ($full) {
2322
+            switch ($period) {
2323 2323
                 case 'D':
2324 2324
                     $period = 'day';
2325 2325
                 break;
@@ -2339,28 +2339,28 @@  discard block
 block discarded – undo
2339 2339
     }
2340 2340
     
2341 2341
     public function get_subscription_interval() {
2342
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2342
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2343 2343
         
2344
-        if ( !$interval > 0 ) {
2344
+        if (!$interval > 0) {
2345 2345
             $interval = 1;
2346 2346
         }
2347 2347
         
2348 2348
         return $interval;
2349 2349
     }
2350 2350
     
2351
-    public function get_subscription_trial_period( $full = false ) {
2352
-        if ( !$this->is_free_trial() ) {
2351
+    public function get_subscription_trial_period($full = false) {
2352
+        if (!$this->is_free_trial()) {
2353 2353
             return '';
2354 2354
         }
2355 2355
         
2356
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2356
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2357 2357
         
2358
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2358
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2359 2359
             $period = 'D';
2360 2360
         }
2361 2361
         
2362
-        if ( $full ) {
2363
-            switch( $period ) {
2362
+        if ($full) {
2363
+            switch ($period) {
2364 2364
                 case 'D':
2365 2365
                     $period = 'day';
2366 2366
                 break;
@@ -2380,13 +2380,13 @@  discard block
 block discarded – undo
2380 2380
     }
2381 2381
     
2382 2382
     public function get_subscription_trial_interval() {
2383
-        if ( !$this->is_free_trial() ) {
2383
+        if (!$this->is_free_trial()) {
2384 2384
             return 0;
2385 2385
         }
2386 2386
         
2387
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2387
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2388 2388
         
2389
-        if ( !$interval > 0 ) {
2389
+        if (!$interval > 0) {
2390 2390
             $interval = 1;
2391 2391
         }
2392 2392
         
@@ -2398,8 +2398,8 @@  discard block
 block discarded – undo
2398 2398
             'status' => 'failing'
2399 2399
         );
2400 2400
 
2401
-        if ( $this->update_subscription( $args ) ) {
2402
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2401
+        if ($this->update_subscription($args)) {
2402
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2403 2403
             return true;
2404 2404
         }
2405 2405
 
@@ -2411,8 +2411,8 @@  discard block
 block discarded – undo
2411 2411
             'status' => 'stopped'
2412 2412
         );
2413 2413
 
2414
-        if ( $this->update_subscription( $args ) ) {
2415
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2414
+        if ($this->update_subscription($args)) {
2415
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2416 2416
             return true;
2417 2417
         }
2418 2418
 
@@ -2424,8 +2424,8 @@  discard block
 block discarded – undo
2424 2424
             'status' => 'active'
2425 2425
         );
2426 2426
 
2427
-        if ( $this->update_subscription( $args ) ) {
2428
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2427
+        if ($this->update_subscription($args)) {
2428
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2429 2429
             return true;
2430 2430
         }
2431 2431
 
@@ -2437,23 +2437,23 @@  discard block
 block discarded – undo
2437 2437
             'status' => 'cancelled'
2438 2438
         );
2439 2439
 
2440
-        if ( $this->update_subscription( $args ) ) {
2441
-            if ( is_user_logged_in() ) {
2442
-                $userdata = get_userdata( get_current_user_id() );
2440
+        if ($this->update_subscription($args)) {
2441
+            if (is_user_logged_in()) {
2442
+                $userdata = get_userdata(get_current_user_id());
2443 2443
                 $user     = $userdata->user_login;
2444 2444
             } else {
2445
-                $user = __( 'gateway', 'invoicing' );
2445
+                $user = __('gateway', 'invoicing');
2446 2446
             }
2447 2447
             
2448 2448
             $subscription_id = $this->get_subscription_id();
2449
-            if ( !$subscription_id ) {
2449
+            if (!$subscription_id) {
2450 2450
                 $subscription_id = $this->ID;
2451 2451
             }
2452 2452
 
2453
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2454
-            $this->add_note( $note );
2453
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2454
+            $this->add_note($note);
2455 2455
 
2456
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2456
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2457 2457
             return true;
2458 2458
         }
2459 2459
 
@@ -2461,11 +2461,11 @@  discard block
 block discarded – undo
2461 2461
     }
2462 2462
 
2463 2463
     public function can_cancel() {
2464
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2464
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2465 2465
     }
2466 2466
     
2467
-    public function add_subscription( $data = array() ) {
2468
-        if ( empty( $this->ID ) ) {
2467
+    public function add_subscription($data = array()) {
2468
+        if (empty($this->ID)) {
2469 2469
             return false;
2470 2470
         }
2471 2471
 
@@ -2484,85 +2484,85 @@  discard block
 block discarded – undo
2484 2484
             'profile_id'        => '',
2485 2485
         );
2486 2486
 
2487
-        $args = wp_parse_args( $data, $defaults );
2487
+        $args = wp_parse_args($data, $defaults);
2488 2488
 
2489
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2490
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2489
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2490
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2491 2491
                 $args['status'] = 'expired';
2492 2492
             }
2493 2493
         }
2494 2494
 
2495
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2495
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2496 2496
         
2497
-        if ( !empty( $args ) ) {
2498
-            foreach ( $args as $key => $value ) {
2499
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2497
+        if (!empty($args)) {
2498
+            foreach ($args as $key => $value) {
2499
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2500 2500
             }
2501 2501
         }
2502 2502
 
2503
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2503
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2504 2504
 
2505 2505
         return true;
2506 2506
     }
2507 2507
     
2508
-    public function update_subscription( $args = array() ) {
2509
-        if ( empty( $this->ID ) ) {
2508
+    public function update_subscription($args = array()) {
2509
+        if (empty($this->ID)) {
2510 2510
             return false;
2511 2511
         }
2512 2512
 
2513
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2514
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2513
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2514
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2515 2515
                 $args['status'] = 'expired';
2516 2516
             }
2517 2517
         }
2518 2518
 
2519
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2520
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2519
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2520
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2521 2521
         }
2522 2522
 
2523
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2523
+        do_action('wpinv_subscription_pre_update', $args, $this);
2524 2524
         
2525
-        if ( !empty( $args ) ) {
2526
-            foreach ( $args as $key => $value ) {
2527
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2525
+        if (!empty($args)) {
2526
+            foreach ($args as $key => $value) {
2527
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2528 2528
             }
2529 2529
         }
2530 2530
 
2531
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2531
+        do_action('wpinv_subscription_post_update', $args, $this);
2532 2532
 
2533 2533
         return true;
2534 2534
     }
2535 2535
     
2536 2536
     public function renew_subscription() {
2537 2537
         $parent_invoice = $this->get_parent_payment();
2538
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2538
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2539 2539
         
2540
-        $current_time   = current_time( 'timestamp' );
2540
+        $current_time   = current_time('timestamp');
2541 2541
         $start          = $this->get_subscription_created();
2542
-        $start          = $start ? strtotime( $start ) : $current_time;
2542
+        $start          = $start ? strtotime($start) : $current_time;
2543 2543
         $expires        = $this->get_expiration_time();
2544 2544
         
2545
-        if ( !$expires ) {
2546
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2545
+        if (!$expires) {
2546
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2547 2547
         }
2548 2548
         
2549
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2550
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2549
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2550
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2551 2551
         $bill_times     = $parent_invoice->get_bill_times();
2552 2552
         $times_billed   = $parent_invoice->get_total_payments();
2553 2553
         
2554
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2554
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2555 2555
             $args = array(
2556 2556
                 'status'     => 'active',
2557 2557
             );
2558 2558
 
2559
-            $parent_invoice->update_subscription( $args );
2559
+            $parent_invoice->update_subscription($args);
2560 2560
         }
2561 2561
         
2562
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2562
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2563 2563
 
2564
-        $status       = 'active';
2565
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2564
+        $status = 'active';
2565
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2566 2566
             $this->complete_subscription();
2567 2567
             $status = 'completed';
2568 2568
         }
@@ -2572,10 +2572,10 @@  discard block
 block discarded – undo
2572 2572
             'status'     => $status,
2573 2573
         );
2574 2574
 
2575
-        $this->update_subscription( $args );
2575
+        $this->update_subscription($args);
2576 2576
 
2577
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2578
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2577
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2578
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2579 2579
     }
2580 2580
     
2581 2581
     public function complete_subscription() {
@@ -2583,8 +2583,8 @@  discard block
 block discarded – undo
2583 2583
             'status' => 'completed'
2584 2584
         );
2585 2585
 
2586
-        if ( $this->update_subscription( $args ) ) {
2587
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2586
+        if ($this->update_subscription($args)) {
2587
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2588 2588
         }
2589 2589
     }
2590 2590
     
@@ -2593,44 +2593,44 @@  discard block
 block discarded – undo
2593 2593
             'status' => 'expired'
2594 2594
         );
2595 2595
 
2596
-        if ( $this->update_subscription( $args ) ) {
2597
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2596
+        if ($this->update_subscription($args)) {
2597
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2598 2598
         }
2599 2599
     }
2600 2600
 
2601 2601
     public function get_cancel_url() {
2602
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2602
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2603 2603
 
2604
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2604
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2605 2605
     }
2606 2606
 
2607 2607
     public function can_update() {
2608
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2608
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2609 2609
     }
2610 2610
 
2611 2611
     public function get_update_url() {
2612
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2612
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2613 2613
 
2614
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2614
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2615 2615
     }
2616 2616
 
2617 2617
     public function is_parent() {
2618
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2618
+        $is_parent = empty($this->parent_invoice) ? true : false;
2619 2619
 
2620
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2620
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2621 2621
     }
2622 2622
     
2623 2623
     public function is_renewal() {
2624 2624
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2625 2625
 
2626
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2626
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2627 2627
     }
2628 2628
     
2629 2629
     public function get_parent_payment() {
2630 2630
         $parent_payment = NULL;
2631 2631
         
2632
-        if ( $this->is_renewal() ) {
2633
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2632
+        if ($this->is_renewal()) {
2633
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2634 2634
         }
2635 2635
         
2636 2636
         return $parent_payment;
@@ -2641,100 +2641,100 @@  discard block
 block discarded – undo
2641 2641
         
2642 2642
         $subscription_status = $this->get_subscription_status();
2643 2643
 
2644
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2644
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2645 2645
             $ret = true;
2646 2646
         }
2647 2647
 
2648
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2648
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2649 2649
     }
2650 2650
 
2651 2651
     public function is_subscription_expired() {
2652 2652
         $ret = false;
2653 2653
         $subscription_status = $this->get_subscription_status();
2654 2654
 
2655
-        if ( $subscription_status == 'expired' ) {
2655
+        if ($subscription_status == 'expired') {
2656 2656
             $ret = true;
2657
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2657
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2658 2658
             $ret        = false;
2659 2659
             $expiration = $this->get_expiration_time();
2660 2660
 
2661
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2661
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2662 2662
                 $ret = true;
2663 2663
 
2664
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2664
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2665 2665
                     $this->expire_subscription();
2666 2666
                 }
2667 2667
             }
2668 2668
         }
2669 2669
 
2670
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2670
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2671 2671
     }
2672 2672
     
2673
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2674
-        $item   = new WPInv_Item( $item_id );
2673
+    public function get_new_expiration($item_id = 0, $trial = true) {
2674
+        $item   = new WPInv_Item($item_id);
2675 2675
         $interval = $item->get_recurring_interval();
2676
-        $period = $item->get_recurring_period( true );
2676
+        $period = $item->get_recurring_period(true);
2677 2677
         
2678
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2678
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2679 2679
         
2680
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2681
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2680
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2681
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2682 2682
         }
2683 2683
 
2684
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2684
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2685 2685
     }
2686 2686
     
2687
-    public function get_subscription_data( $filed = '' ) {
2688
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2687
+    public function get_subscription_data($filed = '') {
2688
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2689 2689
         
2690 2690
         $subscription_meta = array();
2691
-        foreach ( $fields as $field ) {
2692
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2691
+        foreach ($fields as $field) {
2692
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2693 2693
         }
2694 2694
         
2695
-        $item = $this->get_recurring( true );
2695
+        $item = $this->get_recurring(true);
2696 2696
         
2697
-        if ( !empty( $item ) ) {
2698
-            if ( empty( $subscription_meta['item_id'] ) ) {
2697
+        if (!empty($item)) {
2698
+            if (empty($subscription_meta['item_id'])) {
2699 2699
                 $subscription_meta['item_id'] = $item->ID;
2700 2700
             }
2701
-            if ( empty( $subscription_meta['period'] ) ) {
2701
+            if (empty($subscription_meta['period'])) {
2702 2702
                 $subscription_meta['period'] = $item->get_recurring_period();
2703 2703
             }
2704
-            if ( empty( $subscription_meta['interval'] ) ) {
2704
+            if (empty($subscription_meta['interval'])) {
2705 2705
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2706 2706
             }
2707
-            if ( $item->has_free_trial() ) {
2708
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2707
+            if ($item->has_free_trial()) {
2708
+                if (empty($subscription_meta['trial_period'])) {
2709 2709
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2710 2710
                 }
2711
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2711
+                if (empty($subscription_meta['trial_interval'])) {
2712 2712
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2713 2713
                 }
2714 2714
             } else {
2715 2715
                 $subscription_meta['trial_period']      = '';
2716 2716
                 $subscription_meta['trial_interval']    = 0;
2717 2717
             }
2718
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2718
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2719 2719
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2720 2720
             }
2721
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2722
-                $subscription_meta['initial_amount']    = wpinv_format_amount( $this->get_total() );
2723
-                $subscription_meta['recurring_amount']  = wpinv_format_amount( $this->get_recurring_details( 'total' ) );
2721
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2722
+                $subscription_meta['initial_amount']    = wpinv_format_amount($this->get_total());
2723
+                $subscription_meta['recurring_amount']  = wpinv_format_amount($this->get_recurring_details('total'));
2724 2724
             }
2725 2725
         }
2726 2726
         
2727
-        if ( $filed === '' ) {
2728
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2727
+        if ($filed === '') {
2728
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2729 2729
         }
2730 2730
         
2731
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2731
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2732 2732
         
2733
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2733
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2734 2734
     }
2735 2735
     
2736 2736
     public function is_paid() {
2737
-        if ( $this->has_status( array( 'publish', 'complete', 'processing', 'renewal' ) ) ) {
2737
+        if ($this->has_status(array('publish', 'complete', 'processing', 'renewal'))) {
2738 2738
             return true;
2739 2739
         }
2740 2740
         
@@ -2746,28 +2746,28 @@  discard block
 block discarded – undo
2746 2746
         
2747 2747
         $requires_vat = false;
2748 2748
         
2749
-        if ( $this->country ) {
2749
+        if ($this->country) {
2750 2750
             $wpi_country        = $this->country;
2751 2751
             
2752
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2752
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2753 2753
         }
2754 2754
         
2755
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2755
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2756 2756
     }
2757 2757
     
2758 2758
     public function refresh_item_ids() {
2759 2759
         $item_ids = array();
2760 2760
         
2761
-        if ( !empty( $this->cart_details ) ) {
2762
-            foreach ( $this->cart_details as $key => $item ) {
2763
-                if ( !empty( $item['id'] ) ) {
2761
+        if (!empty($this->cart_details)) {
2762
+            foreach ($this->cart_details as $key => $item) {
2763
+                if (!empty($item['id'])) {
2764 2764
                     $item_ids[] = $item['id'];
2765 2765
                 }
2766 2766
             }
2767 2767
         }
2768 2768
         
2769
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2769
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2770 2770
         
2771
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2771
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2772 2772
     }
2773 2773
 }
Please login to merge, or discard this patch.
templates/emails/wpinv-email-invoice-details.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,72 +1,72 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat;
7 7
 
8
-$sent_to_admin  = !empty( $sent_to_admin ) ? true : false;
9
-if ( $sent_to_admin ) {
10
-    $invoice_url = get_edit_post_link( $invoice->ID );
8
+$sent_to_admin = !empty($sent_to_admin) ? true : false;
9
+if ($sent_to_admin) {
10
+    $invoice_url = get_edit_post_link($invoice->ID);
11 11
 } else {
12
-    $secret = !empty( $email_type ) && $email_type == 'user_invoice' ? true : false;
13
-    $invoice_url = $invoice->get_view_url( $secret );
12
+    $secret = !empty($email_type) && $email_type == 'user_invoice' ? true : false;
13
+    $invoice_url = $invoice->get_view_url($secret);
14 14
 }
15 15
 $use_taxes = wpinv_use_taxes();
16 16
 $vat_name = $wpinv_euvat->get_vat_name();
17 17
 
18
-do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); ?>
18
+do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); ?>
19 19
 <div id="wpinv-email-details">
20
-    <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_email_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3>
20
+    <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_email_details_title', __('Invoice Details', 'invoicing')); ?></h3>
21 21
     <table class="table table-bordered table-sm">
22
-        <?php if ( $invoice_number = $invoice->get_number() ) { ?>
22
+        <?php if ($invoice_number = $invoice->get_number()) { ?>
23 23
             <tr>
24
-                <td><?php _e( 'Invoice Number', 'invoicing' ); ?></td>
25
-                <td><a href="<?php echo esc_url( $invoice_url ) ;?>"><?php echo $invoice_number; ?></a></td>
24
+                <td><?php _e('Invoice Number', 'invoicing'); ?></td>
25
+                <td><a href="<?php echo esc_url($invoice_url); ?>"><?php echo $invoice_number; ?></a></td>
26 26
             </tr>
27 27
         <?php } ?>
28 28
         <tr>
29
-            <td><?php _e( 'Invoice Status', 'invoicing' ); ?></td>
30
-            <td><?php echo $invoice->get_status( true ); ?></td>
29
+            <td><?php _e('Invoice Status', 'invoicing'); ?></td>
30
+            <td><?php echo $invoice->get_status(true); ?></td>
31 31
         </tr>
32
-        <?php if ( $invoice->is_renewal() ) { ?>
32
+        <?php if ($invoice->is_renewal()) { ?>
33 33
         <tr>
34
-            <td><?php _e( 'Parent Invoice', 'invoicing' ); ?></td>
35
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
34
+            <td><?php _e('Parent Invoice', 'invoicing'); ?></td>
35
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
36 36
         </tr>
37 37
         <?php } ?>
38 38
         <tr>
39
-            <td><?php _e( 'Payment Method', 'invoicing' ); ?></td>
39
+            <td><?php _e('Payment Method', 'invoicing'); ?></td>
40 40
             <td><?php echo $invoice->get_gateway_title(); ?></td>
41 41
         </tr>
42
-        <?php if ( $invoice_date = $invoice->get_invoice_date( false ) ) { ?>
42
+        <?php if ($invoice_date = $invoice->get_invoice_date(false)) { ?>
43 43
             <tr>
44
-                <td><?php _e( 'Invoice Date', 'invoicing' ); ?></td>
45
-                <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $invoice_date ) ), $invoice->get_invoice_date() ); ?></td>
44
+                <td><?php _e('Invoice Date', 'invoicing'); ?></td>
45
+                <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($invoice_date)), $invoice->get_invoice_date()); ?></td>
46 46
             </tr>
47 47
         <?php } ?>
48
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date() ) ) { ?>
48
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date())) { ?>
49 49
             <tr>
50
-                <td><?php _e( 'Due Date', 'invoicing' ); ?></td>
51
-                <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $due_date ) ), $invoice->get_due_date( true ) ); ?></td>
50
+                <td><?php _e('Due Date', 'invoicing'); ?></td>
51
+                <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($due_date)), $invoice->get_due_date(true)); ?></td>
52 52
             </tr>
53 53
         <?php } ?>
54
-        <?php if ( empty( $sent_to_admin ) && $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
54
+        <?php if (empty($sent_to_admin) && $owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
55 55
             <tr>
56
-                <td><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></td>
56
+                <td><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></td>
57 57
                 <td><?php echo $owner_vat_number; ?></td>
58 58
             </tr>
59 59
         <?php } ?>
60
-        <?php if ( $use_taxes && $user_vat_number = $invoice->vat_number ) { ?>
60
+        <?php if ($use_taxes && $user_vat_number = $invoice->vat_number) { ?>
61 61
             <tr>
62
-                <td><?php echo wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ); ?></td>
62
+                <td><?php echo wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name); ?></td>
63 63
                 <td><?php echo $user_vat_number; ?></td>
64 64
             </tr>
65 65
         <?php } ?>
66 66
         <tr class="table-active">
67
-            <td><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></td>
68
-            <td><strong><?php echo $invoice->get_total( true ); ?></strong></td>
67
+            <td><strong><?php _e('Total Amount', 'invoicing') ?></strong></td>
68
+            <td><strong><?php echo $invoice->get_total(true); ?></strong></td>
69 69
         </tr>
70 70
     </table>
71 71
 </div>
72
-<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?>
73 72
\ No newline at end of file
73
+<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?>
74 74
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +709 added lines, -709 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,132 +17,132 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
90
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
91 91
         
92
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
93
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
92
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
93
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
94 94
         
95
-        $vat_name   = self::get_vat_name();
95
+        $vat_name = self::get_vat_name();
96 96
         
97 97
         $vars = array();
98 98
         $vars['UseTaxes'] = wpinv_use_taxes();
99 99
         $vars['EUStates'] = self::get_eu_states();
100
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
101
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
102
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
103
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
104
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
105
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
106
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
107
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
100
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
101
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
102
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
103
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
104
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
105
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
106
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
107
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
108 108
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
109 109
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
110
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
111
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
112
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
113
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
114
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
115
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
116
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
117
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
118
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
119
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
120
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
121
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
122
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
110
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
111
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
112
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
113
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
114
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
115
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
116
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
117
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
118
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
119
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
120
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
121
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
122
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
123 123
         $vars['isFront'] = is_admin() ? false : true;
124
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
124
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
125 125
         $vars['baseCountry'] = wpinv_get_default_country();
126
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
127
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
126
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
127
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
128 128
         
129
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
130
-        wp_enqueue_script( 'wpinv-vat-script' );
131
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
129
+        wp_enqueue_script('wpinv-vat-validation-script');
130
+        wp_enqueue_script('wpinv-vat-script');
131
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
132 132
     }
133 133
 
134 134
     public static function enqueue_admin_scripts() {
135
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
135
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
136 136
             self::enqueue_vat_scripts();
137 137
         }
138 138
     }
139 139
     
140
-    public static function section_vat_settings( $sections ) {
141
-        if ( !empty( $sections ) ) {
142
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
140
+    public static function section_vat_settings($sections) {
141
+        if (!empty($sections)) {
142
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
143 143
             
144
-            if ( self::allow_vat_classes() ) {
145
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
144
+            if (self::allow_vat_classes()) {
145
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
146 146
             }
147 147
         }
148 148
         return $sections;
@@ -151,52 +151,52 @@  discard block
 block discarded – undo
151 151
     public static function vat_rates_settings() {
152 152
         $vat_classes = self::get_rate_classes();
153 153
         $vat_rates = array();
154
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
155
-        $current_url = remove_query_arg( 'wpi_sub' );
154
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
155
+        $current_url = remove_query_arg('wpi_sub');
156 156
         
157 157
         $vat_rates['vat_rates_header'] = array(
158 158
             'id' => 'vat_rates_header',
159
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
159
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
160 160
             'desc' => '',
161 161
             'type' => 'header',
162 162
             'size' => 'regular'
163 163
         );
164 164
         $vat_rates['vat_rates_class'] = array(
165 165
             'id'          => 'vat_rates_class',
166
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
167
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
166
+            'name'        => __('Edit VAT Rates', 'invoicing'),
167
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
168 168
             'type'        => 'select',
169
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
169
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
170 170
             'chosen'      => true,
171
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
171
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
172 172
             'selected'    => $vat_class,
173 173
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
174 174
         );
175 175
         
176
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
176
+        if ($vat_class != '_standard' && $vat_class != '_new') {
177 177
             $vat_rates['vat_rate_delete'] = array(
178 178
                 'id'   => 'vat_rate_delete',
179 179
                 'type' => 'vat_rate_delete',
180 180
             );
181 181
         }
182 182
                     
183
-        if ( $vat_class == '_new' ) {
183
+        if ($vat_class == '_new') {
184 184
             $vat_rates['vat_rates_settings'] = array(
185 185
                 'id' => 'vat_rates_settings',
186
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
186
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
187 187
                 'type' => 'header',
188 188
             );
189 189
             $vat_rates['vat_rate_name'] = array(
190 190
                 'id'   => 'vat_rate_name',
191
-                'name' => __( 'Name', 'invoicing' ),
192
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
191
+                'name' => __('Name', 'invoicing'),
192
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
193 193
                 'type' => 'text',
194 194
                 'size' => 'regular',
195 195
             );
196 196
             $vat_rates['vat_rate_desc'] = array(
197 197
                 'id'   => 'vat_rate_desc',
198
-                'name' => __( 'Description', 'invoicing' ),
199
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
198
+                'name' => __('Description', 'invoicing'),
199
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
200 200
                 'type' => 'text',
201 201
                 'size' => 'regular',
202 202
             );
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             $vat_rates['vat_rates'] = array(
209 209
                 'id'   => 'vat_rates',
210 210
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
211
-                'desc' => self::get_class_desc( $vat_class ),
211
+                'desc' => self::get_class_desc($vat_class),
212 212
                 'type' => 'vat_rates',
213 213
             );
214 214
         }
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
         return $vat_rates;
217 217
     }
218 218
     
219
-    public static function vat_settings( $settings ) {
220
-        if ( !empty( $settings ) ) {    
219
+    public static function vat_settings($settings) {
220
+        if (!empty($settings)) {    
221 221
             $vat_settings = array();
222 222
             $vat_settings['vat_company_title'] = array(
223 223
                 'id' => 'vat_company_title',
224
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
224
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
225 225
                 'desc' => '',
226 226
                 'type' => 'header',
227 227
                 'size' => 'regular'
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
             
230 230
             $vat_settings['vat_company_name'] = array(
231 231
                 'id' => 'vat_company_name',
232
-                'name' => __( 'Your Company Name', 'invoicing' ),
233
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
232
+                'name' => __('Your Company Name', 'invoicing'),
233
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
234 234
                 'type' => 'text',
235 235
                 'size' => 'regular',
236 236
             );
237 237
             
238 238
             $vat_settings['vat_number'] = array(
239 239
                 'id'   => 'vat_number',
240
-                'name' => __( 'Your VAT Number', 'invoicing' ),
240
+                'name' => __('Your VAT Number', 'invoicing'),
241 241
                 'type' => 'vat_number',
242 242
                 'size' => 'regular',
243 243
             );
244 244
 
245 245
             $vat_settings['vat_settings_title'] = array(
246 246
                 'id' => 'vat_settings_title',
247
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
247
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
248 248
                 'desc' => '',
249 249
                 'type' => 'header',
250 250
                 'size' => 'regular'
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 
253 253
             $vat_settings['apply_vat_rules'] = array(
254 254
                 'id' => 'apply_vat_rules',
255
-                'name' => __( 'Enable VAT rules', 'invoicing' ),
256
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
255
+                'name' => __('Enable VAT rules', 'invoicing'),
256
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
257 257
                 'type' => 'checkbox',
258 258
                 'std' => '1'
259 259
             );
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 
270 270
             $vat_settings['vat_prevent_b2c_purchase'] = array(
271 271
                 'id' => 'vat_prevent_b2c_purchase',
272
-                'name' => __( 'Prevent EU B2C sales', 'invoicing' ),
273
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
272
+                'name' => __('Prevent EU B2C sales', 'invoicing'),
273
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
274 274
                 'type' => 'checkbox'
275 275
             );
276 276
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 
279 279
             $vat_settings['vat_same_country_rule'] = array(
280 280
                 'id'          => 'vat_same_country_rule',
281
-                'name'        => __( 'Same country rule', 'invoicing' ),
282
-                'desc'        => __( 'Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
281
+                'name'        => __('Same country rule', 'invoicing'),
282
+                'desc'        => __('Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
283 283
                 'type'        => 'select',
284 284
                 'options'     => array(
285
-                    ''          => __( 'Normal', 'invoicing' ),
286
-                    'no'        => __( 'No VAT', 'invoicing' ),
287
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
285
+                    ''          => __('Normal', 'invoicing'),
286
+                    'no'        => __('No VAT', 'invoicing'),
287
+                    'always'    => __('Always apply VAT', 'invoicing'),
288 288
                 ),
289
-                'placeholder' => __( 'Select a option', 'invoicing' ),
289
+                'placeholder' => __('Select a option', 'invoicing'),
290 290
                 'std'         => ''
291 291
             );
292 292
 
293 293
             $vat_settings['vat_checkout_title'] = array(
294 294
                 'id' => 'vat_checkout_title',
295
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
295
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
296 296
                 'desc' => '',
297 297
                 'type' => 'header',
298 298
                 'size' => 'regular'
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
 
301 301
             $vat_settings['vat_disable_fields'] = array(
302 302
                 'id' => 'vat_disable_fields',
303
-                'name' => __( 'Disable VAT fields', 'invoicing' ),
304
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
303
+                'name' => __('Disable VAT fields', 'invoicing'),
304
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
305 305
                 'type' => 'checkbox'
306 306
             );
307 307
 
308 308
             $vat_settings['vat_ip_lookup'] = array(
309 309
                 'id'   => 'vat_ip_lookup',
310
-                'name' => __( 'IP Country lookup', 'invoicing' ),
310
+                'name' => __('IP Country lookup', 'invoicing'),
311 311
                 'type' => 'vat_ip_lookup',
312 312
                 'size' => 'regular',
313 313
                 'std' => 'default'
@@ -315,21 +315,21 @@  discard block
 block discarded – undo
315 315
 
316 316
             $vat_settings['hide_ip_address'] = array(
317 317
                 'id' => 'hide_ip_address',
318
-                'name' => __( 'Hide IP info at checkout', 'invoicing' ),
319
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
318
+                'name' => __('Hide IP info at checkout', 'invoicing'),
319
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
320 320
                 'type' => 'checkbox'
321 321
             );
322 322
 
323 323
             $vat_settings['vat_ip_country_default'] = array(
324 324
                 'id' => 'vat_ip_country_default',
325
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
326
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
325
+                'name' => __('Enable IP Country as Default', 'invoicing'),
326
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vies_validation_title'] = array(
331 331
                 'id' => 'vies_validation_title',
332
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
332
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
333 333
                 'desc' => '',
334 334
                 'type' => 'header',
335 335
                 'size' => 'regular'
@@ -337,37 +337,37 @@  discard block
 block discarded – undo
337 337
 
338 338
             $vat_settings['vat_vies_check'] = array(
339 339
                 'id' => 'vat_vies_check',
340
-                'name' => __( 'Disable VIES VAT ID check', 'invoicing' ),
341
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
340
+                'name' => __('Disable VIES VAT ID check', 'invoicing'),
341
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
342 342
                 'type' => 'checkbox'
343 343
             );
344 344
 
345 345
             $vat_settings['vat_disable_company_name_check'] = array(
346 346
                 'id' => 'vat_disable_company_name_check',
347
-                'name' => __( 'Disable VIES name check', 'invoicing' ),
348
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
347
+                'name' => __('Disable VIES name check', 'invoicing'),
348
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_offline_check'] = array(
353 353
                 'id' => 'vat_offline_check',
354
-                'name' => __( 'Disable basic checks', 'invoicing' ),
355
-                'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ),
354
+                'name' => __('Disable basic checks', 'invoicing'),
355
+                'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
             
359 359
 
360 360
             $settings['vat'] = $vat_settings;
361 361
             
362
-            if ( self::allow_vat_classes() ) {
362
+            if (self::allow_vat_classes()) {
363 363
                 $settings['vat_rates'] = self::vat_rates_settings();
364 364
             }
365 365
             
366 366
             $eu_fallback_rate = array(
367 367
                 'id'   => 'eu_fallback_rate',
368
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
368
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
369 369
                 'type' => 'eu_fallback_rate',
370
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
370
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
371 371
                 'std'  => '20',
372 372
                 'size' => 'small'
373 373
             );
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
384 384
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
385 385
         
386
-        if ( !is_dir( $destination_dir ) ) { 
387
-            mkdir( $destination_dir );
386
+        if (!is_dir($destination_dir)) { 
387
+            mkdir($destination_dir);
388 388
         }
389 389
         
390
-        $database_files     = array(
390
+        $database_files = array(
391 391
             'country'   => array(
392 392
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
393 393
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -398,57 +398,57 @@  discard block
 block discarded – undo
398 398
             )
399 399
         );
400 400
 
401
-        foreach( $database_files as $database => $files ) {
402
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
401
+        foreach ($database_files as $database => $files) {
402
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
403 403
             
404
-            if ( empty( $result['success'] ) ) {
404
+            if (empty($result['success'])) {
405 405
                 echo $result['message'];
406 406
                 exit;
407 407
             }
408 408
             
409
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
410
-            echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
409
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
410
+            echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' ';
411 411
         }
412 412
         
413 413
         exit;
414 414
     }
415 415
     
416
-    public static function geoip2_download_file( $source_url, $destination_file ) {
416
+    public static function geoip2_download_file($source_url, $destination_file) {
417 417
         $success    = false;
418 418
         $message    = '';
419 419
         
420
-        if ( !function_exists( 'download_url' ) ) {
421
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
420
+        if (!function_exists('download_url')) {
421
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
422 422
         }
423 423
 
424
-        $temp_file  = download_url( $source_url );
424
+        $temp_file = download_url($source_url);
425 425
         
426
-        if ( is_wp_error( $temp_file ) ) {
427
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
426
+        if (is_wp_error($temp_file)) {
427
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
428 428
         } else {
429
-            $handle = gzopen( $temp_file, 'rb' );
429
+            $handle = gzopen($temp_file, 'rb');
430 430
             
431
-            if ( $handle ) {
432
-                $fopen  = fopen( $destination_file, 'wb' );
433
-                if ( $fopen ) {
434
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
435
-                        fwrite( $fopen, $data );
431
+            if ($handle) {
432
+                $fopen = fopen($destination_file, 'wb');
433
+                if ($fopen) {
434
+                    while (($data = gzread($handle, 4096)) != false) {
435
+                        fwrite($fopen, $data);
436 436
                     }
437 437
 
438
-                    gzclose( $handle );
439
-                    fclose( $fopen );
438
+                    gzclose($handle);
439
+                    fclose($fopen);
440 440
                         
441 441
                     $success = true;
442 442
                 } else {
443
-                    gzclose( $handle );
444
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
443
+                    gzclose($handle);
444
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
445 445
                 }
446 446
             } else {
447
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
447
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
448 448
             }
449 449
             
450
-            if ( file_exists( $temp_file ) ) {
451
-                unlink( $temp_file );
450
+            if (file_exists($temp_file)) {
451
+                unlink($temp_file);
452 452
             }
453 453
         }
454 454
         
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
     }
461 461
     
462 462
     public static function load_geoip2() {
463
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
463
+        if (defined('WPINV_GEOIP2_LODDED')) {
464 464
             return;
465 465
         }
466 466
         
467
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
467
+        if (!class_exists('\MaxMind\Db\Reader')) {
468 468
             $maxmind_db_files = array(
469 469
                 'Reader/Decoder.php',
470 470
                 'Reader/InvalidDatabaseException.php',
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
                 'Reader.php',
474 474
             );
475 475
             
476
-            foreach ( $maxmind_db_files as $key => $file ) {
477
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
476
+            foreach ($maxmind_db_files as $key => $file) {
477
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
478 478
             }
479 479
         }
480 480
         
481
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
481
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
482 482
             $geoip2_files = array(
483 483
                 'ProviderInterface.php',
484 484
                 'Compat/JsonSerializable.php',
@@ -512,23 +512,23 @@  discard block
 block discarded – undo
512 512
                 'WebService/Client.php',
513 513
             );
514 514
             
515
-            foreach ( $geoip2_files as $key => $file ) {
516
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
515
+            foreach ($geoip2_files as $key => $file) {
516
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
517 517
             }
518 518
         }
519 519
 
520
-        define( 'WPINV_GEOIP2_LODDED', true );
520
+        define('WPINV_GEOIP2_LODDED', true);
521 521
     }
522 522
 
523 523
     public static function geoip2_country_dbfile() {
524 524
         $upload_dir = wp_upload_dir();
525 525
 
526
-        if ( !isset( $upload_dir['basedir'] ) ) {
526
+        if (!isset($upload_dir['basedir'])) {
527 527
             return false;
528 528
         }
529 529
 
530 530
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
531
-        if ( !file_exists( $filename ) ) {
531
+        if (!file_exists($filename)) {
532 532
             return false;
533 533
         }
534 534
         
@@ -538,12 +538,12 @@  discard block
 block discarded – undo
538 538
     public static function geoip2_city_dbfile() {
539 539
         $upload_dir = wp_upload_dir();
540 540
 
541
-        if ( !isset( $upload_dir['basedir'] ) ) {
541
+        if (!isset($upload_dir['basedir'])) {
542 542
             return false;
543 543
         }
544 544
 
545 545
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
546
-        if ( !file_exists( $filename ) ) {
546
+        if (!file_exists($filename)) {
547 547
             return false;
548 548
         }
549 549
         
@@ -554,10 +554,10 @@  discard block
 block discarded – undo
554 554
         try {
555 555
             self::load_geoip2();
556 556
 
557
-            if ( $filename = self::geoip2_country_dbfile() ) {
558
-                return new \GeoIp2\Database\Reader( $filename );
557
+            if ($filename = self::geoip2_country_dbfile()) {
558
+                return new \GeoIp2\Database\Reader($filename);
559 559
             }
560
-        } catch( Exception $e ) {
560
+        } catch (Exception $e) {
561 561
             return false;
562 562
         }
563 563
         
@@ -568,173 +568,173 @@  discard block
 block discarded – undo
568 568
         try {
569 569
             self::load_geoip2();
570 570
 
571
-            if ( $filename = self::geoip2_city_dbfile() ) {
572
-                return new \GeoIp2\Database\Reader( $filename );
571
+            if ($filename = self::geoip2_city_dbfile()) {
572
+                return new \GeoIp2\Database\Reader($filename);
573 573
             }
574
-        } catch( Exception $e ) {
574
+        } catch (Exception $e) {
575 575
             return false;
576 576
         }
577 577
         
578 578
         return false;
579 579
     }
580 580
 
581
-    public static function geoip2_country_record( $ip_address ) {
581
+    public static function geoip2_country_record($ip_address) {
582 582
         try {
583 583
             $reader = self::geoip2_country_reader();
584 584
 
585
-            if ( $reader ) {
586
-                $record = $reader->country( $ip_address );
585
+            if ($reader) {
586
+                $record = $reader->country($ip_address);
587 587
                 
588
-                if ( !empty( $record->country->isoCode ) ) {
588
+                if (!empty($record->country->isoCode)) {
589 589
                     return $record;
590 590
                 }
591 591
             }
592
-        } catch(\InvalidArgumentException $e) {
593
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
592
+        } catch (\InvalidArgumentException $e) {
593
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
594 594
             
595 595
             return false;
596
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
597
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
596
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
597
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
598 598
             
599 599
             return false;
600
-        } catch( Exception $e ) {
600
+        } catch (Exception $e) {
601 601
             return false;
602 602
         }
603 603
         
604 604
         return false;
605 605
     }
606 606
 
607
-    public static function geoip2_city_record( $ip_address ) {
607
+    public static function geoip2_city_record($ip_address) {
608 608
         try {
609 609
             $reader = self::geoip2_city_reader();
610 610
 
611
-            if ( $reader ) {
612
-                $record = $reader->city( $ip_address );
611
+            if ($reader) {
612
+                $record = $reader->city($ip_address);
613 613
                 
614
-                if ( !empty( $record->country->isoCode ) ) {
614
+                if (!empty($record->country->isoCode)) {
615 615
                     return $record;
616 616
                 }
617 617
             }
618
-        } catch(\InvalidArgumentException $e) {
619
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
618
+        } catch (\InvalidArgumentException $e) {
619
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
620 620
             
621 621
             return false;
622
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
623
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
622
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
623
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
624 624
             
625 625
             return false;
626
-        } catch( Exception $e ) {
626
+        } catch (Exception $e) {
627 627
             return false;
628 628
         }
629 629
         
630 630
         return false;
631 631
     }
632 632
 
633
-    public static function geoip2_country_code( $ip_address ) {
634
-        $record = self::geoip2_country_record( $ip_address );
635
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
633
+    public static function geoip2_country_code($ip_address) {
634
+        $record = self::geoip2_country_record($ip_address);
635
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
636 636
     }
637 637
 
638 638
     // Find country by IP address.
639
-    public static function get_country_by_ip( $ip = '' ) {
639
+    public static function get_country_by_ip($ip = '') {
640 640
         global $wpinv_ip_address_country;
641 641
         
642
-        if ( !empty( $wpinv_ip_address_country ) ) {
642
+        if (!empty($wpinv_ip_address_country)) {
643 643
             return $wpinv_ip_address_country;
644 644
         }
645 645
         
646
-        if ( empty( $ip ) ) {
646
+        if (empty($ip)) {
647 647
             $ip = wpinv_get_ip();
648 648
         }
649 649
 
650
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
651
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
650
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
651
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
652 652
 
653
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
654
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
653
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
654
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
655 655
                 try {
656
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
657
-                } catch( Exception $e ) {
658
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
656
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
657
+                } catch (Exception $e) {
658
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
659 659
                 }
660
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
661
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
662
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
663
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
660
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
661
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
662
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
663
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
664 664
                 
665
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
665
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
666 666
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
667 667
                 }
668 668
             }
669 669
         }
670 670
 
671
-        if ( empty( $wpinv_ip_address_country ) ) {
671
+        if (empty($wpinv_ip_address_country)) {
672 672
             $wpinv_ip_address_country = wpinv_get_default_country();
673 673
         }
674 674
 
675 675
         return $wpinv_ip_address_country;
676 676
     }
677 677
     
678
-    public static function sanitize_vat_settings( $input ) {
678
+    public static function sanitize_vat_settings($input) {
679 679
         global $wpinv_options;
680 680
         
681 681
         $valid      = false;
682 682
         $message    = '';
683 683
         
684
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
685
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
686
-                $valid = self::offline_check( $input['vat_number'] );
684
+        if (!empty($wpinv_options['vat_vies_check'])) {
685
+            if (empty($wpinv_options['vat_offline_check'])) {
686
+                $valid = self::offline_check($input['vat_number']);
687 687
             } else {
688 688
                 $valid = true;
689 689
             }
690 690
             
691
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
691
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
692 692
         } else {
693
-            $result = self::check_vat( $input['vat_number'] );
693
+            $result = self::check_vat($input['vat_number']);
694 694
             
695
-            if ( empty( $result['valid'] ) ) {
695
+            if (empty($result['valid'])) {
696 696
                 $valid      = false;
697 697
                 $message    = $result['message'];
698 698
             } else {
699
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
700
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
699
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
700
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
701 701
             }
702 702
         }
703 703
 
704
-        if ( $message && self::is_vat_validated() != $valid ) {
705
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
704
+        if ($message && self::is_vat_validated() != $valid) {
705
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
706 706
         }
707 707
 
708 708
         $input['vat_valid'] = $valid;
709 709
         return $input;
710 710
     }
711 711
     
712
-    public static function sanitize_vat_rates( $input ) {
713
-        if( !current_user_can( 'manage_options' ) ) {
714
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
712
+    public static function sanitize_vat_rates($input) {
713
+        if (!current_user_can('manage_options')) {
714
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
715 715
             return $input;
716 716
         }
717 717
         
718 718
         $vat_classes = self::get_rate_classes();
719
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
719
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
720 720
         
721
-        if ( empty( $vat_class ) ) {
722
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
721
+        if (empty($vat_class)) {
722
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
723 723
             
724 724
             return $input;
725 725
         }
726 726
 
727
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
727
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
728 728
 
729
-        if ( $vat_class === '_standard' ) {
729
+        if ($vat_class === '_standard') {
730 730
             // Save the active rates in the invoice settings
731
-            update_option( 'wpinv_tax_rates', $new_rates );
731
+            update_option('wpinv_tax_rates', $new_rates);
732 732
         } else {
733 733
             // Get the existing set of rates
734 734
             $rates = self::get_non_standard_rates();
735 735
             $rates[$vat_class] = $new_rates;
736 736
 
737
-            update_option( 'wpinv_vat_rates', $rates );
737
+            update_option('wpinv_vat_rates', $rates);
738 738
         }
739 739
         
740 740
         return $input;
@@ -744,71 +744,71 @@  discard block
 block discarded – undo
744 744
         $response = array();
745 745
         $response['success'] = false;
746 746
         
747
-        if ( !current_user_can( 'manage_options' ) ) {
748
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
749
-            wp_send_json( $response );
747
+        if (!current_user_can('manage_options')) {
748
+            $response['error'] = __('Invalid access!', 'invoicing');
749
+            wp_send_json($response);
750 750
         }
751 751
         
752
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
753
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
752
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
753
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
754 754
         
755
-        if ( empty( $vat_class_name ) ) {
756
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
757
-            wp_send_json( $response );
755
+        if (empty($vat_class_name)) {
756
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
757
+            wp_send_json($response);
758 758
         }
759 759
         
760 760
         $vat_classes = (array)self::get_rate_classes();
761 761
 
762
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
763
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
764
-            wp_send_json( $response );
762
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
763
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
764
+            wp_send_json($response);
765 765
         }
766 766
         
767
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
768
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
767
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
768
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
769 769
         
770
-        $vat_classes = (array)self::get_rate_classes( true );
771
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
770
+        $vat_classes = (array)self::get_rate_classes(true);
771
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
772 772
         
773
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
773
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
774 774
         
775 775
         $response['success'] = true;
776
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
776
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
777 777
         
778
-        wp_send_json( $response );
778
+        wp_send_json($response);
779 779
     }
780 780
     
781 781
     public static function delete_class() {
782 782
         $response = array();
783 783
         $response['success'] = false;
784 784
         
785
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
786
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
787
-            wp_send_json( $response );
785
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
786
+            $response['error'] = __('Invalid access!', 'invoicing');
787
+            wp_send_json($response);
788 788
         }
789 789
         
790
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
790
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
791 791
         $vat_classes = (array)self::get_rate_classes();
792 792
 
793
-        if ( !isset( $vat_classes[$vat_class] ) ) {
794
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
795
-            wp_send_json( $response );
793
+        if (!isset($vat_classes[$vat_class])) {
794
+            $response['error'] = __('Requested class does not exists', 'invoicing');
795
+            wp_send_json($response);
796 796
         }
797 797
         
798
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
799
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
800
-            wp_send_json( $response );
798
+        if ($vat_class == '_new' || $vat_class == '_standard') {
799
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
800
+            wp_send_json($response);
801 801
         }
802 802
             
803
-        $vat_classes = (array)self::get_rate_classes( true );
804
-        unset( $vat_classes[$vat_class] );
803
+        $vat_classes = (array)self::get_rate_classes(true);
804
+        unset($vat_classes[$vat_class]);
805 805
         
806
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
806
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
807 807
         
808 808
         $response['success'] = true;
809
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
809
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
810 810
         
811
-        wp_send_json( $response );
811
+        wp_send_json($response);
812 812
     }
813 813
     
814 814
     public static function update_eu_rates() {        
@@ -817,72 +817,72 @@  discard block
 block discarded – undo
817 817
         $response['error']      = null;
818 818
         $response['data']       = null;
819 819
         
820
-        if ( !current_user_can( 'manage_options' ) ) {
821
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
822
-            wp_send_json( $response );
820
+        if (!current_user_can('manage_options')) {
821
+            $response['error'] = __('Invalid access!', 'invoicing');
822
+            wp_send_json($response);
823 823
         }
824 824
         
825
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
826
-        $euvatrates = self::request_euvatrates( $group );
825
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
826
+        $euvatrates = self::request_euvatrates($group);
827 827
         
828
-        if ( !empty( $euvatrates ) ) {
829
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
828
+        if (!empty($euvatrates)) {
829
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
830 830
                 $response['success']        = true;
831 831
                 $response['data']['rates']  = $euvatrates['rates'];
832
-            } else if ( !empty( $euvatrates['error'] ) ) {
832
+            } else if (!empty($euvatrates['error'])) {
833 833
                 $response['error']          = $euvatrates['error'];
834 834
             }
835 835
         }
836 836
             
837
-        wp_send_json( $response );
837
+        wp_send_json($response);
838 838
     }
839 839
     
840 840
     public static function hide_vat_fields() {
841
-        $hide = wpinv_get_option( 'vat_disable_fields' );
841
+        $hide = wpinv_get_option('vat_disable_fields');
842 842
         
843
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
843
+        return apply_filters('wpinv_hide_vat_fields', $hide);
844 844
     }
845 845
     
846 846
     public static function same_country_rule() {
847
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
847
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
848 848
         
849
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
849
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
850 850
     }
851 851
     
852 852
     public static function get_vat_name() {
853
-        $vat_name   = wpinv_get_option( 'vat_name' );
854
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
853
+        $vat_name   = wpinv_get_option('vat_name');
854
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
855 855
         
856
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
856
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
857 857
     }
858 858
     
859 859
     public static function get_company_name() {
860
-        $company_name = wpinv_get_option( 'vat_company_name' );
860
+        $company_name = wpinv_get_option('vat_company_name');
861 861
         
862
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
862
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
863 863
     }
864 864
     
865 865
     public static function get_vat_number() {
866
-        $vat_number = wpinv_get_option( 'vat_number' );
866
+        $vat_number = wpinv_get_option('vat_number');
867 867
         
868
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
868
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
869 869
     }
870 870
     
871 871
     public static function is_vat_validated() {
872
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
872
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
873 873
         
874
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
874
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
875 875
     }
876 876
     
877
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
878
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
877
+    public static function sanitize_vat($vat_number, $country_code = '') {        
878
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
879 879
         
880
-        if ( empty( $country_code ) ) {
881
-            $country_code = substr( $vat_number, 0, 2 );
880
+        if (empty($country_code)) {
881
+            $country_code = substr($vat_number, 0, 2);
882 882
         }
883 883
         
884
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
885
-            $vat = str_replace( $country_code, '', $vat_number );
884
+        if (strpos($vat_number, $country_code) === 0) {
885
+            $vat = str_replace($country_code, '', $vat_number);
886 886
         } else {
887 887
             $vat = $country_code . $vat_number;
888 888
         }
@@ -895,140 +895,140 @@  discard block
 block discarded – undo
895 895
         return $return;
896 896
     }
897 897
     
898
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
899
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
898
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
899
+        $vat            = self::sanitize_vat($vat_number, $country_code);
900 900
         $vat_number     = $vat['vat_number'];
901 901
         $country_code   = $vat['iso'];
902 902
         $regex          = array();
903 903
         
904
-        switch ( $country_code ) {
904
+        switch ($country_code) {
905 905
             case 'AT':
906
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
906
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
907 907
                 break;
908 908
             case 'BE':
909
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
909
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
910 910
                 break;
911 911
             case 'BG':
912
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
912
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
913 913
                 break;
914 914
             case 'CH':
915 915
             case 'CHE':
916
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
916
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
917 917
                 break;
918 918
             case 'CY':
919
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
919
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
920 920
                 break;
921 921
             case 'CZ':
922
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
922
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
923 923
                 break;
924 924
             case 'DE':
925
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
925
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
926 926
                 break;
927 927
             case 'DK':
928
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
928
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
929 929
                 break;
930 930
             case 'EE':
931
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
931
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
932 932
                 break;
933 933
             case 'EL':
934
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
934
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
935 935
                 break;
936 936
             case 'ES':
937
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
938
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
939
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
940
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
937
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
938
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
939
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
940
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
941 941
                 break;
942 942
             case 'EU':
943
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
943
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
944 944
                 break;
945 945
             case 'FI':
946
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
946
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
947 947
                 break;
948 948
             case 'FR':
949
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
950
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
951
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
952
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
949
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
950
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
951
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
952
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
953 953
                 break;
954 954
             case 'GB':
955
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
956
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
957
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
958
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
955
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
956
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
957
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
958
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
959 959
                 break;
960 960
             case 'GR':
961
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
961
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
962 962
                 break;
963 963
             case 'HR':
964
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
964
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
965 965
                 break;
966 966
             case 'HU':
967
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
967
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
968 968
                 break;
969 969
             case 'IE':
970
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
971
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
972
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
970
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
971
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
972
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
973 973
                 break;
974 974
             case 'IT':
975
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
975
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
976 976
                 break;
977 977
             case 'LV':
978
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
978
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
979 979
                 break;
980 980
             case 'LT':
981
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
981
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
982 982
                 break;
983 983
             case 'LU':
984
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
984
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
985 985
                 break;
986 986
             case 'MT':
987
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
987
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
988 988
                 break;
989 989
             case 'NL':
990
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
990
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
991 991
                 break;
992 992
             case 'NO':
993
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
993
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
994 994
                 break;
995 995
             case 'PL':
996
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
996
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
997 997
                 break;
998 998
             case 'PT':
999
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
999
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1000 1000
                 break;
1001 1001
             case 'RO':
1002
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1002
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1003 1003
                 break;
1004 1004
             case 'RS':
1005
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1005
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1006 1006
                 break;
1007 1007
             case 'SI':
1008
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1008
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1009 1009
                 break;
1010 1010
             case 'SK':
1011
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1011
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1012 1012
                 break;
1013 1013
             case 'SE':
1014
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1014
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1015 1015
                 break;
1016 1016
             default:
1017 1017
                 $regex = array();
1018 1018
             break;
1019 1019
         }
1020 1020
         
1021
-        if ( empty( $regex ) ) {
1021
+        if (empty($regex)) {
1022 1022
             return false;
1023 1023
         }
1024 1024
         
1025
-        foreach ( $regex as $pattern ) {
1025
+        foreach ($regex as $pattern) {
1026 1026
             $matches = null;
1027
-            preg_match_all( $pattern, $vat_number, $matches );
1027
+            preg_match_all($pattern, $vat_number, $matches);
1028 1028
             
1029
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1030
-                if ( $formatted ) {
1031
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1029
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1030
+                if ($formatted) {
1031
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1032 1032
                 } else {
1033 1033
                     return true;
1034 1034
                 }
@@ -1038,75 +1038,75 @@  discard block
 block discarded – undo
1038 1038
         return false;
1039 1039
     }
1040 1040
     
1041
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1042
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1041
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1042
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1043 1043
         $vat_number     = $vat['vat'];
1044 1044
         $iso            = $vat['iso'];
1045 1045
         
1046
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1046
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1047 1047
         
1048
-        if ( ini_get( 'allow_url_fopen' ) ) {
1049
-            $response = file_get_contents( $url );
1050
-        } else if ( function_exists( 'curl_init' ) ) {
1048
+        if (ini_get('allow_url_fopen')) {
1049
+            $response = file_get_contents($url);
1050
+        } else if (function_exists('curl_init')) {
1051 1051
             $ch = curl_init();
1052 1052
             
1053
-            curl_setopt( $ch, CURLOPT_URL, $url );
1054
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1055
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1056
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1057
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1053
+            curl_setopt($ch, CURLOPT_URL, $url);
1054
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1055
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1056
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1057
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1058 1058
             
1059
-            $response = curl_exec( $ch );
1059
+            $response = curl_exec($ch);
1060 1060
             
1061
-            if ( curl_errno( $ch ) ) {
1062
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1061
+            if (curl_errno($ch)) {
1062
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1063 1063
                 $response = '';
1064 1064
             }
1065 1065
             
1066
-            curl_close( $ch );
1066
+            curl_close($ch);
1067 1067
         } else {
1068
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1068
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1069 1069
         }
1070 1070
         
1071
-        if ( empty( $response ) ) {
1071
+        if (empty($response)) {
1072 1072
             return $result;
1073 1073
         }
1074 1074
 
1075
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1075
+        if (preg_match('/invalid VAT number/i', $response)) {
1076 1076
             return false;
1077
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1078
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1077
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1078
+            $content = explode("valid VAT number", htmlentities($response));
1079 1079
             
1080
-            if ( !empty( $content[1] ) ) {
1081
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1080
+            if (!empty($content[1])) {
1081
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1082 1082
                 
1083
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1083
+                if (!empty($matches[2]) && $matches[3]) {
1084 1084
                     $return = array();
1085 1085
                     
1086
-                    foreach ( $matches[2] as $key => $label ) {
1087
-                        $label = trim( $label );
1086
+                    foreach ($matches[2] as $key => $label) {
1087
+                        $label = trim($label);
1088 1088
                         
1089
-                        switch ( strtolower( $label ) ) {
1089
+                        switch (strtolower($label)) {
1090 1090
                             case 'member state':
1091
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1091
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1092 1092
                             break;
1093 1093
                             case 'vat number':
1094
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1094
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1095 1095
                             break;
1096 1096
                             case 'name':
1097
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1097
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1098 1098
                             break;
1099 1099
                             case 'address':
1100
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1101
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1100
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1101
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1102 1102
                             break;
1103 1103
                             case 'consultation number':
1104
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1104
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1105 1105
                             break;
1106 1106
                         }
1107 1107
                     }
1108 1108
                     
1109
-                    if ( !empty( $return ) ) {
1109
+                    if (!empty($return)) {
1110 1110
                         return $return;
1111 1111
                     }
1112 1112
                 }
@@ -1118,55 +1118,55 @@  discard block
 block discarded – undo
1118 1118
         }
1119 1119
     }
1120 1120
     
1121
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1121
+    public static function check_vat($vat_number, $country_code = '') {        
1122 1122
         $vat_name           = self::get_vat_name();
1123 1123
         
1124 1124
         $return             = array();
1125 1125
         $return['valid']    = false;
1126
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1126
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1127 1127
                 
1128
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1128
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1129 1129
             return $return;
1130 1130
         }
1131 1131
             
1132
-        $response = self::vies_check( $vat_number, $country_code );
1132
+        $response = self::vies_check($vat_number, $country_code);
1133 1133
         
1134
-        if ( $response ) {
1135
-            $return['valid']    = true;
1134
+        if ($response) {
1135
+            $return['valid'] = true;
1136 1136
             
1137
-            if ( is_array( $response ) ) {
1138
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1139
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1137
+            if (is_array($response)) {
1138
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1139
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1140 1140
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1141 1141
             }
1142 1142
         } else {
1143 1143
             $return['valid']    = false;
1144
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1144
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1145 1145
         }
1146 1146
         
1147 1147
         return $return;
1148 1148
     }
1149 1149
     
1150
-    public static function request_euvatrates( $group ) {
1150
+    public static function request_euvatrates($group) {
1151 1151
         $response               = array();
1152 1152
         $response['success']    = false;
1153 1153
         $response['error']      = null;
1154 1154
         $response['eurates']    = null;
1155 1155
         
1156 1156
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1157
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1158
-        $api_response   = wp_remote_get( $euvatrates_url );
1157
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1158
+        $api_response   = wp_remote_get($euvatrates_url);
1159 1159
     
1160 1160
         try {
1161
-            if ( is_wp_error( $api_response ) ) {
1162
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1161
+            if (is_wp_error($api_response)) {
1162
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1163 1163
             } else {
1164
-                $body = json_decode( $api_response['body'] );
1164
+                $body = json_decode($api_response['body']);
1165 1165
                 
1166
-                if ( isset( $body->rates ) ) {
1166
+                if (isset($body->rates)) {
1167 1167
                     $rates = array();
1168 1168
                     
1169
-                    foreach ( $body->rates as $country_code => $rate ) {
1169
+                    foreach ($body->rates as $country_code => $rate) {
1170 1170
                         $vat_rate = array();
1171 1171
                         $vat_rate['country']        = $rate->country;
1172 1172
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1175 1175
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1176 1176
                         
1177
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1177
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1178 1178
                             $vat_rate_group = array();
1179 1179
                             $vat_rate_group['country'] = $rate->country;
1180 1180
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1186,79 +1186,79 @@  discard block
 block discarded – undo
1186 1186
                     }
1187 1187
                     
1188 1188
                     $response['success']    = true;                                
1189
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1189
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1190 1190
                 } else {
1191
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1191
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1192 1192
                 }
1193 1193
             }
1194
-        } catch ( Exception $e ) {
1195
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1194
+        } catch (Exception $e) {
1195
+            $response['error'] = __($e->getMessage(), 'invoicing');
1196 1196
         }
1197 1197
         
1198
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1198
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1199 1199
     }    
1200 1200
     
1201
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1201
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1202 1202
         global $wpi_item_id, $wpi_country;
1203 1203
         
1204
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1205
-            $country_code = trim( $_POST['wpinv_country'] );
1206
-        } else if ( !empty( $_POST['country'] ) ) {
1207
-            $country_code = trim( $_POST['country'] );
1208
-        } else if ( !empty( $wpi_country ) ) {
1204
+        if (!empty($_POST['wpinv_country'])) {
1205
+            $country_code = trim($_POST['wpinv_country']);
1206
+        } else if (!empty($_POST['country'])) {
1207
+            $country_code = trim($_POST['country']);
1208
+        } else if (!empty($wpi_country)) {
1209 1209
             $country_code = $wpi_country;
1210 1210
         } else {
1211
-            $country_code = self::get_user_country( '', $user_id );
1211
+            $country_code = self::get_user_country('', $user_id);
1212 1212
         }
1213 1213
         
1214
-        if ( $is_digital === null && $wpi_item_id ) {
1215
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1214
+        if ($is_digital === null && $wpi_item_id) {
1215
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1216 1216
         }
1217 1217
         
1218
-        if ( !empty( $country_code ) ) {
1219
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1218
+        if (!empty($country_code)) {
1219
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1220 1220
         }
1221 1221
         
1222
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1222
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1223 1223
     }
1224 1224
     
1225
-    public static function tax_label( $label = '' ) {
1225
+    public static function tax_label($label = '') {
1226 1226
         global $wpi_requires_vat;
1227 1227
         
1228
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1229
-            $wpi_requires_vat = self::requires_vat( 0, false );
1228
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1229
+            $wpi_requires_vat = self::requires_vat(0, false);
1230 1230
         }
1231 1231
         
1232
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1232
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1233 1233
     }
1234 1234
     
1235 1235
     public static function standard_rates_label() {
1236
-        return __( 'Standard Rates', 'invoicing' );
1236
+        return __('Standard Rates', 'invoicing');
1237 1237
     }
1238 1238
     
1239
-    public static function get_rate_classes( $with_desc = false ) {        
1240
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1241
-        $classes = maybe_unserialize( $rate_classes_option );
1239
+    public static function get_rate_classes($with_desc = false) {        
1240
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1241
+        $classes = maybe_unserialize($rate_classes_option);
1242 1242
         
1243
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1243
+        if (empty($classes) || !is_array($classes)) {
1244 1244
             $classes = array();
1245 1245
         }
1246 1246
 
1247 1247
         $rate_classes = array();
1248
-        if ( !array_key_exists( '_standard', $classes ) ) {
1249
-            if ( $with_desc ) {
1250
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1248
+        if (!array_key_exists('_standard', $classes)) {
1249
+            if ($with_desc) {
1250
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1251 1251
             } else {
1252 1252
                 $rate_classes['_standard'] = self::standard_rates_label();
1253 1253
             }
1254 1254
         }
1255 1255
         
1256
-        foreach ( $classes as $key => $class ) {
1257
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1258
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1256
+        foreach ($classes as $key => $class) {
1257
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1258
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1259 1259
             
1260
-            if ( $with_desc ) {
1261
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1260
+            if ($with_desc) {
1261
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1262 1262
             } else {
1263 1263
                 $rate_classes[$key] = $name;
1264 1264
             }
@@ -1269,15 +1269,15 @@  discard block
 block discarded – undo
1269 1269
     
1270 1270
     public static function get_all_classes() {        
1271 1271
         $classes            = self::get_rate_classes();
1272
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1272
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1273 1273
         
1274
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1274
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1275 1275
     }
1276 1276
     
1277
-    public static function get_class_desc( $rate_class ) {        
1278
-        $rate_classes = self::get_rate_classes( true );
1277
+    public static function get_class_desc($rate_class) {        
1278
+        $rate_classes = self::get_rate_classes(true);
1279 1279
 
1280
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1280
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1281 1281
             return $rate_classes[$rate_class]['desc'];
1282 1282
         }
1283 1283
         
@@ -1293,106 +1293,106 @@  discard block
 block discarded – undo
1293 1293
             'increased'     => 'Increased'
1294 1294
         );
1295 1295
         
1296
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1296
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1297 1297
     }
1298 1298
 
1299 1299
     public static function get_rules() {
1300 1300
         $vat_rules = array(
1301
-            'digital' => __( 'Digital Product', 'invoicing' ),
1302
-            'physical' => __( 'Physical Product', 'invoicing' )
1301
+            'digital' => __('Digital Product', 'invoicing'),
1302
+            'physical' => __('Physical Product', 'invoicing')
1303 1303
         );
1304
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1304
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1305 1305
     }
1306 1306
 
1307
-    public static function get_vat_rates( $class ) {
1308
-        if ( $class === '_standard' ) {
1307
+    public static function get_vat_rates($class) {
1308
+        if ($class === '_standard') {
1309 1309
             return wpinv_get_tax_rates();
1310 1310
         }
1311 1311
 
1312 1312
         $rates = self::get_non_standard_rates();
1313 1313
 
1314
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1314
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1315 1315
     }
1316 1316
 
1317 1317
     public static function get_non_standard_rates() {
1318
-        $option = get_option( 'wpinv_vat_rates', array());
1319
-        return is_array( $option ) ? $option : array();
1318
+        $option = get_option('wpinv_vat_rates', array());
1319
+        return is_array($option) ? $option : array();
1320 1320
     }
1321 1321
     
1322 1322
     public static function allow_vat_rules() {
1323
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1323
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1324 1324
     }
1325 1325
     
1326 1326
     public static function allow_vat_classes() {
1327 1327
         return false; // TODO
1328
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1328
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1329 1329
     }
1330 1330
     
1331
-    public static function get_item_class( $postID ) {
1332
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1331
+    public static function get_item_class($postID) {
1332
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1333 1333
 
1334
-        if ( empty( $class ) ) {
1334
+        if (empty($class)) {
1335 1335
             $class = '_standard';
1336 1336
         }
1337 1337
         
1338
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1338
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1339 1339
     }
1340 1340
     
1341
-    public static function item_class_label( $postID ) {        
1341
+    public static function item_class_label($postID) {        
1342 1342
         $vat_classes = self::get_all_classes();
1343 1343
         
1344
-        $class = self::get_item_class( $postID );
1345
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1344
+        $class = self::get_item_class($postID);
1345
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1346 1346
         
1347
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1347
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1348 1348
     }
1349 1349
     
1350
-    public static function get_item_rule( $postID ) {        
1351
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1350
+    public static function get_item_rule($postID) {        
1351
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1352 1352
         
1353
-        if ( empty( $rule_type ) ) {        
1353
+        if (empty($rule_type)) {        
1354 1354
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1355 1355
         }
1356 1356
         
1357
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1357
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1358 1358
     }
1359 1359
     
1360
-    public static function item_rule_label( $postID ) {
1360
+    public static function item_rule_label($postID) {
1361 1361
         $vat_rules  = self::get_rules();
1362
-        $vat_rule   = self::get_item_rule( $postID );
1363
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1362
+        $vat_rule   = self::get_item_rule($postID);
1363
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1364 1364
         
1365
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1365
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1366 1366
     }
1367 1367
     
1368
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1369
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1368
+    public static function item_has_digital_rule($item_id = 0) {        
1369
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1370 1370
     }
1371 1371
     
1372
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1373
-        if ( !self::allow_vat_rules() ) {
1372
+    public static function invoice_has_digital_rule($invoice = 0) {        
1373
+        if (!self::allow_vat_rules()) {
1374 1374
             return false;
1375 1375
         }
1376 1376
         
1377
-        if ( empty( $invoice ) ) {
1377
+        if (empty($invoice)) {
1378 1378
             return true;
1379 1379
         }
1380 1380
         
1381
-        if ( is_int( $invoice ) ) {
1382
-            $invoice = new WPInv_Invoice( $invoice );
1381
+        if (is_int($invoice)) {
1382
+            $invoice = new WPInv_Invoice($invoice);
1383 1383
         }
1384 1384
         
1385
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1385
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1386 1386
             return true;
1387 1387
         }
1388 1388
         
1389
-        $cart_items  = $invoice->get_cart_details();
1389
+        $cart_items = $invoice->get_cart_details();
1390 1390
         
1391
-        if ( !empty( $cart_items ) ) {
1391
+        if (!empty($cart_items)) {
1392 1392
             $has_digital_rule = false;
1393 1393
             
1394
-            foreach ( $cart_items as $key => $item ) {
1395
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1394
+            foreach ($cart_items as $key => $item) {
1395
+                if (self::item_has_digital_rule($item['id'])) {
1396 1396
                     $has_digital_rule = true;
1397 1397
                     break;
1398 1398
                 }
@@ -1404,67 +1404,67 @@  discard block
 block discarded – undo
1404 1404
         return $has_digital_rule;
1405 1405
     }
1406 1406
     
1407
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1408
-        if ( !wpinv_use_taxes() ) {
1407
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1408
+        if (!wpinv_use_taxes()) {
1409 1409
             return false;
1410 1410
         }
1411 1411
         
1412 1412
         $is_taxable = true;
1413 1413
 
1414
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1414
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1415 1415
             $is_taxable = false;
1416 1416
         }
1417 1417
         
1418
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1418
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1419 1419
     }
1420 1420
     
1421
-    public static function find_rate( $country, $state, $rate, $class ) {
1421
+    public static function find_rate($country, $state, $rate, $class) {
1422 1422
         global $wpi_zero_tax;
1423 1423
 
1424
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1424
+        if ($class === '_exempt' || $wpi_zero_tax) {
1425 1425
             return 0;
1426 1426
         }
1427 1427
 
1428
-        $tax_rates   = wpinv_get_tax_rates();
1428
+        $tax_rates = wpinv_get_tax_rates();
1429 1429
         
1430
-        if ( $class !== '_standard' ) {
1431
-            $class_rates = self::get_vat_rates( $class );
1430
+        if ($class !== '_standard') {
1431
+            $class_rates = self::get_vat_rates($class);
1432 1432
             
1433
-            if ( is_array( $class_rates ) ) {
1433
+            if (is_array($class_rates)) {
1434 1434
                 $indexed_class_rates = array();
1435 1435
                 
1436
-                foreach ( $class_rates as $key => $cr ) {
1436
+                foreach ($class_rates as $key => $cr) {
1437 1437
                     $indexed_class_rates[$cr['country']] = $cr;
1438 1438
                 }
1439 1439
 
1440
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1440
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1441 1441
                     $tr_country = $tr['country'];
1442
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1442
+                    if (!isset($indexed_class_rates[$tr_country])) {
1443 1443
                         return $tr;
1444 1444
                     }
1445 1445
                     $icr = $indexed_class_rates[$tr_country];
1446
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1446
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1447 1447
 
1448
-                }, $tax_rates, $class_rates );
1448
+                }, $tax_rates, $class_rates);
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        if ( !empty( $tax_rates ) ) {
1453
-            foreach ( $tax_rates as $key => $tax_rate ) {
1454
-                if ( $country != $tax_rate['country'] )
1452
+        if (!empty($tax_rates)) {
1453
+            foreach ($tax_rates as $key => $tax_rate) {
1454
+                if ($country != $tax_rate['country'])
1455 1455
                     continue;
1456 1456
 
1457
-                if ( !empty( $tax_rate['global'] ) ) {
1458
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1459
-                        $rate = number_format( $tax_rate['rate'], 4 );
1457
+                if (!empty($tax_rate['global'])) {
1458
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1459
+                        $rate = number_format($tax_rate['rate'], 4);
1460 1460
                     }
1461 1461
                 } else {
1462
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1462
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1463 1463
                         continue;
1464 1464
 
1465 1465
                     $state_rate = $tax_rate['rate'];
1466
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1467
-                        $rate = number_format( $state_rate, 4 );
1466
+                    if (0 !== $state_rate || !empty($state_rate)) {
1467
+                        $rate = number_format($state_rate, 4);
1468 1468
                     }
1469 1469
                 }
1470 1470
             }
@@ -1473,84 +1473,84 @@  discard block
 block discarded – undo
1473 1473
         return $rate;
1474 1474
     }
1475 1475
     
1476
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1476
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1477 1477
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1478 1478
         
1479 1479
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1480 1480
         $allow_vat_classes = self::allow_vat_classes();
1481
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1481
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1482 1482
 
1483
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1483
+        if ($class === '_exempt' || $wpi_zero_tax) {
1484 1484
             return 0;
1485
-        } else if ( !$allow_vat_classes ) {
1485
+        } else if (!$allow_vat_classes) {
1486 1486
             $class = '_standard';
1487 1487
         }
1488 1488
 
1489
-        if( !empty( $_POST['wpinv_country'] ) ) {
1489
+        if (!empty($_POST['wpinv_country'])) {
1490 1490
             $post_country = $_POST['wpinv_country'];
1491
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1491
+        } elseif (!empty($_POST['wpinv_country'])) {
1492 1492
             $post_country = $_POST['wpinv_country'];
1493
-        } elseif( !empty( $_POST['country'] ) ) {
1493
+        } elseif (!empty($_POST['country'])) {
1494 1494
             $post_country = $_POST['country'];
1495 1495
         } else {
1496 1496
             $post_country = '';
1497 1497
         }
1498 1498
 
1499
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1500
-        $base_country   = wpinv_is_base_country( $country );
1499
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1500
+        $base_country   = wpinv_is_base_country($country);
1501 1501
         
1502
-        $requires_vat   = self::requires_vat( 0, false );
1503
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1504
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1502
+        $requires_vat   = self::requires_vat(0, false);
1503
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1504
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1505 1505
           
1506
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1506
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1507 1507
             $rate = 0;
1508
-        } else if ( $requires_vat ) {
1509
-            $vat_number = self::get_user_vat_number( '', 0, true );
1508
+        } else if ($requires_vat) {
1509
+            $vat_number = self::get_user_vat_number('', 0, true);
1510 1510
             $vat_info   = self::current_vat_data();
1511 1511
             
1512
-            if ( is_array( $vat_info ) ) {
1513
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1512
+            if (is_array($vat_info)) {
1513
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1514 1514
             }
1515 1515
             
1516
-            if ( $country == 'UK' ) {
1516
+            if ($country == 'UK') {
1517 1517
                 $country = 'GB';
1518 1518
             }
1519 1519
 
1520
-            if ( !empty( $vat_number ) ) {
1520
+            if (!empty($vat_number)) {
1521 1521
                 $rate = 0;
1522 1522
             } else {
1523
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1523
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1524 1524
             }
1525 1525
 
1526
-            if ( empty( $vat_number ) && !$is_digital ) {
1527
-                if ( $base_country ) {
1528
-                    $rate = self::find_rate( $country, null, $rate, $class );
1526
+            if (empty($vat_number) && !$is_digital) {
1527
+                if ($base_country) {
1528
+                    $rate = self::find_rate($country, null, $rate, $class);
1529 1529
                 } else {
1530
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1530
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1531 1531
                         $rate = $wpinv_options['eu_fallback_rate'];
1532
-                    } else if( !empty( $country ) ) {
1533
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1532
+                    } else if (!empty($country)) {
1533
+                        $rate = self::find_rate($country, $state, $rate, $class);
1534 1534
                     }
1535 1535
                 }
1536
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1537
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1536
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1537
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1538 1538
                     $rate = $wpinv_options['eu_fallback_rate'];
1539
-                } else if( !empty( $country ) ) {
1540
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1539
+                } else if (!empty($country)) {
1540
+                    $rate = self::find_rate($country, $state, $rate, $class);
1541 1541
                 }
1542 1542
             }
1543 1543
         } else {
1544
-            if ( $is_digital ) {
1544
+            if ($is_digital) {
1545 1545
                 $ip_country_code = self::get_country_by_ip();
1546 1546
                 
1547
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1548
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1547
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1548
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1549 1549
                 } else {
1550
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1550
+                    $rate = self::find_rate($country, $state, $rate, $class);
1551 1551
                 }
1552 1552
             } else {
1553
-                $rate = self::find_rate( $country, $state, $rate, $class );
1553
+                $rate = self::find_rate($country, $state, $rate, $class);
1554 1554
             }
1555 1555
         }
1556 1556
 
@@ -1560,48 +1560,48 @@  discard block
 block discarded – undo
1560 1560
     public static function current_vat_data() {
1561 1561
         global $wpi_session;
1562 1562
         
1563
-        return $wpi_session->get( 'user_vat_data' );
1563
+        return $wpi_session->get('user_vat_data');
1564 1564
     }
1565 1565
     
1566
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1567
-        $user_address = wpinv_get_user_address( $user_id, false );
1566
+    public static function get_user_country($country = '', $user_id = 0) {
1567
+        $user_address = wpinv_get_user_address($user_id, false);
1568 1568
         
1569
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1569
+        if (wpinv_get_option('vat_ip_country_default')) {
1570 1570
             $country = '';
1571 1571
         }
1572 1572
         
1573
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1574
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1573
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1574
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1575 1575
 
1576
-        if ( empty( $result ) ) {
1576
+        if (empty($result)) {
1577 1577
             $result = self::get_country_by_ip();
1578 1578
         }
1579 1579
 
1580 1580
         return $result;
1581 1581
     }
1582 1582
     
1583
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1583
+    public static function set_user_country($country = '', $user_id = 0) {
1584 1584
         global $wpi_userID;
1585 1585
         
1586
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1586
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1587 1587
             $country = wpinv_get_default_country();
1588 1588
         }
1589 1589
         
1590 1590
         return $country;
1591 1591
     }
1592 1592
     
1593
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1593
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1594 1594
         global $wpi_current_id, $wpi_userID;
1595 1595
         
1596
-        if ( !empty( $_POST['new_user'] ) ) {
1596
+        if (!empty($_POST['new_user'])) {
1597 1597
             return '';
1598 1598
         }
1599 1599
         
1600
-        if ( empty( $user_id ) ) {
1601
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1600
+        if (empty($user_id)) {
1601
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1602 1602
         }
1603 1603
 
1604
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1604
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1605 1605
         
1606 1606
         /* TODO
1607 1607
         if ( $is_valid && $vat_number ) {
@@ -1612,36 +1612,36 @@  discard block
 block discarded – undo
1612 1612
         }
1613 1613
         */
1614 1614
 
1615
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1615
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1616 1616
     }
1617 1617
     
1618
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1619
-        if ( empty( $user_id ) ) {
1618
+    public static function get_user_company($company = '', $user_id = 0) {
1619
+        if (empty($user_id)) {
1620 1620
             $user_id = get_current_user_id();
1621 1621
         }
1622 1622
 
1623
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1623
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1624 1624
 
1625
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1625
+        return apply_filters('wpinv_user_company', $company, $user_id);
1626 1626
     }
1627 1627
     
1628
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1629
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1628
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1629
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1630 1630
 
1631
-        if ( is_user_logged_in() && $save ) {
1631
+        if (is_user_logged_in() && $save) {
1632 1632
             $user_id = get_current_user_id();
1633 1633
 
1634
-            if ( !empty( $vat_number ) ) {
1635
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1634
+            if (!empty($vat_number)) {
1635
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1636 1636
             } else {
1637
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1637
+                delete_user_meta($user_id, '_wpinv_vat_number');
1638 1638
             }
1639 1639
 
1640
-            if ( !empty( $company ) ) {
1641
-                update_user_meta( $user_id, '_wpinv_company', $company );
1640
+            if (!empty($company)) {
1641
+                update_user_meta($user_id, '_wpinv_company', $company);
1642 1642
             } else {
1643
-                delete_user_meta( $user_id, '_wpinv_company');
1644
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1643
+                delete_user_meta($user_id, '_wpinv_company');
1644
+                delete_user_meta($user_id, '_wpinv_vat_number');
1645 1645
             }
1646 1646
         }
1647 1647
 
@@ -1651,113 +1651,113 @@  discard block
 block discarded – undo
1651 1651
     public static function ajax_vat_validate() {
1652 1652
         global $wpinv_options, $wpi_session;
1653 1653
         
1654
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1654
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1655 1655
         $response               = array();
1656 1656
         $response['success']    = false;
1657 1657
         
1658
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1659
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1660
-            wp_send_json( $response );
1658
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1659
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1660
+            wp_send_json($response);
1661 1661
         }
1662 1662
         
1663
-        $vat_name   = self::get_vat_name();
1663
+        $vat_name = self::get_vat_name();
1664 1664
         
1665
-        if ( $is_checkout ) {
1665
+        if ($is_checkout) {
1666 1666
             $invoice = wpinv_get_invoice_cart();
1667 1667
             
1668
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1668
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1669 1669
                 $vat_info = array();
1670
-                $wpi_session->set( 'user_vat_data', $vat_info );
1670
+                $wpi_session->set('user_vat_data', $vat_info);
1671 1671
 
1672 1672
                 self::save_user_vat_details();
1673 1673
                 
1674 1674
                 $response['success'] = true;
1675
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1676
-                wp_send_json( $response );
1675
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1676
+                wp_send_json($response);
1677 1677
             }
1678 1678
         }
1679 1679
         
1680
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1681
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1680
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1681
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1682 1682
         
1683
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1684
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1685
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1683
+        $vat_info = $wpi_session->get('user_vat_data');
1684
+        if (!is_array($vat_info) || empty($vat_info)) {
1685
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1686 1686
         }
1687 1687
         
1688
-        if ( empty( $vat_number ) ) {
1689
-            if ( $is_checkout ) {
1688
+        if (empty($vat_number)) {
1689
+            if ($is_checkout) {
1690 1690
                 $response['success'] = true;
1691
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1691
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1692 1692
                 
1693
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1693
+                $vat_info = $wpi_session->get('user_vat_data');
1694 1694
                 $vat_info['number'] = "";
1695 1695
                 $vat_info['valid'] = true;
1696 1696
                 
1697
-                self::save_user_vat_details( $company );
1697
+                self::save_user_vat_details($company);
1698 1698
             } else {
1699
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1699
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1700 1700
                 
1701 1701
                 $vat_info['valid'] = false;
1702 1702
             }
1703 1703
 
1704
-            $wpi_session->set( 'user_vat_data', $vat_info );
1705
-            wp_send_json( $response );
1704
+            $wpi_session->set('user_vat_data', $vat_info);
1705
+            wp_send_json($response);
1706 1706
         }
1707 1707
         
1708
-        if ( empty( $company ) ) {
1708
+        if (empty($company)) {
1709 1709
             $vat_info['valid'] = false;
1710
-            $wpi_session->set( 'user_vat_data', $vat_info );
1710
+            $wpi_session->set('user_vat_data', $vat_info);
1711 1711
             
1712
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1713
-            wp_send_json( $response );
1712
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1713
+            wp_send_json($response);
1714 1714
         }
1715 1715
         
1716
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1717
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1716
+        if (!empty($wpinv_options['vat_vies_check'])) {
1717
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1718 1718
                 $vat_info['valid'] = false;
1719
-                $wpi_session->set( 'user_vat_data', $vat_info );
1719
+                $wpi_session->set('user_vat_data', $vat_info);
1720 1720
                 
1721
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1722
-                wp_send_json( $response );
1721
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1722
+                wp_send_json($response);
1723 1723
             }
1724 1724
             
1725 1725
             $response['success'] = true;
1726
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1726
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1727 1727
         } else {
1728
-            $result = self::check_vat( $vat_number );
1728
+            $result = self::check_vat($vat_number);
1729 1729
             
1730
-            if ( empty( $result['valid'] ) ) {
1730
+            if (empty($result['valid'])) {
1731 1731
                 $response['error'] = $result['message'];
1732
-                wp_send_json( $response );
1732
+                wp_send_json($response);
1733 1733
             }
1734 1734
             
1735
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1736
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1735
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1736
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1737 1737
             
1738
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1738
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1739 1739
 
1740
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1740
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1741 1741
                 $response['success'] = true;
1742
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1742
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1743 1743
             } else {           
1744 1744
                 $vat_info['valid'] = false;
1745
-                $wpi_session->set( 'user_vat_data', $vat_info );
1745
+                $wpi_session->set('user_vat_data', $vat_info);
1746 1746
                 
1747 1747
                 $response['success'] = false;
1748
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1749
-                wp_send_json( $response );
1748
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1749
+                wp_send_json($response);
1750 1750
             }
1751 1751
         }
1752 1752
         
1753
-        if ( $is_checkout ) {
1754
-            self::save_user_vat_details( $company, $vat_number );
1753
+        if ($is_checkout) {
1754
+            self::save_user_vat_details($company, $vat_number);
1755 1755
 
1756
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1757
-            $wpi_session->set( 'user_vat_data', $vat_info );
1756
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1757
+            $wpi_session->set('user_vat_data', $vat_info);
1758 1758
         }
1759 1759
 
1760
-        wp_send_json( $response );
1760
+        wp_send_json($response);
1761 1761
     }
1762 1762
     
1763 1763
     public static function ajax_vat_reset() {
@@ -1766,161 +1766,161 @@  discard block
 block discarded – undo
1766 1766
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1767 1767
         $vat_number = self::get_user_vat_number();
1768 1768
         
1769
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1770
-        $wpi_session->set( 'user_vat_data', $vat_info );
1769
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1770
+        $wpi_session->set('user_vat_data', $vat_info);
1771 1771
         
1772 1772
         $response                       = array();
1773 1773
         $response['success']            = true;
1774 1774
         $response['data']['company']    = $company;
1775 1775
         $response['data']['number']     = $vat_number;
1776 1776
         
1777
-        wp_send_json( $response );
1777
+        wp_send_json($response);
1778 1778
     }
1779 1779
     
1780
-    public static function checkout_vat_validate( $valid_data, $post ) {
1780
+    public static function checkout_vat_validate($valid_data, $post) {
1781 1781
         global $wpinv_options, $wpi_session;
1782 1782
         
1783
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1783
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1784 1784
         
1785
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1786
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1785
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1786
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1787 1787
             return;
1788 1788
         }
1789 1789
         
1790
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1791
-        $wpi_session->set( 'user_vat_data', null );
1790
+        $vat_saved = $wpi_session->get('user_vat_data');
1791
+        $wpi_session->set('user_vat_data', null);
1792 1792
         
1793 1793
         $invoice        = wpinv_get_invoice_cart();
1794 1794
         $amount         = $invoice->get_total();
1795
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1796
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1795
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1796
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1797 1797
         
1798
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1799
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1800
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1801
-        if ( empty( $country ) ) {
1798
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1799
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1800
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1801
+        if (empty($country)) {
1802 1802
             $country = wpinv_default_billing_country();
1803 1803
         }
1804 1804
         
1805
-        if ( !$is_digital && $no_vat ) {
1805
+        if (!$is_digital && $no_vat) {
1806 1806
             return;
1807 1807
         }
1808 1808
             
1809
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1809
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1810 1810
         
1811 1811
         $ip_country_code    = self::get_country_by_ip();
1812
-        $is_eu_state        = self::is_eu_state( $country );
1813
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1812
+        $is_eu_state        = self::is_eu_state($country);
1813
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1814 1814
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1815 1815
         
1816
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1816
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1817 1817
             $vat_data['adddress_confirmed'] = false;
1818 1818
             
1819
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1820
-                if ( $ip_country_code != $country ) {
1821
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1819
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1820
+                if ($ip_country_code != $country) {
1821
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1822 1822
                 }
1823 1823
             } else {
1824 1824
                 $vat_data['adddress_confirmed'] = true;
1825 1825
             }
1826 1826
         }
1827 1827
         
1828
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1829
-            if ( $is_eu_state ) {
1830
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1831
-            } else if ( $is_digital && $is_eu_state_ip ) {
1832
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1828
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1829
+            if ($is_eu_state) {
1830
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1831
+            } else if ($is_digital && $is_eu_state_ip) {
1832
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1833 1833
             }
1834 1834
         }
1835 1835
         
1836
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1836
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1837 1837
             return;
1838 1838
         }
1839 1839
 
1840
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1841
-            $vat_data['valid']  = $vat_saved['valid'];
1840
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1841
+            $vat_data['valid'] = $vat_saved['valid'];
1842 1842
         }
1843 1843
             
1844
-        if ( $company !== null ) {
1844
+        if ($company !== null) {
1845 1845
             $vat_data['company'] = $company;
1846 1846
         }
1847 1847
 
1848 1848
         $message = '';
1849
-        if ( $vat_number !== null ) {
1849
+        if ($vat_number !== null) {
1850 1850
             $vat_data['number'] = $vat_number;
1851 1851
             
1852
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1853
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1854
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1852
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1853
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1854
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1855 1855
                         $vat_data['valid'] = false;
1856 1856
                     }
1857 1857
                 } else {
1858
-                    $result = self::check_vat( $vat_number );
1858
+                    $result = self::check_vat($vat_number);
1859 1859
                     
1860
-                    if ( !empty( $result['valid'] ) ) {                
1860
+                    if (!empty($result['valid'])) {                
1861 1861
                         $vat_data['valid'] = true;
1862
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1863
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1862
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1863
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1864 1864
                     
1865
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1865
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1866 1866
 
1867
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1867
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1868 1868
                             $vat_data['valid'] = false;
1869 1869
                             
1870
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1870
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1871 1871
                         }
1872 1872
                     } else {
1873
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1873
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1874 1874
                     }
1875 1875
                 }
1876 1876
                 
1877
-                if ( !$vat_data['valid'] ) {
1878
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1879
-                    wpinv_set_error( 'vat_validation', $error );
1877
+                if (!$vat_data['valid']) {
1878
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1879
+                    wpinv_set_error('vat_validation', $error);
1880 1880
                 }
1881 1881
             }
1882 1882
         }
1883 1883
 
1884
-        $wpi_session->set( 'user_vat_data', $vat_data );
1884
+        $wpi_session->set('user_vat_data', $vat_data);
1885 1885
     }
1886 1886
     
1887
-    public static function checkout_vat_fields( $billing_details ) {
1887
+    public static function checkout_vat_fields($billing_details) {
1888 1888
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1889 1889
         
1890 1890
         $ip_address         = wpinv_get_ip();
1891 1891
         $ip_country_code    = self::get_country_by_ip();
1892 1892
         
1893
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1893
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1894 1894
         $invoice            = wpinv_get_invoice_cart();
1895
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1895
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1896 1896
         $wpi_country        = $invoice->country;
1897 1897
         
1898
-        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital );
1898
+        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital);
1899 1899
         $wpi_requires_vat   = $requires_vat;
1900 1900
         
1901 1901
         $company            = is_user_logged_in() ? self::get_user_company() : '';
1902 1902
         $vat_number         = self::get_user_vat_number();
1903 1903
         
1904
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1905
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1904
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1905
+        $vat_info           = $wpi_session->get('user_vat_data');
1906 1906
 
1907
-        if ( is_array( $vat_info ) ) {
1908
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1909
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1910
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1907
+        if (is_array($vat_info)) {
1908
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1909
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1910
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1911 1911
         }
1912 1912
         
1913 1913
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1914 1914
 
1915
-        if ( $ip_country_code == 'UK' ) {
1915
+        if ($ip_country_code == 'UK') {
1916 1916
             $ip_country_code = 'GB';
1917 1917
         }
1918 1918
         
1919
-        if ( $selected_country == 'UK' ) {
1919
+        if ($selected_country == 'UK') {
1920 1920
             $selected_country = 'GB';
1921 1921
         }
1922 1922
         
1923
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1923
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1924 1924
             $requires_vat = false;
1925 1925
         }
1926 1926
 
@@ -1928,52 +1928,52 @@  discard block
 block discarded – undo
1928 1928
         $display_validate_btn   = 'none';
1929 1929
         $display_reset_btn      = 'none';
1930 1930
         
1931
-        if ( !empty( $vat_number ) && $validated ) {
1932
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1931
+        if (!empty($vat_number) && $validated) {
1932
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1933 1933
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1934 1934
             $display_reset_btn      = 'block';
1935 1935
         } else {
1936
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1937
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1936
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1937
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1938 1938
             $display_validate_btn   = 'block';
1939 1939
         }
1940 1940
         
1941
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1941
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1942 1942
         ?>
1943 1943
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1944 1944
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1945
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1945
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1946 1946
                 <div id="wpinv-fields-box" class="panel-body">
1947 1947
                     <p id="wpi_show_vat_note">
1948
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1948
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1949 1949
                     </p>
1950 1950
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1951 1951
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1952
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1952
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1953 1953
                             <?php
1954
-                            echo wpinv_html_text( array(
1954
+                            echo wpinv_html_text(array(
1955 1955
                                     'id'            => 'wpinv_company',
1956 1956
                                     'name'          => 'wpinv_company',
1957 1957
                                     'value'         => $company,
1958 1958
                                     'class'         => 'wpi-input form-control',
1959
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1960
-                                ) );
1959
+                                    'placeholder'   => __('Company name', 'invoicing'),
1960
+                                ));
1961 1961
                             ?>
1962 1962
                         </p>
1963 1963
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1964
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1964
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1965 1965
                             <span id="wpinv_vat_number-wrap">
1966 1966
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1967
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1968
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1967
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1968
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1969 1969
                             </span>
1970 1970
                         </p>
1971 1971
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1972
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1973
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1972
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1973
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1974 1974
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1975 1975
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1976
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1976
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1977 1977
                         </p>
1978 1978
                     </div>
1979 1979
                 </div>
@@ -1987,32 +1987,32 @@  discard block
 block discarded – undo
1987 1987
                 </span>
1988 1988
             </div>
1989 1989
         </div>
1990
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1991
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1990
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1991
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1992 1992
         ?>
1993 1993
         <div class="wpi-ip-info clearfix panel panel-info">
1994 1994
             <div id="wpinv-fields-box" class="panel-body">
1995
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
1995
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
1996 1996
             </div>
1997 1997
         </div>
1998 1998
         <?php }
1999 1999
     }
2000 2000
     
2001
-    public static function show_vat_notice( $invoice ) {
2002
-        if ( empty( $invoice ) ) {
2001
+    public static function show_vat_notice($invoice) {
2002
+        if (empty($invoice)) {
2003 2003
             return NULL;
2004 2004
         }
2005 2005
         
2006
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2007
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2008
-        if ( $label || $notice ) {
2006
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2007
+        $notice     = wpinv_get_option('vat_invoice_notice');
2008
+        if ($label || $notice) {
2009 2009
         ?>
2010 2010
         <div class="row wpinv-vat-notice">
2011 2011
             <div class="col-sm-12">
2012
-                <?php if ( $label ) { ?>
2013
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2014
-                <?php } if ( $notice ) { ?>
2015
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2012
+                <?php if ($label) { ?>
2013
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2014
+                <?php } if ($notice) { ?>
2015
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2016 2016
                 <?php } ?>
2017 2017
             </div>
2018 2018
         </div>
Please login to merge, or discard this patch.