Passed
Push — master ( 0a9164...47344e )
by Brian
20:43
created
templates/wpinv-checkout-cart.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -6,144 +6,144 @@
 block discarded – undo
6 6
 global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns;
7 7
 $invoice            = wpinv_get_invoice_cart();
8 8
 $currency           = $invoice->get_currency();
9
-$cart_items         = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details();
9
+$cart_items         = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details();
10 10
 $quantities_enabled = wpinv_item_quantities_enabled();
11 11
 $use_taxes          = wpinv_use_taxes();
12 12
 $tax_label          = $wpinv_euvat->tax_label();
13
-$tax_title          = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
13
+$tax_title          = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
14 14
 ?>
15 15
 <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
16 16
     <thead>
17 17
         <tr class="wpinv_cart_header_row">
18
-            <?php do_action( 'wpinv_checkout_table_header_first' ); ?>
19
-            <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
20
-            <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
21
-            <?php if ( $quantities_enabled ) { ?>
22
-            <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
18
+            <?php do_action('wpinv_checkout_table_header_first'); ?>
19
+            <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
20
+            <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
21
+            <?php if ($quantities_enabled) { ?>
22
+            <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
23 23
             <?php } ?>
24
-            <?php if ( $use_taxes ) { ?>
24
+            <?php if ($use_taxes) { ?>
25 25
             <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
26 26
             <?php } ?>
27
-            <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
28
-            <?php do_action( 'wpinv_checkout_table_header_last' ); ?>
27
+            <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
28
+            <?php do_action('wpinv_checkout_table_header_last'); ?>
29 29
         </tr>
30 30
     </thead>
31 31
     <tbody>
32 32
         <?php
33
-            do_action( 'wpinv_cart_items_before' );
33
+            do_action('wpinv_cart_items_before');
34 34
             
35
-            if ( $cart_items ) {
36
-                foreach ( $cart_items as $key => $item ) {
37
-                    $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL;
35
+            if ($cart_items) {
36
+                foreach ($cart_items as $key => $item) {
37
+                    $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL;
38 38
                 ?>
39
-                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
40
-                    <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?>
39
+                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
40
+                    <?php do_action('wpinv_checkout_table_body_first', $item); ?>
41 41
                     <td class="wpinv_cart_item_name text-left">
42 42
                         <?php
43
-                            if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
43
+                            if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
44 44
                                 echo '<div class="wpinv_cart_item_image">';
45
-                                    echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
45
+                                    echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
46 46
                                 echo '</div>';
47 47
                             }
48
-                            $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
48
+                            $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
49 49
                             echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>';
50
-                            $summary = apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice );
51
-                            if ( !empty( $summary ) ) {
50
+                            $summary = apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice);
51
+                            if (!empty($summary)) {
52 52
                                 echo $summary;
53 53
                             }
54 54
                         ?>
55 55
                     </td>
56 56
                     <td class="wpinv_cart_item_price text-right">
57 57
                         <?php 
58
-                        echo wpinv_cart_item_price( $item, $currency );
59
-                        do_action( 'wpinv_checkout_cart_item_price_after', $item, $key );
58
+                        echo wpinv_cart_item_price($item, $currency);
59
+                        do_action('wpinv_checkout_cart_item_price_after', $item, $key);
60 60
                         ?>
61 61
                     </td>
62
-                    <?php if ( $quantities_enabled ) { ?>
62
+                    <?php if ($quantities_enabled) { ?>
63 63
                     <td class="wpinv_cart_item_qty text-right">
64 64
                         <?php
65
-                        echo wpinv_get_cart_item_quantity( $item );
66
-                        do_action( 'wpinv_cart_item_quantitiy', $item, $key );
65
+                        echo wpinv_get_cart_item_quantity($item);
66
+                        do_action('wpinv_cart_item_quantitiy', $item, $key);
67 67
                         ?>
68 68
                     </td>
69 69
                     <?php } ?>
70
-                    <?php if ( $use_taxes ) { ?>
70
+                    <?php if ($use_taxes) { ?>
71 71
                     <td class="wpinv_cart_item_tax text-right">
72 72
                         <?php
73 73
 
74
-                        if ( $invoice->is_taxable() ) {
75
-                            echo wpinv_cart_item_tax( $item, $currency );
74
+                        if ($invoice->is_taxable()) {
75
+                            echo wpinv_cart_item_tax($item, $currency);
76 76
                         } else {
77 77
                             echo 0;
78 78
                         }
79 79
 
80 80
                         //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() );
81
-                        do_action( 'wpinv_cart_item_tax', $item, $key );
81
+                        do_action('wpinv_cart_item_tax', $item, $key);
82 82
                         ?>
83 83
                     </td>
84 84
                     <?php } ?>
85 85
                     <td class="wpinv_cart_item_subtotal text-right">
86 86
                         <?php
87
-                        echo wpinv_cart_item_subtotal( $item, $currency );
88
-                        do_action( 'wpinv_cart_item_subtotal', $item, $key );
87
+                        echo wpinv_cart_item_subtotal($item, $currency);
88
+                        do_action('wpinv_cart_item_subtotal', $item, $key);
89 89
                         ?>
90 90
                     </td>
91
-                    <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?>
91
+                    <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?>
92 92
                 </tr>
93 93
             <?php } ?>
94 94
         <?php } ?>
95
-        <?php do_action( 'wpinv_cart_items_middle' ); ?>
96
-        <?php do_action( 'wpinv_cart_items_after' ); ?>
95
+        <?php do_action('wpinv_cart_items_middle'); ?>
96
+        <?php do_action('wpinv_cart_items_after'); ?>
97 97
     </tbody>
98 98
     <tfoot>
99 99
         <?php $cart_columns = wpinv_checkout_cart_columns(); ?>
100
-        <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?>
100
+        <?php if (has_action('wpinv_cart_footer_buttons')) { ?>
101 101
             <tr class="wpinv_cart_footer_row">
102
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
103
-                <td colspan="<?php echo ( $cart_columns ); ?>">
104
-                    <?php do_action( 'wpinv_cart_footer_buttons' ); ?>
102
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
103
+                <td colspan="<?php echo ($cart_columns); ?>">
104
+                    <?php do_action('wpinv_cart_footer_buttons'); ?>
105 105
                 </td>
106
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
106
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
107 107
             </tr>
108 108
         <?php } ?>
109 109
 
110
-        <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?>
111
-            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
112
-                <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?>
113
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
114
-                    <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
110
+        <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?>
111
+            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
112
+                <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?>
113
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
114
+                    <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
115 115
                 </td>
116 116
                 <td class="wpinv_cart_subtotal text-right">
117
-                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items, $currency ); ?></span>
117
+                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items, $currency); ?></span>
118 118
                 </td>
119
-                <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?>
119
+                <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?>
120 120
             </tr>
121 121
         <?php } ?>
122 122
         
123
-        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?>
123
+        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?>
124 124
 
125
-        <?php if ( $use_taxes ) { ?>
126
-            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
127
-                <?php do_action( 'wpinv_checkout_table_tax_first' ); ?>
128
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
125
+        <?php if ($use_taxes) { ?>
126
+            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
127
+                <?php do_action('wpinv_checkout_table_tax_first'); ?>
128
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
129 129
                     <strong><?php echo $tax_label; ?>:</strong>
130 130
                 </td>
131 131
                 <td class="wpinv_cart_tax text-right">
132
-                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items, false, $currency, $invoice ) ); ?></span>
132
+                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items, false, $currency, $invoice)); ?></span>
133 133
                 </td>
134
-                <?php do_action( 'wpinv_checkout_table_tax_last' ); ?>
134
+                <?php do_action('wpinv_checkout_table_tax_last'); ?>
135 135
             </tr>
136 136
         <?php } ?>
137 137
 
138 138
         <tr class="wpinv_cart_footer_row wpinv_cart_total_row">
139
-            <?php do_action( 'wpinv_checkout_table_footer_first' ); ?>
140
-            <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
141
-                <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
139
+            <?php do_action('wpinv_checkout_table_footer_first'); ?>
140
+            <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
141
+                <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
142 142
             </td>
143 143
             <td class="wpinv_cart_total text-right">
144
-                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span>
144
+                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span>
145 145
             </td>
146
-            <?php do_action( 'wpinv_checkout_table_footer_last' ); ?>
146
+            <?php do_action('wpinv_checkout_table_footer_last'); ?>
147 147
         </tr>
148 148
     </tfoot>
149 149
 </table>
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +781 added lines, -781 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  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
     
@@ -28,48 +28,48 @@  discard block
 block discarded – undo
28 28
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
29 29
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
30 30
  */
31
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
32
-    if ( empty( $invoice_data ) ) {
31
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
32
+    if (empty($invoice_data)) {
33 33
         return false;
34 34
     }
35 35
     
36
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
37
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
36
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
37
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
38 38
     }
39 39
     
40 40
     // If no user id is provided, default to the current user id
41
-    if ( empty( $invoice_data['user_id'] ) ) {
41
+    if (empty($invoice_data['user_id'])) {
42 42
         $invoice_data['user_id'] = get_current_user_id();
43 43
     }
44 44
     
45
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
45
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
46 46
     
47
-    if ( empty( $invoice_data['status'] ) ) {
47
+    if (empty($invoice_data['status'])) {
48 48
         $invoice_data['status'] = 'wpi-pending';
49 49
     }
50 50
 
51
-    if ( empty( $invoice_data['post_type'] ) ) {
51
+    if (empty($invoice_data['post_type'])) {
52 52
         $invoice_data['post_type'] = 'wpi_invoice';
53 53
     }
54 54
     
55
-    if ( empty( $invoice_data['ip'] ) ) {
55
+    if (empty($invoice_data['ip'])) {
56 56
         $invoice_data['ip'] = wpinv_get_ip();
57 57
     }
58 58
 
59 59
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
60 60
     $default_args = array(
61
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
62
-        'user_id'       => (int)$invoice_data['user_id'],
61
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
62
+        'user_id'       => (int) $invoice_data['user_id'],
63 63
         'status'        => $invoice_data['status'],
64 64
         'post_type'     => $invoice_data['post_type'],
65 65
     );
66 66
 
67
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
68
-    if ( is_wp_error( $invoice ) ) {
67
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
68
+    if (is_wp_error($invoice)) {
69 69
         return $wp_error ? $invoice : 0;
70 70
     }
71 71
     
72
-    if ( empty( $invoice_data['invoice_id'] ) ) {
72
+    if (empty($invoice_data['invoice_id'])) {
73 73
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
74 74
     }
75 75
     
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
         'discount'              => array(),
93 93
     );
94 94
 
95
-    if ( $user_id = (int)$invoice->get_user_id() ) {
96
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
97
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
95
+    if ($user_id = (int) $invoice->get_user_id()) {
96
+        if ($user_address = wpinv_get_user_address($user_id)) {
97
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
98 98
         }
99 99
     }
100 100
     
101
-    if ( empty( $invoice_data['user_info'] ) ) {
101
+    if (empty($invoice_data['user_info'])) {
102 102
         $invoice_data['user_info'] = array();
103 103
     }
104 104
     
105
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
105
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
106 106
     
107
-    if ( empty( $user_info['first_name'] ) ) {
107
+    if (empty($user_info['first_name'])) {
108 108
         $user_info['first_name'] = $default_user_info['first_name'];
109 109
         $user_info['last_name'] = $default_user_info['last_name'];
110 110
     }
111 111
     
112
-    if ( empty( $user_info['country'] ) ) {
112
+    if (empty($user_info['country'])) {
113 113
         $user_info['country'] = $default_user_info['country'];
114 114
         $user_info['state'] = $default_user_info['state'];
115 115
         $user_info['city'] = $default_user_info['city'];
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
         $user_info['phone'] = $default_user_info['phone'];
119 119
     }
120 120
     
121
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
122
-        $user_info['discount'] = (array)$user_info['discount'];
121
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
122
+        $user_info['discount'] = (array) $user_info['discount'];
123 123
     }
124 124
 
125 125
     // Payment details
126 126
     $payment_details = array();
127
-    if ( !empty( $invoice_data['payment_details'] ) ) {
127
+    if (!empty($invoice_data['payment_details'])) {
128 128
         $default_payment_details = array(
129 129
             'gateway'           => 'manual',
130 130
             'gateway_title'     => '',
@@ -132,56 +132,56 @@  discard block
 block discarded – undo
132 132
             'transaction_id'    => '',
133 133
         );
134 134
         
135
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
135
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
136 136
         
137
-        if ( empty( $payment_details['gateway'] ) ) {
137
+        if (empty($payment_details['gateway'])) {
138 138
             $payment_details['gateway'] = 'manual';
139 139
         }
140 140
         
141
-        if ( empty( $payment_details['currency'] ) ) {
141
+        if (empty($payment_details['currency'])) {
142 142
             $payment_details['currency'] = wpinv_get_default_country();
143 143
         }
144 144
         
145
-        if ( empty( $payment_details['gateway_title'] ) ) {
146
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
145
+        if (empty($payment_details['gateway_title'])) {
146
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
147 147
         }
148 148
     }
149 149
     
150
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
151
-    
152
-    if ( !empty( $payment_details ) ) {
153
-        $invoice->set( 'currency', $payment_details['currency'] );
154
-        $invoice->set( 'gateway', $payment_details['gateway'] );
155
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
156
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
157
-    }
158
-    
159
-    $invoice->set( 'user_info', $user_info );
160
-    $invoice->set( 'first_name', $user_info['first_name'] );
161
-    $invoice->set( 'last_name', $user_info['last_name'] );
162
-    $invoice->set( 'address', $user_info['address'] );
163
-    $invoice->set( 'company', $user_info['company'] );
164
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
165
-    $invoice->set( 'phone', $user_info['phone'] );
166
-    $invoice->set( 'city', $user_info['city'] );
167
-    $invoice->set( 'country', $user_info['country'] );
168
-    $invoice->set( 'state', $user_info['state'] );
169
-    $invoice->set( 'zip', $user_info['zip'] );
170
-    $invoice->set( 'discounts', $user_info['discount'] );
171
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
172
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
173
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
174
-    
175
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
176
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
177
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
178
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
179
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
180
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
150
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
151
+    
152
+    if (!empty($payment_details)) {
153
+        $invoice->set('currency', $payment_details['currency']);
154
+        $invoice->set('gateway', $payment_details['gateway']);
155
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
156
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
157
+    }
158
+    
159
+    $invoice->set('user_info', $user_info);
160
+    $invoice->set('first_name', $user_info['first_name']);
161
+    $invoice->set('last_name', $user_info['last_name']);
162
+    $invoice->set('address', $user_info['address']);
163
+    $invoice->set('company', $user_info['company']);
164
+    $invoice->set('vat_number', $user_info['vat_number']);
165
+    $invoice->set('phone', $user_info['phone']);
166
+    $invoice->set('city', $user_info['city']);
167
+    $invoice->set('country', $user_info['country']);
168
+    $invoice->set('state', $user_info['state']);
169
+    $invoice->set('zip', $user_info['zip']);
170
+    $invoice->set('discounts', $user_info['discount']);
171
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
172
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
173
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
174
+    
175
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
176
+        foreach ($invoice_data['cart_details'] as $key => $item) {
177
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
178
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
179
+            $name           = !empty($item['name']) ? $item['name'] : '';
180
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
181 181
             
182
-            $post_item  = new WPInv_Item( $item_id );
183
-            if ( !empty( $post_item ) ) {
184
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
182
+            $post_item = new WPInv_Item($item_id);
183
+            if (!empty($post_item)) {
184
+                $name       = !empty($name) ? $name : $post_item->get_name();
185 185
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
186 186
             } else {
187 187
                 continue;
@@ -191,262 +191,262 @@  discard block
 block discarded – undo
191 191
                 'name'          => $name,
192 192
                 'quantity'      => $quantity,
193 193
                 'item_price'    => $item_price,
194
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
195
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
196
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
197
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
198
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
194
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
195
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
196
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
197
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
198
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
199 199
             );
200 200
 
201
-            $invoice->add_item( $item_id, $args );
201
+            $invoice->add_item($item_id, $args);
202 202
         }
203 203
     }
204 204
 
205
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
205
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
206 206
 
207
-    if ( isset( $invoice_data['post_date'] ) ) {
208
-        $invoice->set( 'date', $invoice_data['post_date'] );
207
+    if (isset($invoice_data['post_date'])) {
208
+        $invoice->set('date', $invoice_data['post_date']);
209 209
     }
210 210
     
211 211
     // Invoice due date
212
-    if ( isset( $invoice_data['due_date'] ) ) {
213
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
212
+    if (isset($invoice_data['due_date'])) {
213
+        $invoice->set('due_date', $invoice_data['due_date']);
214 214
     }
215 215
     
216 216
     $invoice->save();
217 217
     
218 218
     // Add notes
219
-    if ( !empty( $invoice_data['private_note'] ) ) {
220
-        $invoice->add_note( $invoice_data['private_note'] );
219
+    if (!empty($invoice_data['private_note'])) {
220
+        $invoice->add_note($invoice_data['private_note']);
221 221
     }
222
-    if ( !empty( $invoice_data['user_note'] ) ) {
223
-        $invoice->add_note( $invoice_data['user_note'], true );
222
+    if (!empty($invoice_data['user_note'])) {
223
+        $invoice->add_note($invoice_data['user_note'], true);
224 224
     }
225 225
     
226
-    if ( $invoice->is_quote() ) {
226
+    if ($invoice->is_quote()) {
227 227
 
228
-        if ( isset( $invoice_data['valid_until'] ) ) {
229
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
228
+        if (isset($invoice_data['valid_until'])) {
229
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
230 230
         }
231 231
         return $invoice;
232 232
 
233 233
     }
234 234
 
235
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
235
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
236 236
 
237
-    if ( ! empty( $invoice->ID ) ) {
237
+    if (!empty($invoice->ID)) {
238 238
         global $wpi_userID, $wpinv_ip_address_country;
239 239
         
240 240
         $checkout_session = wpinv_get_checkout_session();
241 241
         
242 242
         $data_session                   = array();
243 243
         $data_session['invoice_id']     = $invoice->ID;
244
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
244
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
245 245
         
246
-        wpinv_set_checkout_session( $data_session );
246
+        wpinv_set_checkout_session($data_session);
247 247
         
248
-        $wpi_userID         = (int)$invoice->get_user_id();
248
+        $wpi_userID         = (int) $invoice->get_user_id();
249 249
         
250
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
250
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
251 251
         $_POST['state']     = $invoice->state;
252 252
 
253
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
254
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
253
+        $invoice->set('country', sanitize_text_field($_POST['country']));
254
+        $invoice->set('state', sanitize_text_field($_POST['state']));
255 255
         
256 256
         $wpinv_ip_address_country = $invoice->country;
257 257
         
258
-        $invoice = $invoice->recalculate_totals( true );
258
+        $invoice = $invoice->recalculate_totals(true);
259 259
         
260
-        wpinv_set_checkout_session( $checkout_session );
260
+        wpinv_set_checkout_session($checkout_session);
261 261
                     
262 262
         return $invoice;
263 263
     }
264 264
     
265
-    if ( $wp_error ) {
266
-        if ( is_wp_error( $invoice ) ) {
265
+    if ($wp_error) {
266
+        if (is_wp_error($invoice)) {
267 267
             return $invoice;
268 268
         } else {
269
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
269
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
270 270
         }
271 271
     } else {
272 272
         return 0;
273 273
     }
274 274
 }
275 275
 
276
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
277
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
276
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
277
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
278 278
 
279
-    if ( !$invoice_ID ) {
280
-        if ( $wp_error ) {
281
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
279
+    if (!$invoice_ID) {
280
+        if ($wp_error) {
281
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
282 282
         }
283 283
         return 0;
284 284
     }
285 285
 
286
-    $invoice = wpinv_get_invoice( $invoice_ID );
286
+    $invoice = wpinv_get_invoice($invoice_ID);
287 287
 
288
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
288
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
289 289
 
290
-    if ( empty( $invoice->ID ) ) {
291
-        if ( $wp_error ) {
292
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
290
+    if (empty($invoice->ID)) {
291
+        if ($wp_error) {
292
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
293 293
         }
294 294
         return 0;
295 295
     }
296 296
 
297
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
298
-        if ( $wp_error ) {
299
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
297
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
298
+        if ($wp_error) {
299
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
300 300
         }
301 301
         return 0;
302 302
     }
303 303
 
304 304
     // Invoice status
305
-    if ( !empty( $invoice_data['status'] ) ) {
306
-        $invoice->set( 'status', $invoice_data['status'] );
305
+    if (!empty($invoice_data['status'])) {
306
+        $invoice->set('status', $invoice_data['status']);
307 307
     }
308 308
 
309 309
     // Invoice date
310
-    if ( !empty( $invoice_data['post_date'] ) ) {
311
-        $invoice->set( 'date', $invoice_data['post_date'] );
310
+    if (!empty($invoice_data['post_date'])) {
311
+        $invoice->set('date', $invoice_data['post_date']);
312 312
     }
313 313
 
314 314
     // Invoice due date
315
-    if ( isset( $invoice_data['due_date'] ) ) {
316
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
315
+    if (isset($invoice_data['due_date'])) {
316
+        $invoice->set('due_date', $invoice_data['due_date']);
317 317
     }
318 318
 
319 319
     // Invoice IP address
320
-    if ( !empty( $invoice_data['ip'] ) ) {
321
-        $invoice->set( 'ip', $invoice_data['ip'] );
320
+    if (!empty($invoice_data['ip'])) {
321
+        $invoice->set('ip', $invoice_data['ip']);
322 322
     }
323 323
     
324 324
     // User info
325
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
326
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
325
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
326
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
327 327
 
328
-        if ( $discounts = $invoice->get_discounts() ) {
328
+        if ($discounts = $invoice->get_discounts()) {
329 329
             $set_discount = $discounts;
330 330
         } else {
331 331
             $set_discount = '';
332 332
         }
333 333
 
334 334
         // Manage discount
335
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
335
+        if (!empty($invoice_data['user_info']['discount'])) {
336 336
             // Remove discount
337
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
337
+            if ($invoice_data['user_info']['discount'] == 'none') {
338 338
                 $set_discount = '';
339 339
             } else {
340 340
                 $set_discount = $invoice_data['user_info']['discount'];
341 341
             }
342 342
 
343
-            $invoice->set( 'discounts', $set_discount );
343
+            $invoice->set('discounts', $set_discount);
344 344
         }
345 345
 
346 346
         $user_info['discount'] = $set_discount;
347 347
 
348
-        $invoice->set( 'user_info', $user_info );
348
+        $invoice->set('user_info', $user_info);
349 349
     }
350 350
 
351
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
352
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
351
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
352
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
353 353
 
354
-        if ( !empty( $remove_items[0]['id'] ) ) {
355
-            foreach ( $remove_items as $item ) {
356
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
357
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
358
-                if ( empty( $item_id ) ) {
354
+        if (!empty($remove_items[0]['id'])) {
355
+            foreach ($remove_items as $item) {
356
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
357
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
358
+                if (empty($item_id)) {
359 359
                     continue;
360 360
                 }
361 361
 
362
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
363
-                    if ( $item_id == $cart_item['id'] ) {
362
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
363
+                    if ($item_id == $cart_item['id']) {
364 364
                         $args = array(
365 365
                             'id'         => $item_id,
366 366
                             'quantity'   => $quantity,
367 367
                             'cart_index' => $cart_index
368 368
                         );
369 369
 
370
-                        $invoice->remove_item( $item_id, $args );
370
+                        $invoice->remove_item($item_id, $args);
371 371
                         break;
372 372
                     }
373 373
                 }
374 374
             }
375 375
         }
376 376
 
377
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
377
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
378 378
 
379
-        if ( !empty( $add_items[0]['id'] ) ) {
380
-            foreach ( $add_items as $item ) {
381
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
382
-                $post_item      = new WPInv_Item( $item_id );
383
-                if ( empty( $post_item ) ) {
379
+        if (!empty($add_items[0]['id'])) {
380
+            foreach ($add_items as $item) {
381
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
382
+                $post_item      = new WPInv_Item($item_id);
383
+                if (empty($post_item)) {
384 384
                     continue;
385 385
                 }
386 386
 
387 387
                 $valid_item = true;
388
-                if ( !empty( $recurring_item ) ) {
389
-                    if ( $recurring_item->ID != $item_id ) {
388
+                if (!empty($recurring_item)) {
389
+                    if ($recurring_item->ID != $item_id) {
390 390
                         $valid_item = false;
391 391
                     }
392
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
392
+                } else if (wpinv_is_recurring_item($item_id)) {
393 393
                     $valid_item = false;
394 394
                 }
395 395
                 
396
-                if ( !$valid_item ) {
397
-                    if ( $wp_error ) {
398
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
396
+                if (!$valid_item) {
397
+                    if ($wp_error) {
398
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
399 399
                     }
400 400
                     return 0;
401 401
                 }
402 402
 
403
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
404
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
405
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
403
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
404
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
405
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
406 406
 
407 407
                 $args = array(
408 408
                     'name'          => $name,
409 409
                     'quantity'      => $quantity,
410 410
                     'item_price'    => $item_price,
411
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
412
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
413
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
414
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
415
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
411
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
412
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
413
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
414
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
415
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
416 416
                 );
417 417
 
418
-                $invoice->add_item( $item_id, $args );
418
+                $invoice->add_item($item_id, $args);
419 419
             }
420 420
         }
421 421
     }
422 422
     
423 423
     // Payment details
424
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
425
-        if ( !empty( $payment_details['gateway'] ) ) {
426
-            $invoice->set( 'gateway', $payment_details['gateway'] );
424
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
425
+        if (!empty($payment_details['gateway'])) {
426
+            $invoice->set('gateway', $payment_details['gateway']);
427 427
         }
428 428
 
429
-        if ( !empty( $payment_details['transaction_id'] ) ) {
430
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
429
+        if (!empty($payment_details['transaction_id'])) {
430
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
431 431
         }
432 432
     }
433 433
 
434
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
434
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
435 435
 
436 436
     // Parent invoice
437
-    if ( !empty( $invoice_data['parent'] ) ) {
438
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
437
+    if (!empty($invoice_data['parent'])) {
438
+        $invoice->set('parent_invoice', $invoice_data['parent']);
439 439
     }
440 440
 
441 441
     // Save invoice data.
442 442
     $invoice->save();
443 443
     
444
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
445
-        if ( $wp_error ) {
446
-            if ( is_wp_error( $invoice ) ) {
444
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
445
+        if ($wp_error) {
446
+            if (is_wp_error($invoice)) {
447 447
                 return $invoice;
448 448
             } else {
449
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
449
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
450 450
             }
451 451
         } else {
452 452
             return 0;
@@ -454,19 +454,19 @@  discard block
 block discarded – undo
454 454
     }
455 455
 
456 456
     // Add private note
457
-    if ( !empty( $invoice_data['private_note'] ) ) {
458
-        $invoice->add_note( $invoice_data['private_note'] );
457
+    if (!empty($invoice_data['private_note'])) {
458
+        $invoice->add_note($invoice_data['private_note']);
459 459
     }
460 460
 
461 461
     // Add user note
462
-    if ( !empty( $invoice_data['user_note'] ) ) {
463
-        $invoice->add_note( $invoice_data['user_note'], true );
462
+    if (!empty($invoice_data['user_note'])) {
463
+        $invoice->add_note($invoice_data['user_note'], true);
464 464
     }
465 465
 
466
-    if ( $invoice->is_quote() ) {
466
+    if ($invoice->is_quote()) {
467 467
 
468
-        if ( isset( $invoice_data['valid_until'] ) ) {
469
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
468
+        if (isset($invoice_data['valid_until'])) {
469
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
470 470
         }
471 471
         return $invoice;
472 472
 
@@ -478,466 +478,466 @@  discard block
 block discarded – undo
478 478
 
479 479
     $data_session                   = array();
480 480
     $data_session['invoice_id']     = $invoice->ID;
481
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
481
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
482 482
 
483
-    wpinv_set_checkout_session( $data_session );
483
+    wpinv_set_checkout_session($data_session);
484 484
 
485
-    $wpi_userID         = (int)$invoice->get_user_id();
485
+    $wpi_userID         = (int) $invoice->get_user_id();
486 486
 
487
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
487
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
488 488
     $_POST['state']     = $invoice->state;
489 489
 
490
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
491
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
490
+    $invoice->set('country', sanitize_text_field($_POST['country']));
491
+    $invoice->set('state', sanitize_text_field($_POST['state']));
492 492
 
493 493
     $wpinv_ip_address_country = $invoice->country;
494 494
 
495
-    $invoice = $invoice->recalculate_totals( true );
495
+    $invoice = $invoice->recalculate_totals(true);
496 496
 
497
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
497
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
498 498
 
499
-    wpinv_set_checkout_session( $checkout_session );
499
+    wpinv_set_checkout_session($checkout_session);
500 500
 
501 501
     return $invoice;
502 502
 }
503 503
 
504
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
505
-    if ( $cart && empty( $invoice_id ) ) {
506
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
504
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
505
+    if ($cart && empty($invoice_id)) {
506
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
507 507
     }
508 508
 
509
-    $invoice = new WPInv_Invoice( $invoice_id );
509
+    $invoice = new WPInv_Invoice($invoice_id);
510 510
 
511
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
511
+    if (!empty($invoice) && !empty($invoice->ID)) {
512 512
         return $invoice;
513 513
     }
514 514
     
515 515
     return NULL;
516 516
 }
517 517
 
518
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
519
-    return wpinv_get_invoice( $invoice_id, true );
518
+function wpinv_get_invoice_cart($invoice_id = 0) {
519
+    return wpinv_get_invoice($invoice_id, true);
520 520
 }
521 521
 
522
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
523
-    $invoice = new WPInv_Invoice( $invoice_id );
522
+function wpinv_get_invoice_description($invoice_id = 0) {
523
+    $invoice = new WPInv_Invoice($invoice_id);
524 524
     return $invoice->get_description();
525 525
 }
526 526
 
527
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
528
-    $invoice = new WPInv_Invoice( $invoice_id );
527
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
528
+    $invoice = new WPInv_Invoice($invoice_id);
529 529
     return $invoice->get_currency();
530 530
 }
531 531
 
532
-function wpinv_get_payment_user_email( $invoice_id ) {
533
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+function wpinv_get_payment_user_email($invoice_id) {
533
+    $invoice = new WPInv_Invoice($invoice_id);
534 534
     return $invoice->get_email();
535 535
 }
536 536
 
537
-function wpinv_get_user_id( $invoice_id ) {
538
-    $invoice = new WPInv_Invoice( $invoice_id );
537
+function wpinv_get_user_id($invoice_id) {
538
+    $invoice = new WPInv_Invoice($invoice_id);
539 539
     return $invoice->get_user_id();
540 540
 }
541 541
 
542
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
543
-    $invoice = new WPInv_Invoice( $invoice_id );
542
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
543
+    $invoice = new WPInv_Invoice($invoice_id);
544 544
     
545
-    return $invoice->get_status( $return_label );
545
+    return $invoice->get_status($return_label);
546 546
 }
547 547
 
548
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
549
-    $invoice = new WPInv_Invoice( $invoice_id );
548
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
549
+    $invoice = new WPInv_Invoice($invoice_id);
550 550
     
551
-    return $invoice->get_gateway( $return_label );
551
+    return $invoice->get_gateway($return_label);
552 552
 }
553 553
 
554
-function wpinv_get_payment_gateway_name( $invoice_id ) {
555
-    $invoice = new WPInv_Invoice( $invoice_id );
554
+function wpinv_get_payment_gateway_name($invoice_id) {
555
+    $invoice = new WPInv_Invoice($invoice_id);
556 556
     
557 557
     return $invoice->get_gateway_title();
558 558
 }
559 559
 
560
-function wpinv_get_payment_transaction_id( $invoice_id ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_get_payment_transaction_id($invoice_id) {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     
563 563
     return $invoice->get_transaction_id();
564 564
 }
565 565
 
566
-function wpinv_get_id_by_transaction_id( $key ) {
566
+function wpinv_get_id_by_transaction_id($key) {
567 567
     global $wpdb;
568 568
 
569
-    $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 ) );
569
+    $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));
570 570
 
571
-    if ( $invoice_id != NULL )
571
+    if ($invoice_id != NULL)
572 572
         return $invoice_id;
573 573
 
574 574
     return 0;
575 575
 }
576 576
 
577
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
578
-    $invoice = new WPInv_Invoice( $invoice_id );
577
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
578
+    $invoice = new WPInv_Invoice($invoice_id);
579 579
 
580
-    return $invoice->get_meta( $meta_key, $single );
580
+    return $invoice->get_meta($meta_key, $single);
581 581
 }
582 582
 
583
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
584
-    $invoice = new WPInv_Invoice( $invoice_id );
583
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
584
+    $invoice = new WPInv_Invoice($invoice_id);
585 585
     
586
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
586
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
587 587
 }
588 588
 
589
-function wpinv_get_items( $invoice_id = 0 ) {
590
-    $invoice            = wpinv_get_invoice( $invoice_id );
589
+function wpinv_get_items($invoice_id = 0) {
590
+    $invoice            = wpinv_get_invoice($invoice_id);
591 591
     
592 592
     $items              = $invoice->get_items();
593 593
     $invoice_currency   = $invoice->get_currency();
594 594
 
595
-    if ( !empty( $items ) && is_array( $items ) ) {
596
-        foreach ( $items as $key => $item ) {
595
+    if (!empty($items) && is_array($items)) {
596
+        foreach ($items as $key => $item) {
597 597
             $items[$key]['currency'] = $invoice_currency;
598 598
 
599
-            if ( !isset( $item['subtotal'] ) ) {
599
+            if (!isset($item['subtotal'])) {
600 600
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
601 601
             }
602 602
         }
603 603
     }
604 604
 
605
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
605
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
606 606
 }
607 607
 
608
-function wpinv_get_fees( $invoice_id = 0 ) {
609
-    $invoice           = wpinv_get_invoice( $invoice_id );
608
+function wpinv_get_fees($invoice_id = 0) {
609
+    $invoice           = wpinv_get_invoice($invoice_id);
610 610
     $fees              = $invoice->get_fees();
611 611
 
612
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
612
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
613 613
 }
614 614
 
615
-function wpinv_get_invoice_ip( $invoice_id ) {
616
-    $invoice = new WPInv_Invoice( $invoice_id );
615
+function wpinv_get_invoice_ip($invoice_id) {
616
+    $invoice = new WPInv_Invoice($invoice_id);
617 617
     return $invoice->get_ip();
618 618
 }
619 619
 
620
-function wpinv_get_invoice_user_info( $invoice_id ) {
621
-    $invoice = new WPInv_Invoice( $invoice_id );
620
+function wpinv_get_invoice_user_info($invoice_id) {
621
+    $invoice = new WPInv_Invoice($invoice_id);
622 622
     return $invoice->get_user_info();
623 623
 }
624 624
 
625
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
626
-    $invoice = new WPInv_Invoice( $invoice_id );
625
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
626
+    $invoice = new WPInv_Invoice($invoice_id);
627 627
 
628
-    return $invoice->get_subtotal( $currency );
628
+    return $invoice->get_subtotal($currency);
629 629
 }
630 630
 
631
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
632
-    $invoice = new WPInv_Invoice( $invoice_id );
631
+function wpinv_tax($invoice_id = 0, $currency = false) {
632
+    $invoice = new WPInv_Invoice($invoice_id);
633 633
 
634
-    return $invoice->get_tax( $currency );
634
+    return $invoice->get_tax($currency);
635 635
 }
636 636
 
637
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
638
-    $invoice = wpinv_get_invoice( $invoice_id );
637
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
638
+    $invoice = wpinv_get_invoice($invoice_id);
639 639
 
640
-    return $invoice->get_discount( $currency, $dash );
640
+    return $invoice->get_discount($currency, $dash);
641 641
 }
642 642
 
643
-function wpinv_discount_code( $invoice_id = 0 ) {
644
-    $invoice = new WPInv_Invoice( $invoice_id );
643
+function wpinv_discount_code($invoice_id = 0) {
644
+    $invoice = new WPInv_Invoice($invoice_id);
645 645
 
646 646
     return $invoice->get_discount_code();
647 647
 }
648 648
 
649
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
650
-    $invoice = new WPInv_Invoice( $invoice_id );
649
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
650
+    $invoice = new WPInv_Invoice($invoice_id);
651 651
 
652
-    return $invoice->get_total( $currency );
652
+    return $invoice->get_total($currency);
653 653
 }
654 654
 
655
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
656
-    $invoice = new WPInv_Invoice( $invoice_id );
655
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
656
+    $invoice = new WPInv_Invoice($invoice_id);
657 657
 
658
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
658
+    $format         = !empty($format) ? $format : get_option('date_format');
659 659
     $date_created   = $invoice->get_created_date();
660
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
660
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
661 661
 
662 662
     return $date_created;
663 663
 }
664 664
 
665
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
666
-    $invoice = new WPInv_Invoice( $invoice_id );
665
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
666
+    $invoice = new WPInv_Invoice($invoice_id);
667 667
     
668
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
668
+    $format         = !empty($format) ? $format : get_option('date_format');
669 669
     $date_completed = $invoice->get_completed_date();
670
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
671
-    if ( $invoice_date == '' && $default ) {
672
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
670
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
671
+    if ($invoice_date == '' && $default) {
672
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
673 673
     }
674 674
 
675 675
     return $invoice_date;
676 676
 }
677 677
 
678
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
679
-    $invoice = new WPInv_Invoice( $invoice_id );
678
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
679
+    $invoice = new WPInv_Invoice($invoice_id);
680 680
     
681 681
     return $invoice->vat_number;
682 682
 }
683 683
 
684
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
685
-    $invoice = new WPInv_Invoice( $invoice_id );
684
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
685
+    $invoice = new WPInv_Invoice($invoice_id);
686 686
 
687
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
687
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
688 688
 }
689 689
 
690
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
690
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
691 691
     global $invoicing;
692 692
     
693
-    if ( empty( $invoice_id ) ) {
693
+    if (empty($invoice_id)) {
694 694
         return NULL;
695 695
     }
696 696
     
697
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
697
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
698 698
     
699
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
699
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
700 700
 }
701 701
 
702
-function wpinv_get_payment_key( $invoice_id = 0 ) {
703
-	$invoice = new WPInv_Invoice( $invoice_id );
702
+function wpinv_get_payment_key($invoice_id = 0) {
703
+	$invoice = new WPInv_Invoice($invoice_id);
704 704
     return $invoice->get_key();
705 705
 }
706 706
 
707
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
708
-    $invoice = new WPInv_Invoice( $invoice_id );
707
+function wpinv_get_invoice_number($invoice_id = 0) {
708
+    $invoice = new WPInv_Invoice($invoice_id);
709 709
     return $invoice->get_number();
710 710
 }
711 711
 
712
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
712
+function wpinv_get_cart_discountable_subtotal($code_id) {
713 713
     $cart_items = wpinv_get_cart_content_details();
714 714
     $items      = array();
715 715
 
716
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
716
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
717 717
 
718
-    if( $cart_items ) {
718
+    if ($cart_items) {
719 719
 
720
-        foreach( $cart_items as $item ) {
720
+        foreach ($cart_items as $item) {
721 721
 
722
-            if( ! in_array( $item['id'], $excluded_items ) ) {
723
-                $items[] =  $item;
722
+            if (!in_array($item['id'], $excluded_items)) {
723
+                $items[] = $item;
724 724
             }
725 725
         }
726 726
     }
727 727
 
728
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
728
+    $subtotal = wpinv_get_cart_items_subtotal($items);
729 729
 
730
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
730
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
731 731
 }
732 732
 
733
-function wpinv_get_cart_items_subtotal( $items ) {
733
+function wpinv_get_cart_items_subtotal($items) {
734 734
     $subtotal = 0.00;
735 735
 
736
-    if ( is_array( $items ) && ! empty( $items ) ) {
737
-        $prices = wp_list_pluck( $items, 'subtotal' );
736
+    if (is_array($items) && !empty($items)) {
737
+        $prices = wp_list_pluck($items, 'subtotal');
738 738
 
739
-        if( is_array( $prices ) ) {
740
-            $subtotal = array_sum( $prices );
739
+        if (is_array($prices)) {
740
+            $subtotal = array_sum($prices);
741 741
         } else {
742 742
             $subtotal = 0.00;
743 743
         }
744 744
 
745
-        if( $subtotal < 0 ) {
745
+        if ($subtotal < 0) {
746 746
             $subtotal = 0.00;
747 747
         }
748 748
     }
749 749
 
750
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
750
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
751 751
 }
752 752
 
753
-function wpinv_get_cart_subtotal( $items = array() ) {
754
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
755
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
753
+function wpinv_get_cart_subtotal($items = array()) {
754
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
755
+    $subtotal = wpinv_get_cart_items_subtotal($items);
756 756
 
757
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
757
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
758 758
 }
759 759
 
760
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
760
+function wpinv_cart_subtotal($items = array(), $currency = '') {
761 761
 
762
-    if( empty( $currency ) ) {
762
+    if (empty($currency)) {
763 763
         $currency = wpinv_get_currency();
764 764
     }
765 765
 
766
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
766
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
767 767
 
768 768
     return $price;
769 769
 }
770 770
 
771
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
772
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
773
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
774
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
775
-    $fees      = (float)wpinv_get_cart_fee_total();
776
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
771
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
772
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
773
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
774
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
775
+    $fees      = (float) wpinv_get_cart_fee_total();
776
+    if (!empty($invoice) && $invoice->is_free_trial()) {
777 777
         $total = 0;
778 778
     } else {
779
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
779
+        $total = $subtotal - $discounts + $cart_tax + $fees;
780 780
     }
781 781
 
782
-    if ( $total < 0 ) {
782
+    if ($total < 0) {
783 783
         $total = 0.00;
784 784
     }
785 785
     
786
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
786
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
787 787
 
788
-    return wpinv_sanitize_amount( $total );
788
+    return wpinv_sanitize_amount($total);
789 789
 }
790 790
 
791
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
791
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
792 792
     global $cart_total;
793
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
794
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
793
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
794
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
795 795
     
796 796
     $cart_total = $total;
797 797
 
798
-    if ( !$echo ) {
798
+    if (!$echo) {
799 799
         return $total;
800 800
     }
801 801
 
802 802
     echo $total;
803 803
 }
804 804
 
805
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
805
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
806 806
 
807
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
807
+    if (!empty($invoice) && !$invoice->is_taxable()) {
808 808
         return 0;
809 809
     }
810 810
 
811 811
     $cart_tax = 0;
812
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
812
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
813 813
 
814
-    if ( $items ) {
815
-        $taxes = wp_list_pluck( $items, 'tax' );
814
+    if ($items) {
815
+        $taxes = wp_list_pluck($items, 'tax');
816 816
 
817
-        if( is_array( $taxes ) ) {
818
-            $cart_tax = array_sum( $taxes );
817
+        if (is_array($taxes)) {
818
+            $cart_tax = array_sum($taxes);
819 819
         }
820 820
     }
821 821
 
822 822
     $cart_tax += wpinv_get_cart_fee_tax();
823 823
 
824
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
824
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
825 825
 }
826 826
 
827
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
827
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
828 828
 
829
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
830
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
829
+    if (!empty($invoice && !$invoice->is_taxable())) {
830
+        echo wpinv_price(wpinv_format_amount(0), $currency);
831 831
         return;
832 832
     }
833 833
 
834
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
835
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
834
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
835
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
836 836
 
837
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
837
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
838 838
 
839
-    if ( !$echo ) {
839
+    if (!$echo) {
840 840
         return $tax;
841 841
     }
842 842
 
843 843
     echo $tax;
844 844
 }
845 845
 
846
-function wpinv_get_cart_discount_code( $items = array() ) {
846
+function wpinv_get_cart_discount_code($items = array()) {
847 847
     $invoice = wpinv_get_invoice_cart();
848
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
848
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
849 849
     
850
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
850
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
851 851
 }
852 852
 
853
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
854
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
853
+function wpinv_cart_discount_code($items = array(), $echo = false) {
854
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
855 855
 
856
-    if ( $cart_discount_code != '' ) {
856
+    if ($cart_discount_code != '') {
857 857
         $cart_discount_code = ' (' . $cart_discount_code . ')';
858 858
     }
859 859
     
860
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
860
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
861 861
 
862
-    if ( !$echo ) {
862
+    if (!$echo) {
863 863
         return $discount_code;
864 864
     }
865 865
 
866 866
     echo $discount_code;
867 867
 }
868 868
 
869
-function wpinv_get_cart_discount( $items = array() ) {
869
+function wpinv_get_cart_discount($items = array()) {
870 870
     $invoice = wpinv_get_invoice_cart();
871
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
871
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
872 872
     
873
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
873
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
874 874
 }
875 875
 
876
-function wpinv_cart_discount( $items = array(), $echo = false ) {
877
-    $cart_discount = wpinv_get_cart_discount( $items );
878
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
876
+function wpinv_cart_discount($items = array(), $echo = false) {
877
+    $cart_discount = wpinv_get_cart_discount($items);
878
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
879 879
 
880
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
880
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
881 881
 
882
-    if ( !$echo ) {
882
+    if (!$echo) {
883 883
         return $discount;
884 884
     }
885 885
 
886 886
     echo $discount;
887 887
 }
888 888
 
889
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
890
-    $item = new WPInv_Item( $item_id );
889
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
890
+    $item = new WPInv_Item($item_id);
891 891
     
892
-    return $item->get_fees( $type, $item_id );
892
+    return $item->get_fees($type, $item_id);
893 893
 }
894 894
 
895 895
 function wpinv_get_cart_fee_total() {
896
-    $total  = 0;
896
+    $total = 0;
897 897
     $fees = wpinv_get_cart_fees();
898 898
     
899
-    if ( $fees ) {
900
-        foreach ( $fees as $fee_id => $fee ) {
899
+    if ($fees) {
900
+        foreach ($fees as $fee_id => $fee) {
901 901
             $total += $fee['amount'];
902 902
         }
903 903
     }
904 904
 
905
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
905
+    return apply_filters('wpinv_get_cart_fee_total', $total);
906 906
 }
907 907
 
908 908
 function wpinv_get_cart_fee_tax() {
909 909
     $tax  = 0;
910 910
     $fees = wpinv_get_cart_fees();
911 911
 
912
-    if ( $fees ) {
913
-        foreach ( $fees as $fee_id => $fee ) {
914
-            if( ! empty( $fee['no_tax'] ) ) {
912
+    if ($fees) {
913
+        foreach ($fees as $fee_id => $fee) {
914
+            if (!empty($fee['no_tax'])) {
915 915
                 continue;
916 916
             }
917 917
 
918
-            $tax += wpinv_calculate_tax( $fee['amount'] );
918
+            $tax += wpinv_calculate_tax($fee['amount']);
919 919
         }
920 920
     }
921 921
 
922
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
922
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
923 923
 }
924 924
 
925 925
 function wpinv_cart_has_recurring_item() {
926 926
     $cart_items = wpinv_get_cart_contents();
927 927
     
928
-    if ( empty( $cart_items ) ) {
928
+    if (empty($cart_items)) {
929 929
         return false;
930 930
     }
931 931
     
932 932
     $has_subscription = false;
933
-    foreach( $cart_items as $cart_item ) {
934
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
933
+    foreach ($cart_items as $cart_item) {
934
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
935 935
             $has_subscription = true;
936 936
             break;
937 937
         }
938 938
     }
939 939
     
940
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
940
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
941 941
 }
942 942
 
943 943
 function wpinv_cart_has_free_trial() {
@@ -945,100 +945,100 @@  discard block
 block discarded – undo
945 945
     
946 946
     $free_trial = false;
947 947
     
948
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
948
+    if (!empty($invoice) && $invoice->is_free_trial()) {
949 949
         $free_trial = true;
950 950
     }
951 951
     
952
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
952
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
953 953
 }
954 954
 
955 955
 function wpinv_get_cart_contents() {
956 956
     $cart_details = wpinv_get_cart_details();
957 957
     
958
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
958
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
959 959
 }
960 960
 
961 961
 function wpinv_get_cart_content_details() {
962 962
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
963 963
     $cart_items = wpinv_get_cart_contents();
964 964
     
965
-    if ( empty( $cart_items ) ) {
965
+    if (empty($cart_items)) {
966 966
         return false;
967 967
     }
968 968
     $invoice = wpinv_get_invoice_cart();
969
-	if ( empty( $invoice ) ) {
969
+	if (empty($invoice)) {
970 970
         return false;
971 971
     }
972 972
 
973 973
     $details = array();
974
-    $length  = count( $cart_items ) - 1;
974
+    $length  = count($cart_items) - 1;
975 975
     
976
-    if ( empty( $_POST['country'] ) ) {
976
+    if (empty($_POST['country'])) {
977 977
         $_POST['country'] = $invoice->country;
978 978
     }
979
-    if ( !isset( $_POST['state'] ) ) {
979
+    if (!isset($_POST['state'])) {
980 980
         $_POST['state'] = $invoice->state;
981 981
     }
982 982
 
983
-    foreach( $cart_items as $key => $item ) {
984
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
985
-        if ( empty( $item_id ) ) {
983
+    foreach ($cart_items as $key => $item) {
984
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
985
+        if (empty($item_id)) {
986 986
             continue;
987 987
         }
988 988
         
989 989
         $wpi_current_id         = $invoice->ID;
990 990
         $wpi_item_id            = $item_id;
991 991
         
992
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
992
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
993 993
             $item_price = $item['custom_price'];
994 994
         } else {
995
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
995
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
996 996
                 $item_price = $item['item_price'];
997 997
             } else {
998
-                $item_price = wpinv_get_item_price( $item_id );
998
+                $item_price = wpinv_get_item_price($item_id);
999 999
             }
1000 1000
         }
1001
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1002
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1003
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1004
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1001
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1002
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1003
+        $quantity           = wpinv_get_cart_item_quantity($item);
1004
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1005 1005
         
1006 1006
         $subtotal           = $item_price * $quantity;
1007
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1008
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1009
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1007
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1008
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1009
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1010 1010
         
1011
-        if ( ! $invoice->is_taxable() ) {
1011
+        if (!$invoice->is_taxable()) {
1012 1012
             $tax = 0;
1013 1013
         }
1014
-        if ( wpinv_prices_include_tax() ) {
1015
-            $subtotal -= wpinv_round_amount( $tax );
1014
+        if (wpinv_prices_include_tax()) {
1015
+            $subtotal -= wpinv_round_amount($tax);
1016 1016
         }
1017 1017
         
1018
-        $total              = $subtotal - $discount + $tax;
1018
+        $total = $subtotal - $discount + $tax;
1019 1019
         
1020 1020
         // Do not allow totals to go negatve
1021
-        if( $total < 0 ) {
1021
+        if ($total < 0) {
1022 1022
             $total = 0;
1023 1023
         }
1024 1024
         
1025
-        $details[ $key ]  = array(
1025
+        $details[$key] = array(
1026 1026
             'id'                => $item_id,
1027
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1028
-            'item_price'        => wpinv_round_amount( $item_price ),
1029
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1027
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1028
+            'item_price'        => wpinv_round_amount($item_price),
1029
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1030 1030
             'quantity'          => $quantity,
1031
-            'discount'          => wpinv_round_amount( $discount ),
1032
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1033
-            'tax'               => wpinv_round_amount( $tax ),
1034
-            'price'             => wpinv_round_amount( $total ),
1031
+            'discount'          => wpinv_round_amount($discount),
1032
+            'subtotal'          => wpinv_round_amount($subtotal),
1033
+            'tax'               => wpinv_round_amount($tax),
1034
+            'price'             => wpinv_round_amount($total),
1035 1035
             'vat_rates_class'   => $tax_class,
1036 1036
             'vat_rate'          => $tax_rate,
1037
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1037
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1038 1038
             'fees'              => $fees,
1039 1039
         );
1040 1040
         
1041
-        if ( $wpinv_is_last_cart_item ) {
1041
+        if ($wpinv_is_last_cart_item) {
1042 1042
             $wpinv_is_last_cart_item   = false;
1043 1043
             $wpinv_flat_discount_total = 0.00;
1044 1044
         }
@@ -1047,67 +1047,67 @@  discard block
 block discarded – undo
1047 1047
     return $details;
1048 1048
 }
1049 1049
 
1050
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1050
+function wpinv_get_cart_details($invoice_id = 0) {
1051 1051
     global $ajax_cart_details;
1052 1052
 
1053
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1053
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1054 1054
     $cart_details = $ajax_cart_details;
1055
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1055
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1056 1056
         $cart_details = $invoice->cart_details;
1057 1057
     }
1058 1058
 
1059
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1060
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1059
+    if (!empty($cart_details) && is_array($cart_details)) {
1060
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1061 1061
 
1062
-        foreach ( $cart_details as $key => $cart_item ) {
1063
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1062
+        foreach ($cart_details as $key => $cart_item) {
1063
+            $cart_details[$key]['currency'] = $invoice_currency;
1064 1064
 
1065
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1066
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1065
+            if (!isset($cart_item['subtotal'])) {
1066
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1067 1067
             }
1068 1068
         }
1069 1069
     }
1070 1070
 
1071
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1071
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1072 1072
 }
1073 1073
 
1074
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1075
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1074
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1075
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1076 1076
         return;
1077 1077
     }
1078 1078
 
1079
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1079
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1080 1080
         return;
1081 1081
     }
1082 1082
 
1083
-    $invoice    = wpinv_get_invoice( $invoice_id );
1083
+    $invoice    = wpinv_get_invoice($invoice_id);
1084 1084
     
1085
-    $old_status = wpinv_status_nicename( $old_status );
1086
-    $new_status = wpinv_status_nicename( $new_status );
1085
+    $old_status = wpinv_status_nicename($old_status);
1086
+    $new_status = wpinv_status_nicename($new_status);
1087 1087
 
1088
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1088
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1089 1089
     
1090 1090
     // Add note
1091
-    return $invoice->add_note( $status_change, false, false, true );
1091
+    return $invoice->add_note($status_change, false, false, true);
1092 1092
 }
1093
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1093
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1094 1094
 
1095
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1095
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1096 1096
     global $wpi_has_free_trial;
1097 1097
     
1098 1098
     $wpi_has_free_trial = false;
1099 1099
     
1100
-    if ( $old_status == 'publish' ) {
1100
+    if ($old_status == 'publish') {
1101 1101
         return; // Make sure that payments are only paid once
1102 1102
     }
1103 1103
 
1104 1104
     // Make sure the payment completion is only processed when new status is paid
1105
-    if ( $new_status != 'publish' ) {
1105
+    if ($new_status != 'publish') {
1106 1106
         return;
1107 1107
     }
1108 1108
 
1109
-    $invoice = new WPInv_Invoice( $invoice_id );
1110
-    if ( empty( $invoice ) ) {
1109
+    $invoice = new WPInv_Invoice($invoice_id);
1110
+    if (empty($invoice)) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
@@ -1115,58 +1115,58 @@  discard block
 block discarded – undo
1115 1115
     $completed_date = $invoice->completed_date;
1116 1116
     $cart_details   = $invoice->cart_details;
1117 1117
 
1118
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1118
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1119 1119
 
1120
-    if ( is_array( $cart_details ) ) {
1120
+    if (is_array($cart_details)) {
1121 1121
         // Increase purchase count and earnings
1122
-        foreach ( $cart_details as $cart_index => $item ) {
1122
+        foreach ($cart_details as $cart_index => $item) {
1123 1123
             // Ensure these actions only run once, ever
1124
-            if ( empty( $completed_date ) ) {
1125
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1124
+            if (empty($completed_date)) {
1125
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1126 1126
             }
1127 1127
         }
1128 1128
     }
1129 1129
     
1130 1130
     // Check for discount codes and increment their use counts
1131
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1132
-        if( ! empty( $discounts ) ) {
1133
-            foreach( $discounts as $code ) {
1134
-                wpinv_increase_discount_usage( $code );
1131
+    if ($discounts = $invoice->get_discounts(true)) {
1132
+        if (!empty($discounts)) {
1133
+            foreach ($discounts as $code) {
1134
+                wpinv_increase_discount_usage($code);
1135 1135
             }
1136 1136
         }
1137 1137
     }
1138 1138
     
1139 1139
     // Ensure this action only runs once ever
1140
-    if( empty( $completed_date ) ) {
1140
+    if (empty($completed_date)) {
1141 1141
         // Save the completed date
1142
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1142
+        $invoice->set('completed_date', current_time('mysql', 0));
1143 1143
         $invoice->save();
1144 1144
 
1145
-        do_action( 'wpinv_complete_payment', $invoice_id );
1145
+        do_action('wpinv_complete_payment', $invoice_id);
1146 1146
     }
1147 1147
 
1148 1148
     // Empty the shopping cart
1149 1149
     wpinv_empty_cart();
1150 1150
 }
1151
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1151
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1152 1152
 
1153
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1154
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1153
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1154
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1155 1155
     
1156
-    if ( empty( $invoice ) ) {
1156
+    if (empty($invoice)) {
1157 1157
         return false;
1158 1158
     }
1159 1159
     
1160
-    return $invoice->update_status( $new_status );
1160
+    return $invoice->update_status($new_status);
1161 1161
 }
1162 1162
 
1163
-function wpinv_cart_has_fees( $type = 'all' ) {
1163
+function wpinv_cart_has_fees($type = 'all') {
1164 1164
     return false;
1165 1165
 }
1166 1166
 
1167 1167
 function wpinv_validate_checkout_fields() {    
1168 1168
     // Check if there is $_POST
1169
-    if ( empty( $_POST ) ) {
1169
+    if (empty($_POST)) {
1170 1170
         return false;
1171 1171
     }
1172 1172
     
@@ -1178,11 +1178,11 @@  discard block
 block discarded – undo
1178 1178
     );
1179 1179
     
1180 1180
     // Validate agree to terms
1181
-    $page = wpinv_get_option( 'tandc_page' );
1182
-    if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1181
+    $page = wpinv_get_option('tandc_page');
1182
+    if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1183 1183
         // Validate agree to terms
1184
-        if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) {
1185
-            wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) );
1184
+        if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) {
1185
+            wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing')));
1186 1186
         }
1187 1187
     }
1188 1188
     
@@ -1198,28 +1198,28 @@  discard block
 block discarded – undo
1198 1198
     
1199 1199
     $invoice = wpinv_get_invoice_cart();
1200 1200
     $has_subscription = $invoice->is_recurring();
1201
-    if ( empty( $invoice ) ) {
1202
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1201
+    if (empty($invoice)) {
1202
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1203 1203
         return $gateway;
1204 1204
     }
1205 1205
 
1206 1206
     // Check if a gateway value is present
1207
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1208
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1207
+    if (!empty($_REQUEST['wpi-gateway'])) {
1208
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1209 1209
 
1210
-        if ( $invoice->is_free() ) {
1210
+        if ($invoice->is_free()) {
1211 1211
             $gateway = 'manual';
1212
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1213
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1214
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1215
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1216
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1212
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1213
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1214
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1215
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1216
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1217 1217
             }
1218 1218
         }
1219 1219
     }
1220 1220
 
1221
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1222
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1221
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1222
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1223 1223
     }
1224 1224
 
1225 1225
     return $gateway;
@@ -1233,10 +1233,10 @@  discard block
 block discarded – undo
1233 1233
     
1234 1234
     $error = false;
1235 1235
     // If we have discounts, loop through them
1236
-    if ( ! empty( $discounts ) ) {
1237
-        foreach ( $discounts as $discount ) {
1236
+    if (!empty($discounts)) {
1237
+        foreach ($discounts as $discount) {
1238 1238
             // Check if valid
1239
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1239
+            if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1240 1240
                 // Discount is not valid
1241 1241
                 $error = true;
1242 1242
             }
@@ -1246,20 +1246,20 @@  discard block
 block discarded – undo
1246 1246
         return NULL;
1247 1247
     }
1248 1248
 
1249
-    if ( $error && !wpinv_get_errors() ) {
1250
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1249
+    if ($error && !wpinv_get_errors()) {
1250
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1251 1251
     }
1252 1252
 
1253
-    return implode( ',', $discounts );
1253
+    return implode(',', $discounts);
1254 1254
 }
1255 1255
 
1256 1256
 function wpinv_checkout_validate_cc() {
1257 1257
     $card_data = wpinv_checkout_get_cc_info();
1258 1258
 
1259 1259
     // Validate the card zip
1260
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1261
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1262
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1260
+    if (!empty($card_data['wpinv_zip'])) {
1261
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1262
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1263 1263
         }
1264 1264
     }
1265 1265
 
@@ -1269,28 +1269,28 @@  discard block
 block discarded – undo
1269 1269
 
1270 1270
 function wpinv_checkout_get_cc_info() {
1271 1271
 	$cc_info = array();
1272
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1273
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1274
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1275
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1276
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1277
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1278
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1279
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1280
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1281
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1272
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1273
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1274
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1275
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1276
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1277
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1278
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1279
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1280
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1281
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1282 1282
 
1283 1283
 	// Return cc info
1284 1284
 	return $cc_info;
1285 1285
 }
1286 1286
 
1287
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1287
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1288 1288
     $ret = false;
1289 1289
 
1290
-    if ( empty( $zip ) || empty( $country_code ) )
1290
+    if (empty($zip) || empty($country_code))
1291 1291
         return $ret;
1292 1292
 
1293
-    $country_code = strtoupper( $country_code );
1293
+    $country_code = strtoupper($country_code);
1294 1294
 
1295 1295
     $zip_regex = array(
1296 1296
         "AD" => "AD\d{3}",
@@ -1450,72 +1450,72 @@  discard block
 block discarded – undo
1450 1450
         "ZM" => "\d{5}"
1451 1451
     );
1452 1452
 
1453
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1453
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1454 1454
         $ret = true;
1455 1455
 
1456
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1456
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1457 1457
 }
1458 1458
 
1459 1459
 function wpinv_checkout_validate_agree_to_terms() {
1460 1460
     // Validate agree to terms
1461
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1461
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1462 1462
         // User did not agree
1463
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1463
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1464 1464
     }
1465 1465
 }
1466 1466
 
1467 1467
 function wpinv_checkout_validate_invoice_user() {
1468 1468
     global $wpi_cart, $user_ID;
1469 1469
 
1470
-    if(empty($wpi_cart)){
1470
+    if (empty($wpi_cart)) {
1471 1471
         $wpi_cart = wpinv_get_invoice_cart();
1472 1472
     }
1473 1473
 
1474
-    $invoice_user = (int)$wpi_cart->get_user_id();
1474
+    $invoice_user = (int) $wpi_cart->get_user_id();
1475 1475
     $valid_user_data = array(
1476 1476
         'user_id' => $invoice_user
1477 1477
     );
1478 1478
 
1479 1479
     // If guest checkout allowed
1480
-    if ( !wpinv_require_login_to_checkout() ) {
1480
+    if (!wpinv_require_login_to_checkout()) {
1481 1481
         return $valid_user_data;
1482 1482
     }
1483 1483
     
1484 1484
     // Verify there is a user_ID
1485
-    if ( $user_ID == $invoice_user ) {
1485
+    if ($user_ID == $invoice_user) {
1486 1486
         // Get the logged in user data
1487
-        $user_data = get_userdata( $user_ID );
1488
-        $required_fields  = wpinv_checkout_required_fields();
1487
+        $user_data = get_userdata($user_ID);
1488
+        $required_fields = wpinv_checkout_required_fields();
1489 1489
 
1490 1490
         // Loop through required fields and show error messages
1491
-         if ( !empty( $required_fields ) ) {
1492
-            foreach ( $required_fields as $field_name => $value ) {
1493
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1494
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1491
+         if (!empty($required_fields)) {
1492
+            foreach ($required_fields as $field_name => $value) {
1493
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1494
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1495 1495
                 }
1496 1496
             }
1497 1497
         }
1498 1498
 
1499 1499
         // Verify data
1500
-        if ( $user_data ) {
1500
+        if ($user_data) {
1501 1501
             // Collected logged in user data
1502 1502
             $valid_user_data = array(
1503 1503
                 'user_id'     => $user_ID,
1504
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1505
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1506
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1504
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1505
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1506
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1507 1507
             );
1508 1508
 
1509
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1510
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1509
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1510
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1511 1511
             }
1512 1512
         } else {
1513 1513
             // Set invalid user error
1514
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1514
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1515 1515
         }
1516 1516
     } else {
1517 1517
         // Set invalid user error
1518
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1518
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1519 1519
     }
1520 1520
 
1521 1521
     // Return user data
@@ -1527,27 +1527,27 @@  discard block
 block discarded – undo
1527 1527
 
1528 1528
     $data = array();
1529 1529
     
1530
-    if ( is_user_logged_in() ) {
1531
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1532
-            $data['user_id'] = (int)get_current_user_id();
1530
+    if (is_user_logged_in()) {
1531
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1532
+            $data['user_id'] = (int) get_current_user_id();
1533 1533
         } else {
1534
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1534
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1535 1535
         }
1536 1536
     } else {
1537 1537
         // If guest checkout allowed
1538
-        if ( !wpinv_require_login_to_checkout() ) {
1538
+        if (!wpinv_require_login_to_checkout()) {
1539 1539
             $data['user_id'] = 0;
1540 1540
         } else {
1541
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1541
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1542 1542
         }
1543 1543
     }
1544 1544
 
1545 1545
     return $data;
1546 1546
 }
1547 1547
 
1548
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1548
+function wpinv_checkout_form_get_user($valid_data = array()) {
1549 1549
 
1550
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1550
+    if (!empty($valid_data['current_user']['user_id'])) {
1551 1551
         $user = $valid_data['current_user'];
1552 1552
     } else {
1553 1553
         // Set the valid invoice user
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
     }
1556 1556
 
1557 1557
     // Verify invoice have an user
1558
-    if ( false === $user || empty( $user ) ) {
1558
+    if (false === $user || empty($user)) {
1559 1559
         return false;
1560 1560
     }
1561 1561
 
@@ -1572,11 +1572,11 @@  discard block
 block discarded – undo
1572 1572
         'zip',
1573 1573
     );
1574 1574
     
1575
-    foreach ( $address_fields as $field ) {
1576
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1575
+    foreach ($address_fields as $field) {
1576
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1577 1577
         
1578
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1579
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1578
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1579
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1580 1580
         }
1581 1581
     }
1582 1582
 
@@ -1584,28 +1584,28 @@  discard block
 block discarded – undo
1584 1584
     return $user;
1585 1585
 }
1586 1586
 
1587
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1587
+function wpinv_set_checkout_session($invoice_data = array()) {
1588 1588
     global $wpi_session;
1589 1589
     
1590
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1590
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1591 1591
 }
1592 1592
 
1593 1593
 function wpinv_get_checkout_session() {
1594 1594
 	global $wpi_session;
1595 1595
     
1596
-    return $wpi_session->get( 'wpinv_checkout' );
1596
+    return $wpi_session->get('wpinv_checkout');
1597 1597
 }
1598 1598
 
1599 1599
 function wpinv_empty_cart() {
1600 1600
     global $wpi_session;
1601 1601
 
1602 1602
     // Remove cart contents
1603
-    $wpi_session->set( 'wpinv_checkout', NULL );
1603
+    $wpi_session->set('wpinv_checkout', NULL);
1604 1604
 
1605 1605
     // Remove all cart fees
1606
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1606
+    $wpi_session->set('wpi_cart_fees', NULL);
1607 1607
 
1608
-    do_action( 'wpinv_empty_cart' );
1608
+    do_action('wpinv_empty_cart');
1609 1609
 }
1610 1610
 
1611 1611
 function wpinv_process_checkout() {
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
     wpinv_clear_errors();
1615 1615
     
1616 1616
     $invoice = wpinv_get_invoice_cart();
1617
-    if ( empty( $invoice ) ) {
1617
+    if (empty($invoice)) {
1618 1618
         return false;
1619 1619
     }
1620 1620
     
@@ -1622,42 +1622,42 @@  discard block
 block discarded – undo
1622 1622
     
1623 1623
     $wpi_checkout_id = $invoice->ID;
1624 1624
     
1625
-    do_action( 'wpinv_pre_process_checkout' );
1625
+    do_action('wpinv_pre_process_checkout');
1626 1626
     
1627
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1627
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1628 1628
         $valid_data = false;
1629
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1629
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1630 1630
     } else {
1631 1631
         // Validate the form $_POST data
1632 1632
         $valid_data = wpinv_validate_checkout_fields();
1633 1633
         
1634 1634
         // Allow themes and plugins to hook to errors
1635
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1635
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1636 1636
     }
1637 1637
     
1638
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1638
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1639 1639
     
1640 1640
     // Validate the user
1641
-    $user = wpinv_checkout_form_get_user( $valid_data );
1641
+    $user = wpinv_checkout_form_get_user($valid_data);
1642 1642
 
1643 1643
     // Let extensions validate fields after user is logged in if user has used login/registration form
1644
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1644
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1645 1645
     
1646
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1647
-        if ( $is_ajax ) {
1648
-            do_action( 'wpinv_ajax_checkout_errors' );
1646
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1647
+        if ($is_ajax) {
1648
+            do_action('wpinv_ajax_checkout_errors');
1649 1649
             die();
1650 1650
         } else {
1651 1651
             return false;
1652 1652
         }
1653 1653
     }
1654 1654
 
1655
-    if ( $is_ajax ) {
1655
+    if ($is_ajax) {
1656 1656
         // Save address fields.
1657
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1658
-        foreach ( $address_fields as $field ) {
1659
-            if ( isset( $user[$field] ) ) {
1660
-                $invoice->set( $field, $user[$field] );
1657
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1658
+        foreach ($address_fields as $field) {
1659
+            if (isset($user[$field])) {
1660
+                $invoice->set($field, $user[$field]);
1661 1661
             }
1662 1662
 
1663 1663
             $invoice->save();
@@ -1665,16 +1665,16 @@  discard block
 block discarded – undo
1665 1665
 
1666 1666
         $response['success']            = true;
1667 1667
         $response['data']['subtotal']   = $invoice->get_subtotal();
1668
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1668
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1669 1669
         $response['data']['discount']   = $invoice->get_discount();
1670
-        $response['data']['discountf']  = $invoice->get_discount( true );
1670
+        $response['data']['discountf']  = $invoice->get_discount(true);
1671 1671
         $response['data']['tax']        = $invoice->get_tax();
1672
-        $response['data']['taxf']       = $invoice->get_tax( true );
1672
+        $response['data']['taxf']       = $invoice->get_tax(true);
1673 1673
         $response['data']['total']      = $invoice->get_total();
1674
-        $response['data']['totalf']     = $invoice->get_total( true );
1675
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1674
+        $response['data']['totalf']     = $invoice->get_total(true);
1675
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1676 1676
 
1677
-        wp_send_json( $response );
1677
+        wp_send_json($response);
1678 1678
     }
1679 1679
     
1680 1680
     $user_info = array(
@@ -1696,42 +1696,42 @@  discard block
 block discarded – undo
1696 1696
     
1697 1697
     // Setup invoice information
1698 1698
     $invoice_data = array(
1699
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1699
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1700 1700
         'items'             => $cart_items,
1701 1701
         'cart_discounts'    => $discounts,
1702
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1703
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1704
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1705
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1706
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1702
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1703
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1704
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1705
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1706
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1707 1707
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1708 1708
         'user_email'        => $invoice->get_email(),
1709
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1710
-        'user_info'         => stripslashes_deep( $user_info ),
1709
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1710
+        'user_info'         => stripslashes_deep($user_info),
1711 1711
         'post_data'         => $_POST,
1712 1712
         'cart_details'      => $cart_items,
1713 1713
         'gateway'           => $valid_data['gateway'],
1714 1714
         'card_info'         => $valid_data['cc_info']
1715 1715
     );
1716 1716
     
1717
-    $vat_info   = $wpinv_euvat->current_vat_data();
1718
-    if ( is_array( $vat_info ) ) {
1717
+    $vat_info = $wpinv_euvat->current_vat_data();
1718
+    if (is_array($vat_info)) {
1719 1719
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1720 1720
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1721
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1721
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1722 1722
 
1723 1723
         // Add the VAT rate to each item in the cart
1724
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1724
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1725 1725
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1726
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1726
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1727 1727
         }
1728 1728
     }
1729 1729
     
1730 1730
     // Save vat fields.
1731
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1732
-    foreach ( $address_fields as $field ) {
1733
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1734
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1731
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1732
+    foreach ($address_fields as $field) {
1733
+        if (isset($invoice_data['user_info'][$field])) {
1734
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1735 1735
         }
1736 1736
 
1737 1737
         $invoice->save();
@@ -1741,55 +1741,55 @@  discard block
 block discarded – undo
1741 1741
     $valid_data['user'] = $user;
1742 1742
     
1743 1743
     // Allow themes and plugins to hook before the gateway
1744
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1744
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1745 1745
     
1746 1746
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1747
-    if ( !$invoice_data['price'] ) {
1747
+    if (!$invoice_data['price']) {
1748 1748
         // Revert to manual
1749 1749
         $invoice_data['gateway'] = 'manual';
1750 1750
         $_POST['wpi-gateway'] = 'manual';
1751 1751
     }
1752 1752
     
1753 1753
     // Allow the invoice data to be modified before it is sent to the gateway
1754
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1754
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1755 1755
     
1756
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1756
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1757 1757
         $mode = 'test';
1758 1758
     } else {
1759
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1759
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1760 1760
     }
1761 1761
     
1762 1762
     // Setup the data we're storing in the purchase session
1763 1763
     $session_data = $invoice_data;
1764 1764
     // Make sure credit card numbers are never stored in sessions
1765
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1766
-        unset( $session_data['card_info']['card_number'] );
1765
+    if (!empty($session_data['card_info']['card_number'])) {
1766
+        unset($session_data['card_info']['card_number']);
1767 1767
     }
1768 1768
     
1769 1769
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1770
-    wpinv_set_checkout_session( $invoice_data );
1770
+    wpinv_set_checkout_session($invoice_data);
1771 1771
     
1772 1772
     // Set gateway
1773
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1774
-    $invoice->update_meta( '_wpinv_mode', $mode );
1775
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1773
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1774
+    $invoice->update_meta('_wpinv_mode', $mode);
1775
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1776 1776
     
1777
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1777
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1778 1778
 
1779 1779
     // Send info to the gateway for payment processing
1780
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1780
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1781 1781
     die();
1782 1782
 }
1783
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1783
+add_action('wpinv_payment', 'wpinv_process_checkout');
1784 1784
 
1785
-function wpinv_get_invoices( $args ) {
1786
-    $args = wp_parse_args( $args, array(
1787
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1785
+function wpinv_get_invoices($args) {
1786
+    $args = wp_parse_args($args, array(
1787
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1788 1788
         'type'     => 'wpi_invoice',
1789 1789
         'parent'   => null,
1790 1790
         'user'     => null,
1791 1791
         'email'    => '',
1792
-        'limit'    => get_option( 'posts_per_page' ),
1792
+        'limit'    => get_option('posts_per_page'),
1793 1793
         'offset'   => null,
1794 1794
         'page'     => 1,
1795 1795
         'exclude'  => array(),
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
         'order'    => 'DESC',
1798 1798
         'return'   => 'objects',
1799 1799
         'paginate' => false,
1800
-    ) );
1800
+    ));
1801 1801
     
1802 1802
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1803 1803
     $map_legacy = array(
@@ -1810,18 +1810,18 @@  discard block
 block discarded – undo
1810 1810
         'paged'          => 'page',
1811 1811
     );
1812 1812
 
1813
-    foreach ( $map_legacy as $from => $to ) {
1814
-        if ( isset( $args[ $from ] ) ) {
1815
-            $args[ $to ] = $args[ $from ];
1813
+    foreach ($map_legacy as $from => $to) {
1814
+        if (isset($args[$from])) {
1815
+            $args[$to] = $args[$from];
1816 1816
         }
1817 1817
     }
1818 1818
 
1819
-    if ( get_query_var( 'paged' ) )
1819
+    if (get_query_var('paged'))
1820 1820
         $args['page'] = get_query_var('paged');
1821
-    else if ( get_query_var( 'page' ) )
1822
-        $args['page'] = get_query_var( 'page' );
1823
-    else if ( !empty( $args[ 'page' ] ) )
1824
-        $args['page'] = $args[ 'page' ];
1821
+    else if (get_query_var('page'))
1822
+        $args['page'] = get_query_var('page');
1823
+    else if (!empty($args['page']))
1824
+        $args['page'] = $args['page'];
1825 1825
     else
1826 1826
         $args['page'] = 1;
1827 1827
 
@@ -1834,48 +1834,48 @@  discard block
 block discarded – undo
1834 1834
         'post_status'    => $args['status'],
1835 1835
         'posts_per_page' => $args['limit'],
1836 1836
         'meta_query'     => array(),
1837
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1837
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1838 1838
         'fields'         => 'ids',
1839 1839
         'orderby'        => $args['orderby'],
1840 1840
         'order'          => $args['order'],
1841 1841
     );
1842 1842
     
1843
-    if ( !empty( $args['user'] ) ) {
1844
-        $wp_query_args['author'] = absint( $args['user'] );
1843
+    if (!empty($args['user'])) {
1844
+        $wp_query_args['author'] = absint($args['user']);
1845 1845
     }
1846 1846
 
1847
-    if ( ! is_null( $args['parent'] ) ) {
1848
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1847
+    if (!is_null($args['parent'])) {
1848
+        $wp_query_args['post_parent'] = absint($args['parent']);
1849 1849
     }
1850 1850
 
1851
-    if ( ! is_null( $args['offset'] ) ) {
1852
-        $wp_query_args['offset'] = absint( $args['offset'] );
1851
+    if (!is_null($args['offset'])) {
1852
+        $wp_query_args['offset'] = absint($args['offset']);
1853 1853
     } else {
1854
-        $wp_query_args['paged'] = absint( $args['page'] );
1854
+        $wp_query_args['paged'] = absint($args['page']);
1855 1855
     }
1856 1856
 
1857
-    if ( ! empty( $args['exclude'] ) ) {
1858
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1857
+    if (!empty($args['exclude'])) {
1858
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1859 1859
     }
1860 1860
 
1861
-    if ( ! $args['paginate' ] ) {
1861
+    if (!$args['paginate']) {
1862 1862
         $wp_query_args['no_found_rows'] = true;
1863 1863
     }
1864 1864
 
1865 1865
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1866 1866
 
1867 1867
     // Get results.
1868
-    $invoices = new WP_Query( $wp_query_args );
1868
+    $invoices = new WP_Query($wp_query_args);
1869 1869
 
1870
-    if ( 'objects' === $args['return'] ) {
1871
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1872
-    } elseif ( 'self' === $args['return'] ) {
1870
+    if ('objects' === $args['return']) {
1871
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1872
+    } elseif ('self' === $args['return']) {
1873 1873
         return $invoices;
1874 1874
     } else {
1875 1875
         $return = $invoices->posts;
1876 1876
     }
1877 1877
 
1878
-    if ( $args['paginate' ] ) {
1878
+    if ($args['paginate']) {
1879 1879
         return (object) array(
1880 1880
             'invoices'      => $return,
1881 1881
             'total'         => $invoices->found_posts,
@@ -1888,22 +1888,22 @@  discard block
 block discarded – undo
1888 1888
 
1889 1889
 function wpinv_get_user_invoices_columns() {
1890 1890
     $columns = array(
1891
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1892
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1893
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1894
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1895
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1896
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1891
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1892
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1893
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1894
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1895
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1896
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1897 1897
         );
1898 1898
 
1899
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1899
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1900 1900
 }
1901 1901
 
1902
-function wpinv_payment_receipt( $atts, $content = null ) {
1902
+function wpinv_payment_receipt($atts, $content = null) {
1903 1903
     global $wpinv_receipt_args;
1904 1904
 
1905
-    $wpinv_receipt_args = shortcode_atts( array(
1906
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1905
+    $wpinv_receipt_args = shortcode_atts(array(
1906
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1907 1907
         'price'           => true,
1908 1908
         'discount'        => true,
1909 1909
         'items'           => true,
@@ -1912,197 +1912,197 @@  discard block
 block discarded – undo
1912 1912
         'invoice_key'     => false,
1913 1913
         'payment_method'  => true,
1914 1914
         'invoice_id'      => true
1915
-    ), $atts, 'wpinv_receipt' );
1915
+    ), $atts, 'wpinv_receipt');
1916 1916
 
1917 1917
     $session = wpinv_get_checkout_session();
1918
-    if ( isset( $_GET['invoice_key'] ) ) {
1919
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1920
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1918
+    if (isset($_GET['invoice_key'])) {
1919
+        $invoice_key = urldecode($_GET['invoice_key']);
1920
+    } else if ($session && isset($session['invoice_key'])) {
1921 1921
         $invoice_key = $session['invoice_key'];
1922
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1922
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1923 1923
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1924
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1925
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1924
+    } else if (isset($_GET['invoice-id'])) {
1925
+        $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']);
1926 1926
     }
1927 1927
 
1928 1928
     // No key found
1929
-    if ( ! isset( $invoice_key ) ) {
1929
+    if (!isset($invoice_key)) {
1930 1930
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1931 1931
     }
1932 1932
 
1933
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1934
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1935
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1936
-        $invoice_id     = (int)$_GET['invoice-id'];
1937
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1933
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1934
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1935
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1936
+        $invoice_id     = (int) $_GET['invoice-id'];
1937
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
1938 1938
     }
1939 1939
 
1940 1940
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1941
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1941
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1942 1942
         // login redirect
1943
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1943
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1944 1944
     }
1945 1945
 
1946
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1946
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1947 1947
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1948 1948
     }
1949 1949
 
1950 1950
     ob_start();
1951 1951
 
1952
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1952
+    wpinv_get_template_part('wpinv-invoice-receipt');
1953 1953
 
1954 1954
     $display = ob_get_clean();
1955 1955
 
1956 1956
     return $display;
1957 1957
 }
1958 1958
 
1959
-function wpinv_get_invoice_id_by_key( $key ) {
1959
+function wpinv_get_invoice_id_by_key($key) {
1960 1960
 	global $wpdb;
1961 1961
 
1962
-	$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 ) );
1962
+	$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));
1963 1963
 
1964
-	if ( $invoice_id != NULL )
1964
+	if ($invoice_id != NULL)
1965 1965
 		return $invoice_id;
1966 1966
 
1967 1967
 	return 0;
1968 1968
 }
1969 1969
 
1970
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1970
+function wpinv_can_view_receipt($invoice_key = '') {
1971 1971
 	$return = false;
1972 1972
 
1973
-	if ( empty( $invoice_key ) ) {
1973
+	if (empty($invoice_key)) {
1974 1974
 		return $return;
1975 1975
 	}
1976 1976
 
1977 1977
 	global $wpinv_receipt_args;
1978 1978
 
1979
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1980
-	if ( isset( $_GET['invoice-id'] ) ) {
1981
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1979
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1980
+	if (isset($_GET['invoice-id'])) {
1981
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
1982 1982
 	}
1983 1983
 
1984
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1984
+	if (empty($wpinv_receipt_args['id'])) {
1985 1985
 		return $return;
1986 1986
 	}
1987 1987
 
1988
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1989
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1988
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1989
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1990 1990
 		return $return;
1991 1991
 	}
1992 1992
 
1993
-	if ( is_user_logged_in() ) {
1994
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1993
+	if (is_user_logged_in()) {
1994
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
1995 1995
 			$return = true;
1996 1996
 		}
1997 1997
 	}
1998 1998
 
1999 1999
 	$session = wpinv_get_checkout_session();
2000
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
2001
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
2000
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
2001
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
2002 2002
 
2003
-		if ( wpinv_require_login_to_checkout() ) {
2003
+		if (wpinv_require_login_to_checkout()) {
2004 2004
 			$return = $return && $check_key === $invoice_key;
2005 2005
 		} else {
2006 2006
 			$return = $check_key === $invoice_key;
2007 2007
 		}
2008 2008
 	}
2009 2009
 
2010
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2010
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2011 2011
 }
2012 2012
 
2013 2013
 function wpinv_pay_for_invoice() {
2014 2014
     global $wpinv_euvat;
2015 2015
     
2016
-    if ( isset( $_GET['invoice_key'] ) ) {
2016
+    if (isset($_GET['invoice_key'])) {
2017 2017
         $checkout_uri   = wpinv_get_checkout_uri();
2018
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2018
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2019 2019
         
2020
-        if ( empty( $invoice_key ) ) {
2021
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2022
-            wp_redirect( $checkout_uri );
2020
+        if (empty($invoice_key)) {
2021
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2022
+            wp_redirect($checkout_uri);
2023 2023
             exit();
2024 2024
         }
2025 2025
         
2026
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2026
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2027 2027
 
2028
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2029
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2030
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2031
-            $invoice_id     = (int)$_GET['invoice-id'];
2032
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2028
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2029
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2030
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2031
+            $invoice_id     = (int) $_GET['invoice-id'];
2032
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2033 2033
         }
2034 2034
         
2035
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2036
-            if ( $invoice->needs_payment() ) {
2035
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2036
+            if ($invoice->needs_payment()) {
2037 2037
                 $data                   = array();
2038 2038
                 $data['invoice_id']     = $invoice_id;
2039
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2039
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2040 2040
                 
2041
-                wpinv_set_checkout_session( $data );
2041
+                wpinv_set_checkout_session($data);
2042 2042
                 
2043
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2043
+                if (wpinv_get_option('vat_ip_country_default')) {
2044 2044
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2045 2045
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2046 2046
                     
2047
-                    wpinv_recalculate_tax( true );
2047
+                    wpinv_recalculate_tax(true);
2048 2048
                 }
2049 2049
                 
2050 2050
             } else {
2051 2051
                 $checkout_uri = $invoice->get_view_url();
2052 2052
             }
2053 2053
         } else {
2054
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2054
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2055 2055
             
2056
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2056
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2057 2057
         }
2058 2058
         
2059
-        if(wp_redirect( $checkout_uri )){
2059
+        if (wp_redirect($checkout_uri)) {
2060 2060
             exit;
2061 2061
         };
2062 2062
         wpinv_die();
2063 2063
     }
2064 2064
 }
2065
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2065
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2066 2066
 
2067
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2068
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2069
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2067
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2068
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2069
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2070 2070
             $user_id = $invoice->get_user_id();
2071
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2071
+            $secret = sanitize_text_field($_GET['_wpipay']);
2072 2072
             
2073
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2074
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2073
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2074
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2075 2075
                 
2076
-                wpinv_guest_redirect( $redirect_to, $user_id );
2076
+                wpinv_guest_redirect($redirect_to, $user_id);
2077 2077
                 exit();
2078 2078
             }
2079 2079
         }
2080 2080
     }
2081 2081
 }
2082
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2082
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2083 2083
 
2084
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2085
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2084
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2085
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2086 2086
     
2087
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2087
+    if (empty($invoice_id) && $invoice_id > 0) {
2088 2088
         return false;
2089 2089
     }
2090 2090
     
2091
-    if ( empty( $transaction_id ) ) {
2091
+    if (empty($transaction_id)) {
2092 2092
         $transaction_id = $invoice_id;
2093 2093
     }
2094 2094
 
2095
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2095
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2096 2096
     
2097
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2097
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2098 2098
 }
2099 2099
 
2100
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2101
-    if ( empty( $status_display ) ) {
2102
-        $status_display = wpinv_status_nicename( $status );
2100
+function wpinv_invoice_status_label($status, $status_display = '') {
2101
+    if (empty($status_display)) {
2102
+        $status_display = wpinv_status_nicename($status);
2103 2103
     }
2104 2104
     
2105
-    switch ( $status ) {
2105
+    switch ($status) {
2106 2106
         case 'publish' :
2107 2107
         case 'wpi-renewal' :
2108 2108
             $class = 'label-success';
@@ -2127,201 +2127,201 @@  discard block
 block discarded – undo
2127 2127
     
2128 2128
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2129 2129
     
2130
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2130
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2131 2131
 }
2132 2132
 
2133
-function wpinv_format_invoice_number( $number, $type = '' ) {
2134
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2135
-    if ( null !== $check ) {
2133
+function wpinv_format_invoice_number($number, $type = '') {
2134
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2135
+    if (null !== $check) {
2136 2136
         return $check;
2137 2137
     }
2138 2138
 
2139
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2139
+    if (!empty($number) && !is_numeric($number)) {
2140 2140
         return $number;
2141 2141
     }
2142 2142
 
2143
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2144
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2145
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2143
+    $padd = wpinv_get_option('invoice_number_padd');
2144
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2145
+    $postfix = wpinv_get_option('invoice_number_postfix');
2146 2146
     
2147
-    $padd = absint( $padd );
2148
-    $formatted_number = absint( $number );
2147
+    $padd = absint($padd);
2148
+    $formatted_number = absint($number);
2149 2149
     
2150
-    if ( $padd > 0 ) {
2151
-        $formatted_number = zeroise( $formatted_number, $padd );
2150
+    if ($padd > 0) {
2151
+        $formatted_number = zeroise($formatted_number, $padd);
2152 2152
     }    
2153 2153
 
2154 2154
     $formatted_number = $prefix . $formatted_number . $postfix;
2155 2155
 
2156
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2156
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2157 2157
 }
2158 2158
 
2159
-function wpinv_get_next_invoice_number( $type = '' ) {
2160
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2161
-    if ( null !== $check ) {
2159
+function wpinv_get_next_invoice_number($type = '') {
2160
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2161
+    if (null !== $check) {
2162 2162
         return $check;
2163 2163
     }
2164 2164
     
2165
-    if ( !wpinv_sequential_number_active() ) {
2165
+    if (!wpinv_sequential_number_active()) {
2166 2166
         return false;
2167 2167
     }
2168 2168
 
2169
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2170
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2171
-    if ( !absint( $start ) > 0 ) {
2169
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2170
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2171
+    if (!absint($start) > 0) {
2172 2172
         $start = 1;
2173 2173
     }
2174 2174
     $increment_number = true;
2175 2175
     $save_number = false;
2176 2176
 
2177
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2178
-        $number = wpinv_clean_invoice_number( $number );
2177
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2178
+        $number = wpinv_clean_invoice_number($number);
2179 2179
     }
2180 2180
 
2181
-    if ( empty( $number ) ) {
2182
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2183
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2181
+    if (empty($number)) {
2182
+        if (!($last_number === 0 || $last_number === '0')) {
2183
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2184 2184
 
2185
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2186
-                if ( is_numeric( $invoice_number ) ) {
2185
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2186
+                if (is_numeric($invoice_number)) {
2187 2187
                     $number = $invoice_number;
2188 2188
                 } else {
2189
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2189
+                    $number = wpinv_clean_invoice_number($invoice_number);
2190 2190
                 }
2191 2191
             }
2192 2192
 
2193
-            if ( empty( $number ) ) {
2193
+            if (empty($number)) {
2194 2194
                 $increment_number = false;
2195 2195
                 $number = $start;
2196
-                $save_number = ( $number - 1 );
2196
+                $save_number = ($number - 1);
2197 2197
             } else {
2198 2198
                 $save_number = $number;
2199 2199
             }
2200 2200
         }
2201 2201
     }
2202 2202
 
2203
-    if ( $start > $number ) {
2203
+    if ($start > $number) {
2204 2204
         $increment_number = false;
2205 2205
         $number = $start;
2206
-        $save_number = ( $number - 1 );
2206
+        $save_number = ($number - 1);
2207 2207
     }
2208 2208
 
2209
-    if ( $save_number !== false ) {
2210
-        update_option( 'wpinv_last_invoice_number', $save_number );
2209
+    if ($save_number !== false) {
2210
+        update_option('wpinv_last_invoice_number', $save_number);
2211 2211
     }
2212 2212
     
2213
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2213
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2214 2214
 
2215
-    if ( $increment_number ) {
2215
+    if ($increment_number) {
2216 2216
         $number++;
2217 2217
     }
2218 2218
 
2219
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2219
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2220 2220
 }
2221 2221
 
2222
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2223
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2224
-    if ( null !== $check ) {
2222
+function wpinv_clean_invoice_number($number, $type = '') {
2223
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2224
+    if (null !== $check) {
2225 2225
         return $check;
2226 2226
     }
2227 2227
     
2228
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2229
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2228
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2229
+    $postfix = wpinv_get_option('invoice_number_postfix');
2230 2230
 
2231
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2231
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2232 2232
 
2233
-    $length      = strlen( $number );
2234
-    $postfix_pos = strrpos( $number, $postfix );
2233
+    $length      = strlen($number);
2234
+    $postfix_pos = strrpos($number, $postfix);
2235 2235
     
2236
-    if ( false !== $postfix_pos ) {
2237
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2236
+    if (false !== $postfix_pos) {
2237
+        $number = substr_replace($number, '', $postfix_pos, $length);
2238 2238
     }
2239 2239
 
2240
-    $number = intval( $number );
2240
+    $number = intval($number);
2241 2241
 
2242
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2242
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2243 2243
 }
2244 2244
 
2245
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2245
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2246 2246
     global $wpdb;
2247 2247
 
2248
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2249
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2248
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2249
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2250 2250
     }
2251 2251
 
2252
-    if ( !$update ) {
2253
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2254
-        clean_post_cache( $post_ID );
2252
+    if (!$update) {
2253
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2254
+        clean_post_cache($post_ID);
2255 2255
     }
2256 2256
 }
2257
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2257
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2258 2258
 
2259
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2260
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2261
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2259
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2260
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2261
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2262 2262
     }
2263 2263
 }
2264
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2264
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2265 2265
 
2266
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2266
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2267 2267
     global $wpdb;
2268 2268
     
2269
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2270
-    if ( null !== $check ) {
2269
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2270
+    if (null !== $check) {
2271 2271
         return $check;
2272 2272
     }
2273 2273
 
2274
-    if ( wpinv_sequential_number_active() ) {
2274
+    if (wpinv_sequential_number_active()) {
2275 2275
         $number = wpinv_get_next_invoice_number();
2276 2276
 
2277
-        if ( $save_sequential ) {
2278
-            update_option( 'wpinv_last_invoice_number', $number );
2277
+        if ($save_sequential) {
2278
+            update_option('wpinv_last_invoice_number', $number);
2279 2279
         }
2280 2280
     } else {
2281 2281
         $number = $post_ID;
2282 2282
     }
2283 2283
 
2284
-    $number = wpinv_format_invoice_number( $number );
2284
+    $number = wpinv_format_invoice_number($number);
2285 2285
 
2286
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2286
+    update_post_meta($post_ID, '_wpinv_number', $number);
2287 2287
 
2288
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2288
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2289 2289
 
2290
-    clean_post_cache( $post_ID );
2290
+    clean_post_cache($post_ID);
2291 2291
 
2292 2292
     return $number;
2293 2293
 }
2294 2294
 
2295
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2296
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2295
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2296
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2297 2297
 }
2298 2298
 
2299
-function wpinv_generate_post_name( $post_ID ) {
2300
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2301
-    $post_name = sanitize_title( $prefix . $post_ID );
2299
+function wpinv_generate_post_name($post_ID) {
2300
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2301
+    $post_name = sanitize_title($prefix . $post_ID);
2302 2302
 
2303
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2303
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2304 2304
 }
2305 2305
 
2306
-function wpinv_is_invoice_viewed( $invoice_id ) {
2307
-    if ( empty( $invoice_id ) ) {
2306
+function wpinv_is_invoice_viewed($invoice_id) {
2307
+    if (empty($invoice_id)) {
2308 2308
         return false;
2309 2309
     }
2310 2310
 
2311
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2311
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2312 2312
 
2313
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2313
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2314 2314
 }
2315 2315
 
2316 2316
 function wpinv_mark_invoice_viewed() {
2317 2317
 
2318
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2319
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2318
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2319
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2320 2320
 	    global $post;
2321 2321
 
2322
-        if(!empty($invoice_key)){
2322
+        if (!empty($invoice_key)) {
2323 2323
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2324
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2324
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2325 2325
 			$invoice_id = $post->ID;
2326 2326
         } else {
2327 2327
         	return;
@@ -2329,60 +2329,60 @@  discard block
 block discarded – undo
2329 2329
 
2330 2330
         $invoice = new WPInv_Invoice($invoice_id);
2331 2331
 
2332
-        if(!$invoice_id){
2332
+        if (!$invoice_id) {
2333 2333
             return;
2334 2334
         }
2335 2335
 
2336
-	    if ( is_user_logged_in() ) {
2337
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2338
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2339
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2340
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2336
+	    if (is_user_logged_in()) {
2337
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2338
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2339
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2340
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2341 2341
 		    }
2342 2342
 	    } else {
2343
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2344
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2343
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2344
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2345 2345
 		    }
2346 2346
 	    }
2347 2347
     }
2348 2348
 
2349 2349
 }
2350
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2350
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2351 2351
 
2352
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2353
-    if ( empty( $invoice ) ) {
2352
+function wpinv_get_subscription($invoice, $by_parent = false) {
2353
+    if (empty($invoice)) {
2354 2354
         return false;
2355 2355
     }
2356 2356
     
2357
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2358
-        $invoice = wpinv_get_invoice( $invoice );
2357
+    if (!is_object($invoice) && is_scalar($invoice)) {
2358
+        $invoice = wpinv_get_invoice($invoice);
2359 2359
     }
2360 2360
     
2361
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2361
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2362 2362
         return false;
2363 2363
     }
2364 2364
     
2365
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2365
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2366 2366
     
2367 2367
     $subs_db    = new WPInv_Subscriptions_DB;
2368
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2368
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2369 2369
     
2370
-    if ( ! empty( $subs ) ) {
2371
-        return reset( $subs );
2370
+    if (!empty($subs)) {
2371
+        return reset($subs);
2372 2372
     }
2373 2373
     
2374 2374
     return false;
2375 2375
 }
2376 2376
 
2377
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2377
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2378 2378
     global $wpdb;
2379 2379
 
2380
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2381
-        if ( !empty( $clauses['join'] ) ) {
2380
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2381
+        if (!empty($clauses['join'])) {
2382 2382
             $clauses['join'] .= " ";
2383 2383
         }
2384 2384
 
2385
-        if ( !empty( $clauses['fields'] ) ) {
2385
+        if (!empty($clauses['fields'])) {
2386 2386
             $clauses['fields'] .= ", ";
2387 2387
         }
2388 2388
 
@@ -2393,4 +2393,4 @@  discard block
 block discarded – undo
2393 2393
 
2394 2394
     return $clauses;
2395 2395
 }
2396
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2397 2396
\ No newline at end of file
2397
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2398 2398
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +624 added lines, -624 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
     public $post_type;
18 18
     
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
     public $full_name = '';
67 67
     public $parent_invoice = 0;
68 68
     
69
-    public function __construct( $invoice_id = false ) {
70
-        if( empty( $invoice_id ) ) {
69
+    public function __construct($invoice_id = false) {
70
+        if (empty($invoice_id)) {
71 71
             return false;
72 72
         }
73 73
 
74
-        $this->setup_invoice( $invoice_id );
74
+        $this->setup_invoice($invoice_id);
75 75
     }
76 76
 
77
-    public function get( $key ) {
78
-        if ( method_exists( $this, 'get_' . $key ) ) {
79
-            $value = call_user_func( array( $this, 'get_' . $key ) );
77
+    public function get($key) {
78
+        if (method_exists($this, 'get_' . $key)) {
79
+            $value = call_user_func(array($this, 'get_' . $key));
80 80
         } else {
81 81
             $value = $this->$key;
82 82
         }
@@ -84,51 +84,51 @@  discard block
 block discarded – undo
84 84
         return $value;
85 85
     }
86 86
 
87
-    public function set( $key, $value ) {
88
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
87
+    public function set($key, $value) {
88
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
89 89
 
90
-        if ( $key === 'status' ) {
90
+        if ($key === 'status') {
91 91
             $this->old_status = $this->status;
92 92
         }
93 93
 
94
-        if ( ! in_array( $key, $ignore ) ) {
95
-            $this->pending[ $key ] = $value;
94
+        if (!in_array($key, $ignore)) {
95
+            $this->pending[$key] = $value;
96 96
         }
97 97
 
98
-        if( '_ID' !== $key ) {
98
+        if ('_ID' !== $key) {
99 99
             $this->$key = $value;
100 100
         }
101 101
     }
102 102
 
103
-    public function _isset( $name ) {
104
-        if ( property_exists( $this, $name) ) {
105
-            return false === empty( $this->$name );
103
+    public function _isset($name) {
104
+        if (property_exists($this, $name)) {
105
+            return false === empty($this->$name);
106 106
         } else {
107 107
             return null;
108 108
         }
109 109
     }
110 110
 
111
-    private function setup_invoice( $invoice_id ) {
111
+    private function setup_invoice($invoice_id) {
112 112
         $this->pending = array();
113 113
 
114
-        if ( empty( $invoice_id ) ) {
114
+        if (empty($invoice_id)) {
115 115
             return false;
116 116
         }
117 117
 
118
-        $invoice = get_post( $invoice_id );
118
+        $invoice = get_post($invoice_id);
119 119
 
120
-        if( !$invoice || is_wp_error( $invoice ) ) {
120
+        if (!$invoice || is_wp_error($invoice)) {
121 121
             return false;
122 122
         }
123 123
 
124
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
124
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
125 125
             return false;
126 126
         }
127 127
 
128
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
128
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
129 129
         
130 130
         // Primary Identifier
131
-        $this->ID              = absint( $invoice_id );
131
+        $this->ID              = absint($invoice_id);
132 132
         $this->post_type       = $invoice->post_type;
133 133
         
134 134
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         $this->post_status     = $this->status;
141 141
         $this->mode            = $this->setup_mode();
142 142
         $this->parent_invoice  = $invoice->post_parent;
143
-        $this->post_name       = $this->setup_post_name( $invoice );
143
+        $this->post_name       = $this->setup_post_name($invoice);
144 144
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
145 145
 
146 146
         // Items
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
         
164 164
         // User based
165 165
         $this->ip              = $this->setup_ip();
166
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
167
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
166
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
167
+        $this->email           = get_the_author_meta('email', $this->user_id);
168 168
         
169 169
         $this->user_info       = $this->setup_user_info();
170 170
                 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         $this->company         = $this->user_info['company'];
174 174
         $this->vat_number      = $this->user_info['vat_number'];
175 175
         $this->vat_rate        = $this->user_info['vat_rate'];
176
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
176
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
177 177
         $this->address         = $this->user_info['address'];
178 178
         $this->city            = $this->user_info['city'];
179 179
         $this->country         = $this->user_info['country'];
@@ -188,39 +188,39 @@  discard block
 block discarded – undo
188 188
         // Other Identifiers
189 189
         $this->key             = $this->setup_invoice_key();
190 190
         $this->number          = $this->setup_invoice_number();
191
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
191
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
192 192
         
193
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
193
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
194 194
         
195 195
         // Allow extensions to add items to this object via hook
196
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
196
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
197 197
 
198 198
         return true;
199 199
     }
200 200
 
201
-    private function setup_status_nicename( $status ) {
202
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
201
+    private function setup_status_nicename($status) {
202
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
203 203
 
204
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
205
-            $all_invoice_statuses  = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
204
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
205
+            $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
206 206
         }
207
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
207
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
208 208
 
209
-        return apply_filters( 'setup_status_nicename', $status );
209
+        return apply_filters('setup_status_nicename', $status);
210 210
     }
211 211
 
212
-    private function setup_post_name( $post = NULL ) {
212
+    private function setup_post_name($post = NULL) {
213 213
         global $wpdb;
214 214
         
215 215
         $post_name = '';
216 216
         
217
-        if ( !empty( $post ) ) {
218
-            if( !empty( $post->post_name ) ) {
217
+        if (!empty($post)) {
218
+            if (!empty($post->post_name)) {
219 219
                 $post_name = $post->post_name;
220
-            } else if ( !empty( $post->ID ) ) {
221
-                $post_name = wpinv_generate_post_name( $post->ID );
220
+            } else if (!empty($post->ID)) {
221
+                $post_name = wpinv_generate_post_name($post->ID);
222 222
 
223
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
223
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
224 224
             }
225 225
         }
226 226
 
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
     }
229 229
     
230 230
     private function setup_due_date() {
231
-        $due_date = $this->get_meta( '_wpinv_due_date' );
231
+        $due_date = $this->get_meta('_wpinv_due_date');
232 232
         
233
-        if ( empty( $due_date ) ) {
234
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
235
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
236
-        } else if ( $due_date == 'none' ) {
233
+        if (empty($due_date)) {
234
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
235
+            $due_date = date_i18n('Y-m-d', $overdue_time);
236
+        } else if ($due_date == 'none') {
237 237
             $due_date = '';
238 238
         }
239 239
         
@@ -241,67 +241,67 @@  discard block
 block discarded – undo
241 241
     }
242 242
     
243 243
     private function setup_completed_date() {
244
-        $invoice = get_post( $this->ID );
244
+        $invoice = get_post($this->ID);
245 245
 
246
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
246
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
247 247
             return false; // This invoice was never paid
248 248
         }
249 249
 
250
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
250
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
251 251
 
252 252
         return $date;
253 253
     }
254 254
     
255 255
     private function setup_cart_details() {
256
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
256
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
257 257
         return $cart_details;
258 258
     }
259 259
     
260 260
     public function array_convert() {
261
-        return get_object_vars( $this );
261
+        return get_object_vars($this);
262 262
     }
263 263
     
264 264
     private function setup_items() {
265
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
265
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
266 266
         return $items;
267 267
     }
268 268
     
269 269
     private function setup_fees() {
270
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
270
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
271 271
         return $payment_fees;
272 272
     }
273 273
         
274 274
     private function setup_currency() {
275
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
275
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
276 276
         return $currency;
277 277
     }
278 278
     
279 279
     private function setup_discount() {
280 280
         //$discount = $this->get_meta( '_wpinv_discount', true );
281
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
282
-        if ( $discount < 0 ) {
281
+        $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total);
282
+        if ($discount < 0) {
283 283
             $discount = 0;
284 284
         }
285
-        $discount = wpinv_round_amount( $discount );
285
+        $discount = wpinv_round_amount($discount);
286 286
         
287 287
         return $discount;
288 288
     }
289 289
     
290 290
     private function setup_discount_code() {
291
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
291
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
292 292
         return $discount_code;
293 293
     }
294 294
     
295 295
     private function setup_tax() {
296 296
 
297
-        $tax = $this->get_meta( '_wpinv_tax', true );
297
+        $tax = $this->get_meta('_wpinv_tax', true);
298 298
 
299 299
         // We don't have tax as it's own meta and no meta was passed
300
-        if ( '' === $tax ) {            
301
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
300
+        if ('' === $tax) {            
301
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
302 302
         }
303 303
         
304
-        if ( $tax < 0 || ! $this->is_taxable() ) {
304
+        if ($tax < 0 || !$this->is_taxable()) {
305 305
             $tax = 0;
306 306
         }
307 307
 
@@ -312,16 +312,16 @@  discard block
 block discarded – undo
312 312
      * If taxes are enabled, allow users to enable/disable taxes per invoice.
313 313
      */
314 314
     private function setup_is_taxable() {
315
-        return (int) $this->get_meta( '_wpinv_disable_taxes', true );
315
+        return (int) $this->get_meta('_wpinv_disable_taxes', true);
316 316
     }
317 317
 
318 318
     private function setup_subtotal() {
319 319
         $subtotal     = 0;
320 320
         $cart_details = $this->cart_details;
321 321
 
322
-        if ( is_array( $cart_details ) ) {
323
-            foreach ( $cart_details as $item ) {
324
-                if ( isset( $item['subtotal'] ) ) {
322
+        if (is_array($cart_details)) {
323
+            foreach ($cart_details as $item) {
324
+                if (isset($item['subtotal'])) {
325 325
                     $subtotal += $item['subtotal'];
326 326
                 }
327 327
             }
@@ -335,23 +335,23 @@  discard block
 block discarded – undo
335 335
     }
336 336
 
337 337
     private function setup_discounts() {
338
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
338
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
339 339
         return $discounts;
340 340
     }
341 341
     
342 342
     private function setup_total() {
343
-        $amount = $this->get_meta( '_wpinv_total', true );
343
+        $amount = $this->get_meta('_wpinv_total', true);
344 344
 
345
-        if ( empty( $amount ) && '0.00' != $amount ) {
346
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
347
-            $meta   = maybe_unserialize( $meta );
345
+        if (empty($amount) && '0.00' != $amount) {
346
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
347
+            $meta   = maybe_unserialize($meta);
348 348
 
349
-            if ( isset( $meta['amount'] ) ) {
349
+            if (isset($meta['amount'])) {
350 350
                 $amount = $meta['amount'];
351 351
             }
352 352
         }
353 353
 
354
-        if($amount < 0){
354
+        if ($amount < 0) {
355 355
             $amount = 0;
356 356
         }
357 357
 
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
     }
360 360
     
361 361
     private function setup_mode() {
362
-        return $this->get_meta( '_wpinv_mode' );
362
+        return $this->get_meta('_wpinv_mode');
363 363
     }
364 364
 
365 365
     private function setup_gateway() {
366
-        $gateway = $this->get_meta( '_wpinv_gateway' );
366
+        $gateway = $this->get_meta('_wpinv_gateway');
367 367
         
368
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
368
+        if (empty($gateway) && 'publish' === $this->status) {
369 369
             $gateway = 'manual';
370 370
         }
371 371
         
@@ -373,23 +373,23 @@  discard block
 block discarded – undo
373 373
     }
374 374
 
375 375
     private function setup_gateway_title() {
376
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
376
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
377 377
         return $gateway_title;
378 378
     }
379 379
 
380 380
     private function setup_transaction_id() {
381
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
381
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
382 382
 
383
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
383
+        if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) {
384 384
             $gateway        = $this->gateway;
385
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
385
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
386 386
         }
387 387
 
388 388
         return $transaction_id;
389 389
     }
390 390
 
391 391
     private function setup_ip() {
392
-        $ip = $this->get_meta( '_wpinv_user_ip' );
392
+        $ip = $this->get_meta('_wpinv_user_ip');
393 393
         return $ip;
394 394
     }
395 395
 
@@ -399,62 +399,62 @@  discard block
 block discarded – undo
399 399
     ///}
400 400
         
401 401
     private function setup_first_name() {
402
-        $first_name = $this->get_meta( '_wpinv_first_name' );
402
+        $first_name = $this->get_meta('_wpinv_first_name');
403 403
         return $first_name;
404 404
     }
405 405
     
406 406
     private function setup_last_name() {
407
-        $last_name = $this->get_meta( '_wpinv_last_name' );
407
+        $last_name = $this->get_meta('_wpinv_last_name');
408 408
         return $last_name;
409 409
     }
410 410
     
411 411
     private function setup_company() {
412
-        $company = $this->get_meta( '_wpinv_company' );
412
+        $company = $this->get_meta('_wpinv_company');
413 413
         return $company;
414 414
     }
415 415
     
416 416
     private function setup_vat_number() {
417
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
417
+        $vat_number = $this->get_meta('_wpinv_vat_number');
418 418
         return $vat_number;
419 419
     }
420 420
     
421 421
     private function setup_vat_rate() {
422
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
422
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
423 423
         return $vat_rate;
424 424
     }
425 425
     
426 426
     private function setup_adddress_confirmed() {
427
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
427
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
428 428
         return $adddress_confirmed;
429 429
     }
430 430
     
431 431
     private function setup_phone() {
432
-        $phone = $this->get_meta( '_wpinv_phone' );
432
+        $phone = $this->get_meta('_wpinv_phone');
433 433
         return $phone;
434 434
     }
435 435
     
436 436
     private function setup_address() {
437
-        $address = $this->get_meta( '_wpinv_address', true );
437
+        $address = $this->get_meta('_wpinv_address', true);
438 438
         return $address;
439 439
     }
440 440
     
441 441
     private function setup_city() {
442
-        $city = $this->get_meta( '_wpinv_city', true );
442
+        $city = $this->get_meta('_wpinv_city', true);
443 443
         return $city;
444 444
     }
445 445
     
446 446
     private function setup_country() {
447
-        $country = $this->get_meta( '_wpinv_country', true );
447
+        $country = $this->get_meta('_wpinv_country', true);
448 448
         return $country;
449 449
     }
450 450
     
451 451
     private function setup_state() {
452
-        $state = $this->get_meta( '_wpinv_state', true );
452
+        $state = $this->get_meta('_wpinv_state', true);
453 453
         return $state;
454 454
     }
455 455
     
456 456
     private function setup_zip() {
457
-        $zip = $this->get_meta( '_wpinv_zip', true );
457
+        $zip = $this->get_meta('_wpinv_zip', true);
458 458
         return $zip;
459 459
     }
460 460
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
             'user_id'        => $this->user_id,
464 464
             'first_name'     => $this->first_name,
465 465
             'last_name'      => $this->last_name,
466
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
466
+            'email'          => get_the_author_meta('email', $this->user_id),
467 467
             'phone'          => $this->phone,
468 468
             'address'        => $this->address,
469 469
             'city'           => $this->city,
@@ -478,12 +478,12 @@  discard block
 block discarded – undo
478 478
         );
479 479
         
480 480
         $user_info = array();
481
-        if ( isset( $this->payment_meta['user_info'] ) ) {
482
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
481
+        if (isset($this->payment_meta['user_info'])) {
482
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
483 483
             
484
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
484
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
485 485
                 $this->user_id = $post->post_author;
486
-                $this->email = get_the_author_meta( 'email', $this->user_id );
486
+                $this->email = get_the_author_meta('email', $this->user_id);
487 487
                 
488 488
                 $user_info['user_id'] = $this->user_id;
489 489
                 $user_info['email'] = $this->email;
@@ -492,13 +492,13 @@  discard block
 block discarded – undo
492 492
             }
493 493
         }
494 494
         
495
-        $user_info    = wp_parse_args( $user_info, $defaults );
495
+        $user_info = wp_parse_args($user_info, $defaults);
496 496
         
497 497
         // Get the user, but only if it's been created
498
-        $user = get_userdata( $this->user_id );
498
+        $user = get_userdata($this->user_id);
499 499
         
500
-        if ( !empty( $user ) && $user->ID > 0 ) {
501
-            if ( empty( $user_info ) ) {
500
+        if (!empty($user) && $user->ID > 0) {
501
+            if (empty($user_info)) {
502 502
                 $user_info = array(
503 503
                     'user_id'    => $user->ID,
504 504
                     'first_name' => $user->first_name,
@@ -507,23 +507,23 @@  discard block
 block discarded – undo
507 507
                     'discount'   => '',
508 508
                 );
509 509
             } else {
510
-                foreach ( $user_info as $key => $value ) {
511
-                    if ( ! empty( $value ) ) {
510
+                foreach ($user_info as $key => $value) {
511
+                    if (!empty($value)) {
512 512
                         continue;
513 513
                     }
514 514
 
515
-                    switch( $key ) {
515
+                    switch ($key) {
516 516
                         case 'user_id':
517
-                            $user_info[ $key ] = $user->ID;
517
+                            $user_info[$key] = $user->ID;
518 518
                             break;
519 519
                         case 'first_name':
520
-                            $user_info[ $key ] = $user->first_name;
520
+                            $user_info[$key] = $user->first_name;
521 521
                             break;
522 522
                         case 'last_name':
523
-                            $user_info[ $key ] = $user->last_name;
523
+                            $user_info[$key] = $user->last_name;
524 524
                             break;
525 525
                         case 'email':
526
-                            $user_info[ $key ] = $user->user_email;
526
+                            $user_info[$key] = $user->user_email;
527 527
                             break;
528 528
                     }
529 529
                 }
@@ -534,25 +534,25 @@  discard block
 block discarded – undo
534 534
     }
535 535
 
536 536
     private function setup_invoice_key() {
537
-        $key = $this->get_meta( '_wpinv_key', true );
537
+        $key = $this->get_meta('_wpinv_key', true);
538 538
         
539 539
         return $key;
540 540
     }
541 541
 
542 542
     private function setup_invoice_number() {
543
-        $number = $this->get_meta( '_wpinv_number', true );
543
+        $number = $this->get_meta('_wpinv_number', true);
544 544
 
545
-        if ( !$number ) {
545
+        if (!$number) {
546 546
             $number = $this->ID;
547 547
 
548
-            if ( $this->status == 'auto-draft' ) {
549
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
550
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
548
+            if ($this->status == 'auto-draft') {
549
+                if (wpinv_sequential_number_active($this->post_type)) {
550
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
551 551
                     $number      = $next_number;
552 552
                 }
553 553
             }
554 554
             
555
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
555
+            $number = wpinv_format_invoice_number($number, $this->post_type);
556 556
         }
557 557
 
558 558
         return $number;
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
     private function insert_invoice() {
562 562
         global $wpdb;
563 563
 
564
-        if ( empty( $this->post_type ) ) {
565
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
564
+        if (empty($this->post_type)) {
565
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
566 566
                 $this->post_type = $post_type;
567
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
567
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
568 568
                 $this->post_type = $post_type;
569 569
             } else {
570 570
                 $this->post_type = 'wpi_invoice';
@@ -572,16 +572,16 @@  discard block
 block discarded – undo
572 572
         }
573 573
 
574 574
         $invoice_number = $this->ID;
575
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
575
+        if ($number = $this->get_meta('_wpinv_number', true)) {
576 576
             $invoice_number = $number;
577 577
         }
578 578
 
579
-        if ( empty( $this->key ) ) {
579
+        if (empty($this->key)) {
580 580
             $this->key = self::generate_key();
581 581
             $this->pending['key'] = $this->key;
582 582
         }
583 583
 
584
-        if ( empty( $this->ip ) ) {
584
+        if (empty($this->ip)) {
585 585
             $this->ip = wpinv_get_ip();
586 586
             $this->pending['ip'] = $this->ip;
587 587
         }
@@ -618,61 +618,61 @@  discard block
 block discarded – undo
618 618
                         'post_status'   => $this->status,
619 619
                         'post_author'   => $this->user_id,
620 620
                         'post_type'     => $this->post_type,
621
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
622
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
621
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
622
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
623 623
                         'post_parent'   => $this->parent_invoice,
624 624
                     );
625
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
625
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
626 626
 
627 627
         // Create a blank invoice
628
-        if ( !empty( $this->ID ) ) {
629
-            $args['ID']         = $this->ID;
628
+        if (!empty($this->ID)) {
629
+            $args['ID'] = $this->ID;
630 630
 
631
-            $invoice_id = wp_update_post( $args, true );
631
+            $invoice_id = wp_update_post($args, true);
632 632
         } else {
633
-            $invoice_id = wp_insert_post( $args, true );
633
+            $invoice_id = wp_insert_post($args, true);
634 634
         }
635 635
 
636
-        if ( is_wp_error( $invoice_id ) ) {
636
+        if (is_wp_error($invoice_id)) {
637 637
             return false;
638 638
         }
639 639
 
640
-        if ( !empty( $invoice_id ) ) {
640
+        if (!empty($invoice_id)) {
641 641
             $this->ID  = $invoice_id;
642 642
             $this->_ID = $invoice_id;
643 643
 
644
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
645
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
646
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
647
-                foreach( $this->fees as $fee ) {
648
-                    $this->increase_fees( $fee['amount'] );
644
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
645
+            if (!empty($this->payment_meta['fees'])) {
646
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
647
+                foreach ($this->fees as $fee) {
648
+                    $this->increase_fees($fee['amount']);
649 649
                 }
650 650
             }
651 651
 
652
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );    
652
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);    
653 653
             $this->new = true;
654 654
         }
655 655
 
656 656
         return $this->ID;
657 657
     }
658 658
 
659
-    public function save( $setup = false ) {
659
+    public function save($setup = false) {
660 660
         global $wpi_session;
661 661
         
662 662
         $saved = false;
663
-        if ( empty( $this->items ) ) {
663
+        if (empty($this->items)) {
664 664
             return $saved; // Don't save empty invoice.
665 665
         }
666 666
         
667
-        if ( empty( $this->key ) ) {
667
+        if (empty($this->key)) {
668 668
             $this->key = self::generate_key();
669 669
             $this->pending['key'] = $this->key;
670 670
         }
671 671
         
672
-        if ( empty( $this->ID ) ) {
672
+        if (empty($this->ID)) {
673 673
             $invoice_id = $this->insert_invoice();
674 674
 
675
-            if ( false === $invoice_id ) {
675
+            if (false === $invoice_id) {
676 676
                 $saved = false;
677 677
             } else {
678 678
                 $this->ID = $invoice_id;
@@ -680,27 +680,27 @@  discard block
 block discarded – undo
680 680
         }
681 681
 
682 682
         // If we have something pending, let's save it
683
-        if ( !empty( $this->pending ) ) {
683
+        if (!empty($this->pending)) {
684 684
             $total_increase = 0;
685 685
             $total_decrease = 0;
686 686
 
687
-            foreach ( $this->pending as $key => $value ) {
688
-                switch( $key ) {
687
+            foreach ($this->pending as $key => $value) {
688
+                switch ($key) {
689 689
                     case 'items':
690 690
                         // Update totals for pending items
691
-                        foreach ( $this->pending[ $key ] as $item ) {
692
-                            switch( $item['action'] ) {
691
+                        foreach ($this->pending[$key] as $item) {
692
+                            switch ($item['action']) {
693 693
                                 case 'add':
694 694
                                     $price = $item['price'];
695 695
                                     $taxes = $item['tax'];
696 696
 
697
-                                    if ( 'publish' === $this->status ) {
697
+                                    if ('publish' === $this->status) {
698 698
                                         $total_increase += $price;
699 699
                                     }
700 700
                                     break;
701 701
 
702 702
                                 case 'remove':
703
-                                    if ( 'publish' === $this->status ) {
703
+                                    if ('publish' === $this->status) {
704 704
                                         $total_decrease += $item['price'];
705 705
                                     }
706 706
                                     break;
@@ -708,16 +708,16 @@  discard block
 block discarded – undo
708 708
                         }
709 709
                         break;
710 710
                     case 'fees':
711
-                        if ( 'publish' !== $this->status ) {
711
+                        if ('publish' !== $this->status) {
712 712
                             break;
713 713
                         }
714 714
 
715
-                        if ( empty( $this->pending[ $key ] ) ) {
715
+                        if (empty($this->pending[$key])) {
716 716
                             break;
717 717
                         }
718 718
 
719
-                        foreach ( $this->pending[ $key ] as $fee ) {
720
-                            switch( $fee['action'] ) {
719
+                        foreach ($this->pending[$key] as $fee) {
720
+                            switch ($fee['action']) {
721 721
                                 case 'add':
722 722
                                     $total_increase += $fee['amount'];
723 723
                                     break;
@@ -729,86 +729,86 @@  discard block
 block discarded – undo
729 729
                         }
730 730
                         break;
731 731
                     case 'status':
732
-                        $this->update_status( $this->status );
732
+                        $this->update_status($this->status);
733 733
                         break;
734 734
                     case 'gateway':
735
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
735
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
736 736
                         break;
737 737
                     case 'mode':
738
-                        $this->update_meta( '_wpinv_mode', $this->mode );
738
+                        $this->update_meta('_wpinv_mode', $this->mode);
739 739
                         break;
740 740
                     case 'transaction_id':
741
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
741
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
742 742
                         break;
743 743
                     case 'ip':
744
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
744
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
745 745
                         break;
746 746
                     ///case 'user_id':
747 747
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
748 748
                         ///$this->user_info['user_id'] = $this->user_id;
749 749
                         ///break;
750 750
                     case 'first_name':
751
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
751
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
752 752
                         $this->user_info['first_name'] = $this->first_name;
753 753
                         break;
754 754
                     case 'last_name':
755
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
755
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
756 756
                         $this->user_info['last_name'] = $this->last_name;
757 757
                         break;
758 758
                     case 'phone':
759
-                        $this->update_meta( '_wpinv_phone', $this->phone );
759
+                        $this->update_meta('_wpinv_phone', $this->phone);
760 760
                         $this->user_info['phone'] = $this->phone;
761 761
                         break;
762 762
                     case 'address':
763
-                        $this->update_meta( '_wpinv_address', $this->address );
763
+                        $this->update_meta('_wpinv_address', $this->address);
764 764
                         $this->user_info['address'] = $this->address;
765 765
                         break;
766 766
                     case 'city':
767
-                        $this->update_meta( '_wpinv_city', $this->city );
767
+                        $this->update_meta('_wpinv_city', $this->city);
768 768
                         $this->user_info['city'] = $this->city;
769 769
                         break;
770 770
                     case 'country':
771
-                        $this->update_meta( '_wpinv_country', $this->country );
771
+                        $this->update_meta('_wpinv_country', $this->country);
772 772
                         $this->user_info['country'] = $this->country;
773 773
                         break;
774 774
                     case 'state':
775
-                        $this->update_meta( '_wpinv_state', $this->state );
775
+                        $this->update_meta('_wpinv_state', $this->state);
776 776
                         $this->user_info['state'] = $this->state;
777 777
                         break;
778 778
                     case 'zip':
779
-                        $this->update_meta( '_wpinv_zip', $this->zip );
779
+                        $this->update_meta('_wpinv_zip', $this->zip);
780 780
                         $this->user_info['zip'] = $this->zip;
781 781
                         break;
782 782
                     case 'company':
783
-                        $this->update_meta( '_wpinv_company', $this->company );
783
+                        $this->update_meta('_wpinv_company', $this->company);
784 784
                         $this->user_info['company'] = $this->company;
785 785
                         break;
786 786
                     case 'vat_number':
787
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
787
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
788 788
                         $this->user_info['vat_number'] = $this->vat_number;
789 789
                         
790
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
791
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
792
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
793
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
794
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
790
+                        $vat_info = $wpi_session->get('user_vat_data');
791
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
792
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
793
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
794
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
795 795
                         }
796 796
     
797 797
                         break;
798 798
                     case 'vat_rate':
799
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
799
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
800 800
                         $this->user_info['vat_rate'] = $this->vat_rate;
801 801
                         break;
802 802
                     case 'adddress_confirmed':
803
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
803
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
804 804
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
805 805
                         break;
806 806
                     
807 807
                     case 'key':
808
-                        $this->update_meta( '_wpinv_key', $this->key );
808
+                        $this->update_meta('_wpinv_key', $this->key);
809 809
                         break;
810 810
                     case 'disable_taxes':
811
-                        $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes );
811
+                        $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes);
812 812
                         break;
813 813
                     case 'date':
814 814
                         $args = array(
@@ -817,49 +817,49 @@  discard block
 block discarded – undo
817 817
                             'edit_date' => true,
818 818
                         );
819 819
 
820
-                        wp_update_post( $args );
820
+                        wp_update_post($args);
821 821
                         break;
822 822
                     case 'due_date':
823
-                        if ( empty( $this->due_date ) ) {
823
+                        if (empty($this->due_date)) {
824 824
                             $this->due_date = 'none';
825 825
                         }
826 826
                         
827
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
827
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
828 828
                         break;
829 829
                     case 'completed_date':
830
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
830
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
831 831
                         break;
832 832
                     case 'discounts':
833
-                        if ( ! is_array( $this->discounts ) ) {
834
-                            $this->discounts = explode( ',', $this->discounts );
833
+                        if (!is_array($this->discounts)) {
834
+                            $this->discounts = explode(',', $this->discounts);
835 835
                         }
836 836
 
837
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
837
+                        $this->user_info['discount'] = implode(',', $this->discounts);
838 838
                         break;
839 839
                     case 'discount':
840
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
840
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
841 841
                         break;
842 842
                     case 'discount_code':
843
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
843
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
844 844
                         break;
845 845
                     case 'parent_invoice':
846 846
                         $args = array(
847 847
                             'ID'          => $this->ID,
848 848
                             'post_parent' => $this->parent_invoice,
849 849
                         );
850
-                        wp_update_post( $args );
850
+                        wp_update_post($args);
851 851
                         break;
852 852
                     default:
853
-                        do_action( 'wpinv_save', $this, $key );
853
+                        do_action('wpinv_save', $this, $key);
854 854
                         break;
855 855
                 }
856 856
             }
857 857
 
858
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
859
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
860
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
858
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
859
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
860
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
861 861
             
862
-            $this->items    = array_values( $this->items );
862
+            $this->items = array_values($this->items);
863 863
             
864 864
             $new_meta = array(
865 865
                 'items'         => $this->items,
@@ -870,12 +870,12 @@  discard block
 block discarded – undo
870 870
             );
871 871
             
872 872
             $meta        = $this->get_meta();
873
-            $merged_meta = array_merge( $meta, $new_meta );
873
+            $merged_meta = array_merge($meta, $new_meta);
874 874
 
875 875
             // Only save the payment meta if it's changed
876
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
877
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
878
-                if ( false !== $updated ) {
876
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
877
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
878
+                if (false !== $updated) {
879 879
                     $saved = true;
880 880
                 }
881 881
             }
@@ -883,15 +883,15 @@  discard block
 block discarded – undo
883 883
             $this->pending = array();
884 884
             $saved         = true;
885 885
         } else {
886
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
887
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
888
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
886
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
887
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
888
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
889 889
         }
890 890
         
891
-        do_action( 'wpinv_invoice_save', $this, $saved );
891
+        do_action('wpinv_invoice_save', $this, $saved);
892 892
 
893
-        if ( true === $saved || $setup ) {
894
-            $this->setup_invoice( $this->ID );
893
+        if (true === $saved || $setup) {
894
+            $this->setup_invoice($this->ID);
895 895
         }
896 896
         
897 897
         $this->refresh_item_ids();
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
         return $saved;
900 900
     }
901 901
     
902
-    public function add_fee( $args, $global = true ) {
902
+    public function add_fee($args, $global = true) {
903 903
         $default_args = array(
904 904
             'label'       => '',
905 905
             'amount'      => 0,
@@ -909,75 +909,75 @@  discard block
 block discarded – undo
909 909
             'item_id'     => 0,
910 910
         );
911 911
 
912
-        $fee = wp_parse_args( $args, $default_args );
912
+        $fee = wp_parse_args($args, $default_args);
913 913
         
914
-        if ( empty( $fee['label'] ) ) {
914
+        if (empty($fee['label'])) {
915 915
             return false;
916 916
         }
917 917
         
918
-        $fee['id']  = sanitize_title( $fee['label'] );
918
+        $fee['id'] = sanitize_title($fee['label']);
919 919
         
920
-        $this->fees[]               = $fee;
920
+        $this->fees[] = $fee;
921 921
         
922 922
         $added_fee               = $fee;
923 923
         $added_fee['action']     = 'add';
924 924
         $this->pending['fees'][] = $added_fee;
925
-        reset( $this->fees );
925
+        reset($this->fees);
926 926
 
927
-        $this->increase_fees( $fee['amount'] );
927
+        $this->increase_fees($fee['amount']);
928 928
         return true;
929 929
     }
930 930
 
931
-    public function remove_fee( $key ) {
931
+    public function remove_fee($key) {
932 932
         $removed = false;
933 933
 
934
-        if ( is_numeric( $key ) ) {
935
-            $removed = $this->remove_fee_by( 'index', $key );
934
+        if (is_numeric($key)) {
935
+            $removed = $this->remove_fee_by('index', $key);
936 936
         }
937 937
 
938 938
         return $removed;
939 939
     }
940 940
 
941
-    public function remove_fee_by( $key, $value, $global = false ) {
942
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
941
+    public function remove_fee_by($key, $value, $global = false) {
942
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
943 943
             'index', 'label', 'amount', 'type',
944
-        ) );
944
+        ));
945 945
 
946
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
946
+        if (!in_array($key, $allowed_fee_keys)) {
947 947
             return false;
948 948
         }
949 949
 
950 950
         $removed = false;
951
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
952
-            $removed_fee             = $this->fees[ $value ];
951
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
952
+            $removed_fee             = $this->fees[$value];
953 953
             $removed_fee['action']   = 'remove';
954 954
             $this->pending['fees'][] = $removed_fee;
955 955
 
956
-            $this->decrease_fees( $removed_fee['amount'] );
956
+            $this->decrease_fees($removed_fee['amount']);
957 957
 
958
-            unset( $this->fees[ $value ] );
958
+            unset($this->fees[$value]);
959 959
             $removed = true;
960
-        } else if ( 'index' !== $key ) {
961
-            foreach ( $this->fees as $index => $fee ) {
962
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
960
+        } else if ('index' !== $key) {
961
+            foreach ($this->fees as $index => $fee) {
962
+                if (isset($fee[$key]) && $fee[$key] == $value) {
963 963
                     $removed_fee             = $fee;
964 964
                     $removed_fee['action']   = 'remove';
965 965
                     $this->pending['fees'][] = $removed_fee;
966 966
 
967
-                    $this->decrease_fees( $removed_fee['amount'] );
967
+                    $this->decrease_fees($removed_fee['amount']);
968 968
 
969
-                    unset( $this->fees[ $index ] );
969
+                    unset($this->fees[$index]);
970 970
                     $removed = true;
971 971
 
972
-                    if ( false === $global ) {
972
+                    if (false === $global) {
973 973
                         break;
974 974
                     }
975 975
                 }
976 976
             }
977 977
         }
978 978
 
979
-        if ( true === $removed ) {
980
-            $this->fees = array_values( $this->fees );
979
+        if (true === $removed) {
980
+            $this->fees = array_values($this->fees);
981 981
         }
982 982
 
983 983
         return $removed;
@@ -985,35 +985,35 @@  discard block
 block discarded – undo
985 985
 
986 986
     
987 987
 
988
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
988
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
989 989
         // Bail if no note specified
990
-        if( !$note ) {
990
+        if (!$note) {
991 991
             return false;
992 992
         }
993 993
 
994
-        if ( empty( $this->ID ) )
994
+        if (empty($this->ID))
995 995
             return false;
996 996
         
997
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
998
-            $user                 = get_user_by( 'id', get_current_user_id() );
997
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
998
+            $user                 = get_user_by('id', get_current_user_id());
999 999
             $comment_author       = $user->display_name;
1000 1000
             $comment_author_email = $user->user_email;
1001 1001
         } else {
1002 1002
             $comment_author       = 'System';
1003 1003
             $comment_author_email = 'system@';
1004
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
1005
-            $comment_author_email = sanitize_email( $comment_author_email );
1004
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
1005
+            $comment_author_email = sanitize_email($comment_author_email);
1006 1006
         }
1007 1007
 
1008
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
1008
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
1009 1009
 
1010
-        $note_id = wp_insert_comment( wp_filter_comment( array(
1010
+        $note_id = wp_insert_comment(wp_filter_comment(array(
1011 1011
             'comment_post_ID'      => $this->ID,
1012 1012
             'comment_content'      => $note,
1013 1013
             'comment_agent'        => 'WPInvoicing',
1014 1014
             'user_id'              => is_admin() ? get_current_user_id() : 0,
1015
-            'comment_date'         => current_time( 'mysql' ),
1016
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
1015
+            'comment_date'         => current_time('mysql'),
1016
+            'comment_date_gmt'     => current_time('mysql', 1),
1017 1017
             'comment_approved'     => 1,
1018 1018
             'comment_parent'       => 0,
1019 1019
             'comment_author'       => $comment_author,
@@ -1021,53 +1021,53 @@  discard block
 block discarded – undo
1021 1021
             'comment_author_url'   => '',
1022 1022
             'comment_author_email' => $comment_author_email,
1023 1023
             'comment_type'         => 'wpinv_note'
1024
-        ) ) );
1024
+        )));
1025 1025
 
1026
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1026
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1027 1027
         
1028
-        if ( $customer_type ) {
1029
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1028
+        if ($customer_type) {
1029
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1030 1030
 
1031
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1031
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1032 1032
         }
1033 1033
 
1034 1034
         return $note_id;
1035 1035
     }
1036 1036
 
1037
-    private function increase_subtotal( $amount = 0.00 ) {
1037
+    private function increase_subtotal($amount = 0.00) {
1038 1038
         $amount          = (float) $amount;
1039 1039
         $this->subtotal += $amount;
1040
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1040
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1041 1041
 
1042 1042
         $this->recalculate_total();
1043 1043
     }
1044 1044
 
1045
-    private function decrease_subtotal( $amount = 0.00 ) {
1045
+    private function decrease_subtotal($amount = 0.00) {
1046 1046
         $amount          = (float) $amount;
1047 1047
         $this->subtotal -= $amount;
1048
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1048
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1049 1049
 
1050
-        if ( $this->subtotal < 0 ) {
1050
+        if ($this->subtotal < 0) {
1051 1051
             $this->subtotal = 0;
1052 1052
         }
1053 1053
 
1054 1054
         $this->recalculate_total();
1055 1055
     }
1056 1056
 
1057
-    private function increase_fees( $amount = 0.00 ) {
1058
-        $amount            = (float)$amount;
1057
+    private function increase_fees($amount = 0.00) {
1058
+        $amount            = (float) $amount;
1059 1059
         $this->fees_total += $amount;
1060
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1060
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1061 1061
 
1062 1062
         $this->recalculate_total();
1063 1063
     }
1064 1064
 
1065
-    private function decrease_fees( $amount = 0.00 ) {
1065
+    private function decrease_fees($amount = 0.00) {
1066 1066
         $amount            = (float) $amount;
1067 1067
         $this->fees_total -= $amount;
1068
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1068
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1069 1069
 
1070
-        if ( $this->fees_total < 0 ) {
1070
+        if ($this->fees_total < 0) {
1071 1071
             $this->fees_total = 0;
1072 1072
         }
1073 1073
 
@@ -1078,54 +1078,54 @@  discard block
 block discarded – undo
1078 1078
         global $wpi_nosave;
1079 1079
         
1080 1080
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1081
-        $this->total = wpinv_round_amount( $this->total );
1081
+        $this->total = wpinv_round_amount($this->total);
1082 1082
         
1083
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1083
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1084 1084
     }
1085 1085
     
1086
-    public function increase_tax( $amount = 0.00 ) {
1086
+    public function increase_tax($amount = 0.00) {
1087 1087
         $amount       = (float) $amount;
1088 1088
         $this->tax   += $amount;
1089 1089
 
1090 1090
         $this->recalculate_total();
1091 1091
     }
1092 1092
 
1093
-    public function decrease_tax( $amount = 0.00 ) {
1093
+    public function decrease_tax($amount = 0.00) {
1094 1094
         $amount     = (float) $amount;
1095 1095
         $this->tax -= $amount;
1096 1096
 
1097
-        if ( $this->tax < 0 ) {
1097
+        if ($this->tax < 0) {
1098 1098
             $this->tax = 0;
1099 1099
         }
1100 1100
 
1101 1101
         $this->recalculate_total();
1102 1102
     }
1103 1103
 
1104
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1105
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1104
+    public function update_status($new_status = false, $note = '', $manual = false) {
1105
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1106 1106
 
1107
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1107
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1108 1108
             return false; // Don't permit status changes that aren't changes
1109 1109
         }
1110 1110
 
1111
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1111
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1112 1112
         $updated = false;
1113 1113
 
1114
-        if ( $do_change ) {
1115
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1114
+        if ($do_change) {
1115
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1116 1116
 
1117 1117
             $update_post_data                   = array();
1118 1118
             $update_post_data['ID']             = $this->ID;
1119 1119
             $update_post_data['post_status']    = $new_status;
1120
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1121
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1120
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1121
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1122 1122
             
1123
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1123
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1124 1124
 
1125
-            $updated = wp_update_post( $update_post_data );     
1125
+            $updated = wp_update_post($update_post_data);     
1126 1126
            
1127 1127
             // Process any specific status functions
1128
-            switch( $new_status ) {
1128
+            switch ($new_status) {
1129 1129
                 case 'wpi-refunded':
1130 1130
                     $this->process_refund();
1131 1131
                     break;
@@ -1138,9 +1138,9 @@  discard block
 block discarded – undo
1138 1138
             }
1139 1139
             
1140 1140
             // Status was changed.
1141
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1142
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1143
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1141
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1142
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1143
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1144 1144
         }
1145 1145
 
1146 1146
         return $updated;
@@ -1154,20 +1154,20 @@  discard block
 block discarded – undo
1154 1154
         $this->save();
1155 1155
     }
1156 1156
 
1157
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1158
-        if ( empty( $meta_key ) ) {
1157
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1158
+        if (empty($meta_key)) {
1159 1159
             return false;
1160 1160
         }
1161 1161
 
1162
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1162
+        if ($meta_key == 'key' || $meta_key == 'date') {
1163 1163
             $current_meta = $this->get_meta();
1164
-            $current_meta[ $meta_key ] = $meta_value;
1164
+            $current_meta[$meta_key] = $meta_value;
1165 1165
 
1166 1166
             $meta_key     = '_wpinv_payment_meta';
1167 1167
             $meta_value   = $current_meta;
1168 1168
         }
1169 1169
 
1170
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1170
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1171 1171
         
1172 1172
         // Do not update created date on invoice marked as paid.
1173 1173
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1182,45 +1182,45 @@  discard block
 block discarded – undo
1182 1182
             wp_update_post( $args );
1183 1183
         }*/
1184 1184
         
1185
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1185
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1186 1186
     }
1187 1187
 
1188 1188
     private function process_refund() {
1189 1189
         $process_refund = true;
1190 1190
 
1191 1191
         // If the payment was not in publish, don't decrement stats as they were never incremented
1192
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1192
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1193 1193
             $process_refund = false;
1194 1194
         }
1195 1195
 
1196 1196
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1197
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1197
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1198 1198
 
1199
-        if ( false === $process_refund ) {
1199
+        if (false === $process_refund) {
1200 1200
             return;
1201 1201
         }
1202 1202
 
1203
-        do_action( 'wpinv_pre_refund_invoice', $this );
1203
+        do_action('wpinv_pre_refund_invoice', $this);
1204 1204
         
1205
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1206
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1207
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1205
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1206
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1207
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1208 1208
         
1209
-        do_action( 'wpinv_post_refund_invoice', $this );
1209
+        do_action('wpinv_post_refund_invoice', $this);
1210 1210
     }
1211 1211
 
1212 1212
     private function process_failure() {
1213 1213
         $discounts = $this->discounts;
1214
-        if ( empty( $discounts ) ) {
1214
+        if (empty($discounts)) {
1215 1215
             return;
1216 1216
         }
1217 1217
 
1218
-        if ( ! is_array( $discounts ) ) {
1219
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1218
+        if (!is_array($discounts)) {
1219
+            $discounts = array_map('trim', explode(',', $discounts));
1220 1220
         }
1221 1221
 
1222
-        foreach ( $discounts as $discount ) {
1223
-            wpinv_decrease_discount_usage( $discount );
1222
+        foreach ($discounts as $discount) {
1223
+            wpinv_decrease_discount_usage($discount);
1224 1224
         }
1225 1225
     }
1226 1226
     
@@ -1228,92 +1228,92 @@  discard block
 block discarded – undo
1228 1228
         $process_pending = true;
1229 1229
 
1230 1230
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1231
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1231
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1232 1232
             $process_pending = false;
1233 1233
         }
1234 1234
 
1235 1235
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1236
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1236
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1237 1237
 
1238
-        if ( false === $process_pending ) {
1238
+        if (false === $process_pending) {
1239 1239
             return;
1240 1240
         }
1241 1241
 
1242
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1243
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1244
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1242
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1243
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1244
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1245 1245
 
1246 1246
         $this->completed_date = '';
1247
-        $this->update_meta( '_wpinv_completed_date', '' );
1247
+        $this->update_meta('_wpinv_completed_date', '');
1248 1248
     }
1249 1249
     
1250 1250
     // get data
1251
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1252
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1251
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1252
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1253 1253
 
1254
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1254
+        if ($meta_key === '_wpinv_payment_meta') {
1255 1255
 
1256
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1256
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1257 1257
 
1258
-            if ( empty( $meta['key'] ) ) {
1258
+            if (empty($meta['key'])) {
1259 1259
                 $meta['key'] = $this->setup_invoice_key();
1260 1260
             }
1261 1261
 
1262
-            if ( empty( $meta['date'] ) ) {
1263
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1262
+            if (empty($meta['date'])) {
1263
+                $meta['date'] = get_post_field('post_date', $this->ID);
1264 1264
             }
1265 1265
         }
1266 1266
 
1267
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1267
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1268 1268
 
1269
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1269
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1270 1270
     }
1271 1271
     
1272 1272
     public function get_description() {
1273
-        $post = get_post( $this->ID );
1273
+        $post = get_post($this->ID);
1274 1274
         
1275
-        $description = !empty( $post ) ? $post->post_content : '';
1276
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1275
+        $description = !empty($post) ? $post->post_content : '';
1276
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1277 1277
     }
1278 1278
     
1279
-    public function get_status( $nicename = false ) {
1280
-        if ( !$nicename ) {
1279
+    public function get_status($nicename = false) {
1280
+        if (!$nicename) {
1281 1281
             $status = $this->status;
1282 1282
         } else {
1283 1283
             $status = $this->status_nicename;
1284 1284
         }
1285 1285
         
1286
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1286
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1287 1287
     }
1288 1288
     
1289 1289
     public function get_cart_details() {
1290
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1290
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1291 1291
     }
1292 1292
     
1293
-    public function get_subtotal( $currency = false ) {
1294
-        $subtotal = wpinv_round_amount( $this->subtotal );
1293
+    public function get_subtotal($currency = false) {
1294
+        $subtotal = wpinv_round_amount($this->subtotal);
1295 1295
         
1296
-        if ( $currency ) {
1297
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1296
+        if ($currency) {
1297
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1298 1298
         }
1299 1299
         
1300
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1300
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1301 1301
     }
1302 1302
     
1303
-    public function get_total( $currency = false ) {        
1304
-        if ( $this->is_free_trial() ) {
1305
-            $total = wpinv_round_amount( 0 );
1303
+    public function get_total($currency = false) {        
1304
+        if ($this->is_free_trial()) {
1305
+            $total = wpinv_round_amount(0);
1306 1306
         } else {
1307
-            $total = wpinv_round_amount( $this->total );
1307
+            $total = wpinv_round_amount($this->total);
1308 1308
         }
1309
-        if ( $currency ) {
1310
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1309
+        if ($currency) {
1310
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1311 1311
         }
1312 1312
         
1313
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1313
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1314 1314
     }
1315 1315
     
1316
-    public function get_recurring_details( $field = '', $currency = false ) {        
1316
+    public function get_recurring_details($field = '', $currency = false) {        
1317 1317
         $data                 = array();
1318 1318
         $data['cart_details'] = $this->cart_details;
1319 1319
         $data['subtotal']     = $this->get_subtotal();
@@ -1321,119 +1321,119 @@  discard block
 block discarded – undo
1321 1321
         $data['tax']          = $this->get_tax();
1322 1322
         $data['total']        = $this->get_total();
1323 1323
     
1324
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1324
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1325 1325
             $is_free_trial = $this->is_free_trial();
1326
-            $discounts = $this->get_discounts( true );
1326
+            $discounts = $this->get_discounts(true);
1327 1327
             
1328
-            if ( $is_free_trial || !empty( $discounts ) ) {
1328
+            if ($is_free_trial || !empty($discounts)) {
1329 1329
                 $first_use_only = false;
1330 1330
                 
1331
-                if ( !empty( $discounts ) ) {
1332
-                    foreach ( $discounts as $key => $code ) {
1333
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1331
+                if (!empty($discounts)) {
1332
+                    foreach ($discounts as $key => $code) {
1333
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1334 1334
                             $first_use_only = true;
1335 1335
                             break;
1336 1336
                         }
1337 1337
                     }
1338 1338
                 }
1339 1339
                     
1340
-                if ( !$first_use_only ) {
1341
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1342
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1343
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1344
-                    $data['total']    = wpinv_round_amount( $this->total );
1340
+                if (!$first_use_only) {
1341
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1342
+                    $data['discount'] = wpinv_round_amount($this->discount);
1343
+                    $data['tax']      = wpinv_round_amount($this->tax);
1344
+                    $data['total']    = wpinv_round_amount($this->total);
1345 1345
                 } else {
1346 1346
                     $cart_subtotal   = 0;
1347 1347
                     $cart_discount   = $this->discount;
1348 1348
                     $cart_tax        = 0;
1349 1349
 
1350
-                    foreach ( $this->cart_details as $key => $item ) {
1351
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1352
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1350
+                    foreach ($this->cart_details as $key => $item) {
1351
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1352
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1353 1353
                         $item_discount  = 0;
1354
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1354
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1355 1355
                         
1356
-                        if ( wpinv_prices_include_tax() ) {
1357
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1356
+                        if (wpinv_prices_include_tax()) {
1357
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1358 1358
                         }
1359 1359
                         
1360 1360
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1361 1361
                         // Do not allow totals to go negative
1362
-                        if ( $item_total < 0 ) {
1362
+                        if ($item_total < 0) {
1363 1363
                             $item_total = 0;
1364 1364
                         }
1365 1365
                         
1366
-                        $cart_subtotal  += (float)($item_subtotal);
1367
-                        $cart_discount  += (float)($item_discount);
1368
-                        $cart_tax       += (float)($item_tax);
1366
+                        $cart_subtotal  += (float) ($item_subtotal);
1367
+                        $cart_discount  += (float) ($item_discount);
1368
+                        $cart_tax       += (float) ($item_tax);
1369 1369
                         
1370
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1371
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1372
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1370
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1371
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1372
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1373 1373
                     }
1374 1374
 
1375 1375
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1376
-	                if ( $total < 0 ) {
1376
+	                if ($total < 0) {
1377 1377
 		                $total = 0;
1378 1378
 	                }
1379 1379
 
1380
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1381
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1382
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1383
-                    $data['total']    = wpinv_round_amount( $total );
1380
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1381
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1382
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1383
+                    $data['total']    = wpinv_round_amount($total);
1384 1384
                 }
1385 1385
             }
1386 1386
         }
1387 1387
         
1388
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1388
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1389 1389
 
1390
-        if ( isset( $data[$field] ) ) {
1391
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1390
+        if (isset($data[$field])) {
1391
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1392 1392
         }
1393 1393
         
1394 1394
         return $data;
1395 1395
     }
1396 1396
     
1397
-    public function get_final_tax( $currency = false ) {        
1398
-        $final_total = wpinv_round_amount( $this->tax );
1399
-        if ( $currency ) {
1400
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1397
+    public function get_final_tax($currency = false) {        
1398
+        $final_total = wpinv_round_amount($this->tax);
1399
+        if ($currency) {
1400
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1401 1401
         }
1402 1402
         
1403
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1403
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1404 1404
     }
1405 1405
     
1406
-    public function get_discounts( $array = false ) {
1406
+    public function get_discounts($array = false) {
1407 1407
         $discounts = $this->discounts;
1408
-        if ( $array && $discounts ) {
1409
-            $discounts = explode( ',', $discounts );
1408
+        if ($array && $discounts) {
1409
+            $discounts = explode(',', $discounts);
1410 1410
         }
1411
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1411
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1412 1412
     }
1413 1413
     
1414
-    public function get_discount( $currency = false, $dash = false ) {
1415
-        if ( !empty( $this->discounts ) ) {
1414
+    public function get_discount($currency = false, $dash = false) {
1415
+        if (!empty($this->discounts)) {
1416 1416
             global $ajax_cart_details;
1417 1417
             $ajax_cart_details = $this->get_cart_details();
1418 1418
             
1419
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1419
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1420 1420
                 $cart_items = $ajax_cart_details;
1421 1421
             } else {
1422 1422
                 $cart_items = $this->items;
1423 1423
             }
1424 1424
 
1425
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1425
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1426 1426
         }
1427
-        $discount   = wpinv_round_amount( $this->discount );
1427
+        $discount   = wpinv_round_amount($this->discount);
1428 1428
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1429 1429
         
1430
-        if ( $currency ) {
1431
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1430
+        if ($currency) {
1431
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1432 1432
         }
1433 1433
         
1434
-        $discount   = $dash . $discount;
1434
+        $discount = $dash . $discount;
1435 1435
         
1436
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1436
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1437 1437
     }
1438 1438
     
1439 1439
     public function get_discount_code() {
@@ -1445,49 +1445,49 @@  discard block
 block discarded – undo
1445 1445
         return (int) $this->disable_taxes === 0;
1446 1446
     }
1447 1447
 
1448
-    public function get_tax( $currency = false ) {
1449
-        $tax = wpinv_round_amount( $this->tax );
1448
+    public function get_tax($currency = false) {
1449
+        $tax = wpinv_round_amount($this->tax);
1450 1450
 
1451
-        if ( $currency ) {
1452
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1451
+        if ($currency) {
1452
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1453 1453
         }
1454 1454
 
1455
-        if ( ! $this->is_taxable() ) {
1456
-            $tax = wpinv_round_amount( 0.00 );
1455
+        if (!$this->is_taxable()) {
1456
+            $tax = wpinv_round_amount(0.00);
1457 1457
         }
1458 1458
 
1459
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1459
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1460 1460
     }
1461 1461
     
1462
-    public function get_fees( $type = 'all' ) {
1463
-        $fees    = array();
1462
+    public function get_fees($type = 'all') {
1463
+        $fees = array();
1464 1464
 
1465
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1466
-            foreach ( $this->fees as $fee ) {
1467
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1465
+        if (!empty($this->fees) && is_array($this->fees)) {
1466
+            foreach ($this->fees as $fee) {
1467
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1468 1468
                     continue;
1469 1469
                 }
1470 1470
 
1471
-                $fee['label'] = stripslashes( $fee['label'] );
1472
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1473
-                $fees[]    = $fee;
1471
+                $fee['label'] = stripslashes($fee['label']);
1472
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1473
+                $fees[] = $fee;
1474 1474
             }
1475 1475
         }
1476 1476
 
1477
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1477
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1478 1478
     }
1479 1479
     
1480
-    public function get_fees_total( $type = 'all' ) {
1480
+    public function get_fees_total($type = 'all') {
1481 1481
         $fees_total = (float) 0.00;
1482 1482
 
1483
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1484
-        if ( ! empty( $payment_fees ) ) {
1485
-            foreach ( $payment_fees as $fee ) {
1483
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1484
+        if (!empty($payment_fees)) {
1485
+            foreach ($payment_fees as $fee) {
1486 1486
                 $fees_total += (float) $fee['amount'];
1487 1487
             }
1488 1488
         }
1489 1489
 
1490
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1490
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1491 1491
         /*
1492 1492
         $fees = $this->get_fees( $type );
1493 1493
 
@@ -1507,116 +1507,116 @@  discard block
 block discarded – undo
1507 1507
     }
1508 1508
 
1509 1509
     public function get_user_id() {
1510
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1510
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1511 1511
     }
1512 1512
     
1513 1513
     public function get_first_name() {
1514
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1514
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1515 1515
     }
1516 1516
     
1517 1517
     public function get_last_name() {
1518
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1518
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1519 1519
     }
1520 1520
     
1521 1521
     public function get_user_full_name() {
1522
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1522
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1523 1523
     }
1524 1524
     
1525 1525
     public function get_user_info() {
1526
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1526
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1527 1527
     }
1528 1528
     
1529 1529
     public function get_email() {
1530
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1530
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1531 1531
     }
1532 1532
     
1533 1533
     public function get_address() {
1534
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1534
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1535 1535
     }
1536 1536
     
1537 1537
     public function get_phone() {
1538
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1538
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1539 1539
     }
1540 1540
     
1541 1541
     public function get_number() {
1542
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1542
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1543 1543
     }
1544 1544
     
1545 1545
     public function get_items() {
1546
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1546
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1547 1547
     }
1548 1548
     
1549 1549
     public function get_key() {
1550
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1550
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1551 1551
     }
1552 1552
     
1553 1553
     public function get_transaction_id() {
1554
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1554
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1555 1555
     }
1556 1556
     
1557 1557
     public function get_gateway() {
1558
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1558
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1559 1559
     }
1560 1560
     
1561 1561
     public function get_gateway_title() {
1562
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1562
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1563 1563
         
1564
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1564
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1565 1565
     }
1566 1566
     
1567 1567
     public function get_currency() {
1568
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1568
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1569 1569
     }
1570 1570
     
1571 1571
     public function get_created_date() {
1572
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1572
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1573 1573
     }
1574 1574
     
1575
-    public function get_due_date( $display = false ) {
1576
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1575
+    public function get_due_date($display = false) {
1576
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1577 1577
         
1578
-        if ( !$display || empty( $due_date ) ) {
1578
+        if (!$display || empty($due_date)) {
1579 1579
             return $due_date;
1580 1580
         }
1581 1581
         
1582
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1582
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1583 1583
     }
1584 1584
     
1585 1585
     public function get_completed_date() {
1586
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1586
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1587 1587
     }
1588 1588
     
1589
-    public function get_invoice_date( $formatted = true ) {
1589
+    public function get_invoice_date($formatted = true) {
1590 1590
         $date_completed = $this->completed_date;
1591 1591
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1592 1592
         
1593
-        if ( $invoice_date == '' ) {
1593
+        if ($invoice_date == '') {
1594 1594
             $date_created   = $this->date;
1595 1595
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1596 1596
         }
1597 1597
         
1598
-        if ( $formatted && $invoice_date ) {
1599
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1598
+        if ($formatted && $invoice_date) {
1599
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1600 1600
         }
1601 1601
 
1602
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1602
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1603 1603
     }
1604 1604
     
1605 1605
     public function get_ip() {
1606
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1606
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1607 1607
     }
1608 1608
         
1609
-    public function has_status( $status ) {
1610
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1609
+    public function has_status($status) {
1610
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1611 1611
     }
1612 1612
     
1613
-    public function add_item( $item_id = 0, $args = array() ) {
1613
+    public function add_item($item_id = 0, $args = array()) {
1614 1614
         global $wpi_current_id, $wpi_item_id;
1615 1615
         
1616
-        $item = new WPInv_Item( $item_id );
1616
+        $item = new WPInv_Item($item_id);
1617 1617
 
1618 1618
         // Bail if this post isn't a item
1619
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1619
+        if (!$item || $item->post_type !== 'wpi_item') {
1620 1620
             return false;
1621 1621
         }
1622 1622
         
@@ -1635,8 +1635,8 @@  discard block
 block discarded – undo
1635 1635
             'fees'          => array()
1636 1636
         );
1637 1637
 
1638
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1639
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1638
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1639
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1640 1640
 
1641 1641
         $wpi_current_id         = $this->ID;
1642 1642
         $wpi_item_id            = $item->ID;
@@ -1648,19 +1648,19 @@  discard block
 block discarded – undo
1648 1648
         $found_cart_key         = false;
1649 1649
         
1650 1650
         if ($has_quantities) {
1651
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1651
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1652 1652
             
1653
-            foreach ( $this->items as $key => $cart_item ) {
1654
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1653
+            foreach ($this->items as $key => $cart_item) {
1654
+                if ((int) $item_id !== (int) $cart_item['id']) {
1655 1655
                     continue;
1656 1656
                 }
1657 1657
 
1658
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1658
+                $this->items[$key]['quantity'] += $args['quantity'];
1659 1659
                 break;
1660 1660
             }
1661 1661
             
1662
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1663
-                if ( $item_id != $cart_item['id'] ) {
1662
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1663
+                if ($item_id != $cart_item['id']) {
1664 1664
                     continue;
1665 1665
                 }
1666 1666
 
@@ -1672,29 +1672,29 @@  discard block
 block discarded – undo
1672 1672
         if ($has_quantities && $found_cart_key !== false) {
1673 1673
             $cart_item          = $this->cart_details[$found_cart_key];
1674 1674
             $item_price         = $cart_item['item_price'];
1675
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1676
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1675
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1676
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1677 1677
             
1678 1678
             $new_quantity       = $quantity + $args['quantity'];
1679 1679
             $subtotal           = $item_price * $new_quantity;
1680 1680
             
1681 1681
             $args['quantity']   = $new_quantity;
1682
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1683
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1682
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1683
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1684 1684
             
1685
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1686
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1685
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1686
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1687 1687
             // The total increase equals the number removed * the item_price
1688
-            $total_increased    = wpinv_round_amount( $item_price );
1688
+            $total_increased    = wpinv_round_amount($item_price);
1689 1689
             
1690
-            if ( wpinv_prices_include_tax() ) {
1691
-                $subtotal -= wpinv_round_amount( $tax );
1690
+            if (wpinv_prices_include_tax()) {
1691
+                $subtotal -= wpinv_round_amount($tax);
1692 1692
             }
1693 1693
 
1694
-            $total              = $subtotal - $discount + $tax;
1694
+            $total = $subtotal - $discount + $tax;
1695 1695
 
1696 1696
             // Do not allow totals to go negative
1697
-            if( $total < 0 ) {
1697
+            if ($total < 0) {
1698 1698
                 $total = 0;
1699 1699
             }
1700 1700
             
@@ -1710,25 +1710,25 @@  discard block
 block discarded – undo
1710 1710
             $this->cart_details[$found_cart_key] = $cart_item;
1711 1711
         } else {
1712 1712
             // Set custom price.
1713
-            if ( $args['custom_price'] !== '' ) {
1713
+            if ($args['custom_price'] !== '') {
1714 1714
                 $item_price = $args['custom_price'];
1715 1715
             } else {
1716 1716
                 // Allow overriding the price
1717
-                if ( false !== $args['item_price'] ) {
1717
+                if (false !== $args['item_price']) {
1718 1718
                     $item_price = $args['item_price'];
1719 1719
                 } else {
1720
-                    $item_price = wpinv_get_item_price( $item->ID );
1720
+                    $item_price = wpinv_get_item_price($item->ID);
1721 1721
                 }
1722 1722
             }
1723 1723
 
1724 1724
             // Sanitizing the price here so we don't have a dozen calls later
1725
-            $item_price = wpinv_sanitize_amount( $item_price );
1726
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1725
+            $item_price = wpinv_sanitize_amount($item_price);
1726
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1727 1727
         
1728
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1729
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1730
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1731
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1728
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1729
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1730
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1731
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1732 1732
 
1733 1733
             // Setup the items meta item
1734 1734
             $new_item = array(
@@ -1736,29 +1736,29 @@  discard block
 block discarded – undo
1736 1736
                 'quantity' => $args['quantity'],
1737 1737
             );
1738 1738
 
1739
-            $this->items[]  = $new_item;
1739
+            $this->items[] = $new_item;
1740 1740
 
1741
-            if ( wpinv_prices_include_tax() ) {
1742
-                $subtotal -= wpinv_round_amount( $tax );
1741
+            if (wpinv_prices_include_tax()) {
1742
+                $subtotal -= wpinv_round_amount($tax);
1743 1743
             }
1744 1744
 
1745
-            $total      = $subtotal - $discount + $tax;
1745
+            $total = $subtotal - $discount + $tax;
1746 1746
 
1747 1747
             // Do not allow totals to go negative
1748
-            if( $total < 0 ) {
1748
+            if ($total < 0) {
1749 1749
                 $total = 0;
1750 1750
             }
1751 1751
         
1752 1752
             $this->cart_details[] = array(
1753 1753
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1754 1754
                 'id'            => $item->ID,
1755
-                'item_price'    => wpinv_round_amount( $item_price ),
1756
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1755
+                'item_price'    => wpinv_round_amount($item_price),
1756
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1757 1757
                 'quantity'      => $args['quantity'],
1758 1758
                 'discount'      => $discount,
1759
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1760
-                'tax'           => wpinv_round_amount( $tax ),
1761
-                'price'         => wpinv_round_amount( $total ),
1759
+                'subtotal'      => wpinv_round_amount($subtotal),
1760
+                'tax'           => wpinv_round_amount($tax),
1761
+                'price'         => wpinv_round_amount($total),
1762 1762
                 'vat_rate'      => $tax_rate,
1763 1763
                 'vat_class'     => $tax_class,
1764 1764
                 'meta'          => $args['meta'],
@@ -1768,18 +1768,18 @@  discard block
 block discarded – undo
1768 1768
             $subtotal = $subtotal - $discount;
1769 1769
         }
1770 1770
         
1771
-        $added_item = end( $this->cart_details );
1772
-        $added_item['action']  = 'add';
1771
+        $added_item = end($this->cart_details);
1772
+        $added_item['action'] = 'add';
1773 1773
         
1774 1774
         $this->pending['items'][] = $added_item;
1775 1775
         
1776
-        $this->increase_subtotal( $subtotal );
1777
-        $this->increase_tax( $tax );
1776
+        $this->increase_subtotal($subtotal);
1777
+        $this->increase_tax($tax);
1778 1778
 
1779 1779
         return true;
1780 1780
     }
1781 1781
     
1782
-    public function remove_item( $item_id, $args = array() ) {
1782
+    public function remove_item($item_id, $args = array()) {
1783 1783
         // Set some defaults
1784 1784
         $defaults = array(
1785 1785
             'quantity'      => 1,
@@ -1787,51 +1787,51 @@  discard block
 block discarded – undo
1787 1787
             'custom_price'  => '',
1788 1788
             'cart_index'    => false,
1789 1789
         );
1790
-        $args = wp_parse_args( $args, $defaults );
1790
+        $args = wp_parse_args($args, $defaults);
1791 1791
 
1792 1792
         // Bail if this post isn't a item
1793
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1793
+        if (get_post_type($item_id) !== 'wpi_item') {
1794 1794
             return false;
1795 1795
         }
1796 1796
         
1797
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1797
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1798 1798
 
1799
-        foreach ( $this->items as $key => $item ) {
1800
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1799
+        foreach ($this->items as $key => $item) {
1800
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1801 1801
                 continue;
1802 1802
             }
1803 1803
 
1804
-            if ( false !== $args['cart_index'] ) {
1805
-                $cart_index = absint( $args['cart_index'] );
1806
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1804
+            if (false !== $args['cart_index']) {
1805
+                $cart_index = absint($args['cart_index']);
1806
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1807 1807
 
1808
-                if ( ! empty( $cart_item ) ) {
1808
+                if (!empty($cart_item)) {
1809 1809
                     // If the cart index item isn't the same item ID, don't remove it
1810
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1810
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1811 1811
                         continue;
1812 1812
                     }
1813 1813
                 }
1814 1814
             }
1815 1815
 
1816
-            $item_quantity = $this->items[ $key ]['quantity'];
1817
-            if ( $item_quantity > $args['quantity'] ) {
1818
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1816
+            $item_quantity = $this->items[$key]['quantity'];
1817
+            if ($item_quantity > $args['quantity']) {
1818
+                $this->items[$key]['quantity'] -= $args['quantity'];
1819 1819
                 break;
1820 1820
             } else {
1821
-                unset( $this->items[ $key ] );
1821
+                unset($this->items[$key]);
1822 1822
                 break;
1823 1823
             }
1824 1824
         }
1825 1825
 
1826 1826
         $found_cart_key = false;
1827
-        if ( false === $args['cart_index'] ) {
1828
-            foreach ( $this->cart_details as $cart_key => $item ) {
1829
-                if ( $item_id != $item['id'] ) {
1827
+        if (false === $args['cart_index']) {
1828
+            foreach ($this->cart_details as $cart_key => $item) {
1829
+                if ($item_id != $item['id']) {
1830 1830
                     continue;
1831 1831
                 }
1832 1832
 
1833
-                if ( false !== $args['item_price'] ) {
1834
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1833
+                if (false !== $args['item_price']) {
1834
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
1835 1835
                         continue;
1836 1836
                     }
1837 1837
                 }
@@ -1840,13 +1840,13 @@  discard block
 block discarded – undo
1840 1840
                 break;
1841 1841
             }
1842 1842
         } else {
1843
-            $cart_index = absint( $args['cart_index'] );
1843
+            $cart_index = absint($args['cart_index']);
1844 1844
 
1845
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1845
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1846 1846
                 return false; // Invalid cart index passed.
1847 1847
             }
1848 1848
 
1849
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1849
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
1850 1850
                 return false; // We still need the proper Item ID to be sure.
1851 1851
             }
1852 1852
 
@@ -1854,41 +1854,41 @@  discard block
 block discarded – undo
1854 1854
         }
1855 1855
         
1856 1856
         $cart_item  = $this->cart_details[$found_cart_key];
1857
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1857
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1858 1858
         
1859
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1859
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1860 1860
             //return false; // Invoice must contain at least one item.
1861 1861
         }
1862 1862
         
1863
-        $discounts  = $this->get_discounts();
1863
+        $discounts = $this->get_discounts();
1864 1864
         
1865
-        if ( $quantity > $args['quantity'] ) {
1865
+        if ($quantity > $args['quantity']) {
1866 1866
             $item_price         = $cart_item['item_price'];
1867
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1867
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1868 1868
             
1869
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1869
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1870 1870
             $subtotal           = $item_price * $new_quantity;
1871 1871
             
1872 1872
             $args['quantity']   = $new_quantity;
1873
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1874
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1873
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1874
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1875 1875
             
1876
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1877
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1878
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1879
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1876
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
1877
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
1878
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
1879
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
1880 1880
             
1881 1881
             // The total increase equals the number removed * the item_price
1882
-            $total_decrease     = wpinv_round_amount( $item_price );
1882
+            $total_decrease     = wpinv_round_amount($item_price);
1883 1883
             
1884
-            if ( wpinv_prices_include_tax() ) {
1885
-                $subtotal -= wpinv_round_amount( $tax );
1884
+            if (wpinv_prices_include_tax()) {
1885
+                $subtotal -= wpinv_round_amount($tax);
1886 1886
             }
1887 1887
 
1888
-            $total              = $subtotal - $discount + $tax;
1888
+            $total = $subtotal - $discount + $tax;
1889 1889
 
1890 1890
             // Do not allow totals to go negative
1891
-            if( $total < 0 ) {
1891
+            if ($total < 0) {
1892 1892
                 $total = 0;
1893 1893
             }
1894 1894
             
@@ -1907,16 +1907,16 @@  discard block
 block discarded – undo
1907 1907
             
1908 1908
             $this->cart_details[$found_cart_key] = $cart_item;
1909 1909
             
1910
-            $remove_item = end( $this->cart_details );
1910
+            $remove_item = end($this->cart_details);
1911 1911
         } else {
1912 1912
             $item_price     = $cart_item['item_price'];
1913
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1914
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1913
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1914
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1915 1915
         
1916
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1916
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1917 1917
             $tax_decrease       = $tax;
1918 1918
 
1919
-            unset( $this->cart_details[$found_cart_key] );
1919
+            unset($this->cart_details[$found_cart_key]);
1920 1920
             
1921 1921
             $remove_item             = $args;
1922 1922
             $remove_item['id']       = $item_id;
@@ -1927,8 +1927,8 @@  discard block
 block discarded – undo
1927 1927
         $remove_item['action']      = 'remove';
1928 1928
         $this->pending['items'][]   = $remove_item;
1929 1929
                
1930
-        $this->decrease_subtotal( $subtotal_decrease );
1931
-        $this->decrease_tax( $tax_decrease );
1930
+        $this->decrease_subtotal($subtotal_decrease);
1931
+        $this->decrease_tax($tax_decrease);
1932 1932
         
1933 1933
         return true;
1934 1934
     }
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
     public function update_items($temp = false) {
1937 1937
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1938 1938
         
1939
-        if ( !empty( $this->cart_details ) ) {
1939
+        if (!empty($this->cart_details)) {
1940 1940
             $wpi_nosave             = $temp;
1941 1941
             $cart_subtotal          = 0;
1942 1942
             $cart_discount          = 0;
@@ -1946,65 +1946,65 @@  discard block
 block discarded – undo
1946 1946
             $_POST['wpinv_country'] = $this->country;
1947 1947
             $_POST['wpinv_state']   = $this->state;
1948 1948
 
1949
-            foreach ( $this->cart_details as $key => $item ) {
1949
+            foreach ($this->cart_details as $key => $item) {
1950 1950
                 $item_price = $item['item_price'];
1951
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1952
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1951
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1952
+                $amount     = wpinv_round_amount($item_price * $quantity);
1953 1953
                 $subtotal   = $item_price * $quantity;
1954 1954
                 
1955 1955
                 $wpi_current_id         = $this->ID;
1956 1956
                 $wpi_item_id            = $item['id'];
1957 1957
                 
1958
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1958
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1959 1959
                 
1960
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1961
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1962
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1960
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1961
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1962
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1963 1963
 
1964
-                if ( ! $this->is_taxable() ) {
1964
+                if (!$this->is_taxable()) {
1965 1965
                     $tax = 0;
1966 1966
                 }
1967 1967
 
1968
-                if ( wpinv_prices_include_tax() ) {
1969
-                    $subtotal -= wpinv_round_amount( $tax );
1968
+                if (wpinv_prices_include_tax()) {
1969
+                    $subtotal -= wpinv_round_amount($tax);
1970 1970
                 }
1971 1971
 
1972
-                $total      = $subtotal - $discount + $tax;
1972
+                $total = $subtotal - $discount + $tax;
1973 1973
 
1974 1974
                 // Do not allow totals to go negative
1975
-                if( $total < 0 ) {
1975
+                if ($total < 0) {
1976 1976
                     $total = 0;
1977 1977
                 }
1978 1978
 
1979 1979
                 $cart_details[] = array(
1980 1980
                     'id'          => $item['id'],
1981 1981
                     'name'        => $item['name'],
1982
-                    'item_price'  => wpinv_round_amount( $item_price ),
1983
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1982
+                    'item_price'  => wpinv_round_amount($item_price),
1983
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1984 1984
                     'quantity'    => $quantity,
1985 1985
                     'discount'    => $discount,
1986
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1987
-                    'tax'         => wpinv_round_amount( $tax ),
1988
-                    'price'       => wpinv_round_amount( $total ),
1986
+                    'subtotal'    => wpinv_round_amount($subtotal),
1987
+                    'tax'         => wpinv_round_amount($tax),
1988
+                    'price'       => wpinv_round_amount($total),
1989 1989
                     'vat_rate'    => $tax_rate,
1990 1990
                     'vat_class'   => $tax_class,
1991 1991
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
1992 1992
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
1993 1993
                 );
1994 1994
 
1995
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
1996
-                $cart_discount  += (float)($discount);
1997
-                $cart_tax       += (float)($tax);
1995
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
1996
+                $cart_discount  += (float) ($discount);
1997
+                $cart_tax       += (float) ($tax);
1998 1998
             }
1999
-            if ( $cart_subtotal < 0 ) {
1999
+            if ($cart_subtotal < 0) {
2000 2000
                 $cart_subtotal = 0;
2001 2001
             }
2002
-            if ( $cart_tax < 0 ) {
2002
+            if ($cart_tax < 0) {
2003 2003
                 $cart_tax = 0;
2004 2004
             }
2005
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
2006
-            $this->tax      = wpinv_round_amount( $cart_tax );
2007
-            $this->discount = wpinv_round_amount( $cart_discount );
2005
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
2006
+            $this->tax      = wpinv_round_amount($cart_tax);
2007
+            $this->discount = wpinv_round_amount($cart_discount);
2008 2008
             
2009 2009
             $this->recalculate_total();
2010 2010
             
@@ -2016,177 +2016,177 @@  discard block
 block discarded – undo
2016 2016
     
2017 2017
     public function recalculate_totals($temp = false) {        
2018 2018
         $this->update_items($temp);
2019
-        $this->save( true );
2019
+        $this->save(true);
2020 2020
         
2021 2021
         return $this;
2022 2022
     }
2023 2023
     
2024 2024
     public function needs_payment() {
2025
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
2025
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
2026 2026
 
2027
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
2027
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
2028 2028
             $needs_payment = true;
2029 2029
         } else {
2030 2030
             $needs_payment = false;
2031 2031
         }
2032 2032
 
2033
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2033
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2034 2034
     }
2035 2035
     
2036
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2036
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2037 2037
         $pay_url = wpinv_get_checkout_uri();
2038 2038
 
2039
-        if ( is_ssl() ) {
2040
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2039
+        if (is_ssl()) {
2040
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2041 2041
         }
2042 2042
         
2043 2043
         $key = $this->get_key();
2044 2044
 
2045
-        if ( $with_key ) {
2046
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2045
+        if ($with_key) {
2046
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2047 2047
         } else {
2048
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2048
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2049 2049
         }
2050 2050
         
2051
-        if ( $secret ) {
2052
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2051
+        if ($secret) {
2052
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2053 2053
         }
2054 2054
 
2055
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2055
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2056 2056
     }
2057 2057
     
2058
-    public function get_view_url( $with_key = false ) {
2059
-        $invoice_url = get_permalink( $this->ID );
2058
+    public function get_view_url($with_key = false) {
2059
+        $invoice_url = get_permalink($this->ID);
2060 2060
 
2061
-        if ( $with_key ) {
2062
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2061
+        if ($with_key) {
2062
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2063 2063
         }
2064 2064
 
2065
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2065
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2066 2066
     }
2067 2067
     
2068
-    public function generate_key( $string = '' ) {
2069
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2070
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2068
+    public function generate_key($string = '') {
2069
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2070
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2071 2071
     }
2072 2072
     
2073 2073
     public function is_recurring() {
2074
-        if ( empty( $this->cart_details ) ) {
2074
+        if (empty($this->cart_details)) {
2075 2075
             return false;
2076 2076
         }
2077 2077
         
2078 2078
         $has_subscription = false;
2079
-        foreach( $this->cart_details as $cart_item ) {
2080
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2079
+        foreach ($this->cart_details as $cart_item) {
2080
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2081 2081
                 $has_subscription = true;
2082 2082
                 break;
2083 2083
             }
2084 2084
         }
2085 2085
         
2086
-        if ( count( $this->cart_details ) > 1 ) {
2086
+        if (count($this->cart_details) > 1) {
2087 2087
             $has_subscription = false;
2088 2088
         }
2089 2089
 
2090
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2090
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2091 2091
     }
2092 2092
 
2093 2093
     public function is_free_trial() {
2094 2094
         $is_free_trial = false;
2095 2095
         
2096
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2097
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2096
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2097
+            if (!empty($item) && $item->has_free_trial()) {
2098 2098
                 $is_free_trial = true;
2099 2099
             }
2100 2100
         }
2101 2101
 
2102
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this );
2102
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this);
2103 2103
     }
2104 2104
 
2105 2105
     public function is_initial_free() {
2106 2106
         $is_initial_free = false;
2107 2107
         
2108
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2108
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2109 2109
             $is_initial_free = true;
2110 2110
         }
2111 2111
 
2112
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2112
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2113 2113
     }
2114 2114
     
2115
-    public function get_recurring( $object = false ) {
2115
+    public function get_recurring($object = false) {
2116 2116
         $item = NULL;
2117 2117
         
2118
-        if ( empty( $this->cart_details ) ) {
2118
+        if (empty($this->cart_details)) {
2119 2119
             return $item;
2120 2120
         }
2121 2121
         
2122
-        foreach( $this->cart_details as $cart_item ) {
2123
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2122
+        foreach ($this->cart_details as $cart_item) {
2123
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2124 2124
                 $item = $cart_item['id'];
2125 2125
                 break;
2126 2126
             }
2127 2127
         }
2128 2128
         
2129
-        if ( $object ) {
2130
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2129
+        if ($object) {
2130
+            $item = $item ? new WPInv_Item($item) : NULL;
2131 2131
             
2132
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2132
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2133 2133
         }
2134 2134
 
2135
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2135
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2136 2136
     }
2137 2137
     
2138 2138
     public function get_subscription_name() {
2139
-        $item = $this->get_recurring( true );
2139
+        $item = $this->get_recurring(true);
2140 2140
         
2141
-        if ( empty( $item ) ) {
2141
+        if (empty($item)) {
2142 2142
             return NULL;
2143 2143
         }
2144 2144
         
2145
-        if ( !($name = $item->get_name()) ) {
2145
+        if (!($name = $item->get_name())) {
2146 2146
             $name = $item->post_name;
2147 2147
         }
2148 2148
 
2149
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2149
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2150 2150
     }
2151 2151
     
2152 2152
     public function get_subscription_id() {
2153
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2153
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2154 2154
         
2155
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2156
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2155
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2156
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2157 2157
             
2158
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2158
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2159 2159
         }
2160 2160
         
2161 2161
         return $subscription_id;
2162 2162
     }
2163 2163
     
2164 2164
     public function is_parent() {
2165
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2165
+        $is_parent = empty($this->parent_invoice) ? true : false;
2166 2166
 
2167
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2167
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2168 2168
     }
2169 2169
     
2170 2170
     public function is_renewal() {
2171 2171
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2172 2172
 
2173
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2173
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2174 2174
     }
2175 2175
     
2176 2176
     public function get_parent_payment() {
2177 2177
         $parent_payment = NULL;
2178 2178
         
2179
-        if ( $this->is_renewal() ) {
2180
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2179
+        if ($this->is_renewal()) {
2180
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2181 2181
         }
2182 2182
         
2183 2183
         return $parent_payment;
2184 2184
     }
2185 2185
     
2186 2186
     public function is_paid() {
2187
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2187
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2188 2188
 
2189
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2189
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2190 2190
     }
2191 2191
 
2192 2192
     /**
@@ -2199,23 +2199,23 @@  discard block
 block discarded – undo
2199 2199
     }
2200 2200
     
2201 2201
     public function is_refunded() {
2202
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2202
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2203 2203
 
2204
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2204
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2205 2205
     }
2206 2206
     
2207 2207
     public function is_free() {
2208 2208
         $is_free = false;
2209 2209
         
2210
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2211
-            if ( $this->is_parent() && $this->is_recurring() ) {
2212
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2210
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2211
+            if ($this->is_parent() && $this->is_recurring()) {
2212
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2213 2213
             } else {
2214 2214
                 $is_free = true;
2215 2215
             }
2216 2216
         }
2217 2217
         
2218
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2218
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2219 2219
     }
2220 2220
     
2221 2221
     public function has_vat() {
@@ -2223,41 +2223,41 @@  discard block
 block discarded – undo
2223 2223
         
2224 2224
         $requires_vat = false;
2225 2225
         
2226
-        if ( $this->country ) {
2226
+        if ($this->country) {
2227 2227
             $wpi_country        = $this->country;
2228 2228
             
2229
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2229
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2230 2230
         }
2231 2231
         
2232
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2232
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2233 2233
     }
2234 2234
     
2235 2235
     public function refresh_item_ids() {
2236 2236
         $item_ids = array();
2237 2237
         
2238
-        if ( !empty( $this->cart_details ) ) {
2239
-            foreach ( $this->cart_details as $key => $item ) {
2240
-                if ( !empty( $item['id'] ) ) {
2238
+        if (!empty($this->cart_details)) {
2239
+            foreach ($this->cart_details as $key => $item) {
2240
+                if (!empty($item['id'])) {
2241 2241
                     $item_ids[] = $item['id'];
2242 2242
                 }
2243 2243
             }
2244 2244
         }
2245 2245
         
2246
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2246
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2247 2247
         
2248
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2248
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2249 2249
     }
2250 2250
     
2251
-    public function get_invoice_quote_type( $post_id ) {
2252
-        if ( empty( $post_id ) ) {
2251
+    public function get_invoice_quote_type($post_id) {
2252
+        if (empty($post_id)) {
2253 2253
             return '';
2254 2254
         }
2255 2255
 
2256
-        $type = get_post_type( $post_id );
2256
+        $type = get_post_type($post_id);
2257 2257
 
2258
-        if ( 'wpi_invoice' === $type ) {
2258
+        if ('wpi_invoice' === $type) {
2259 2259
             $post_type = __('Invoice', 'invoicing');
2260
-        } else{
2260
+        } else {
2261 2261
             $post_type = __('Quote', 'invoicing');
2262 2262
         }
2263 2263
 
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +725 added lines, -725 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,137 +17,137 @@  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
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
90
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
91 91
             self::load_vat_scripts();
92 92
         }
93 93
     }
94 94
 
95
-    public static function load_vat_scripts(){
96
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95
+    public static function load_vat_scripts() {
96
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
97 97
 
98
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
99
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
98
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
99
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
100 100
 
101
-        $vat_name   = self::get_vat_name();
101
+        $vat_name = self::get_vat_name();
102 102
 
103 103
         $vars = array();
104 104
         $vars['UseTaxes'] = wpinv_use_taxes();
105 105
         $vars['EUStates'] = self::get_eu_states();
106
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
107
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
108
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
109
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
110
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
111
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
112
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
113
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
106
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
107
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
108
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
109
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
110
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
111
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
112
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
113
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
114 114
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
115 115
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
116
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
117
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
118
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
119
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
120
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
121
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
122
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
123
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
124
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
125
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
126
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
127
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
128
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
116
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
117
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
118
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
119
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
120
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
121
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
122
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
123
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
124
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
125
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
126
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
127
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
128
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
129 129
         $vars['isFront'] = is_admin() ? false : true;
130 130
         $vars['baseCountry'] = wpinv_get_default_country();
131
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
132
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
131
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
132
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
133 133
 
134
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
135
-        wp_enqueue_script( 'wpinv-vat-script' );
136
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
134
+        wp_enqueue_script('wpinv-vat-validation-script');
135
+        wp_enqueue_script('wpinv-vat-script');
136
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
137 137
     }
138 138
 
139 139
     public static function enqueue_admin_scripts() {
140
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
140
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
141 141
             self::load_vat_scripts();
142 142
         }
143 143
     }
144 144
     
145
-    public static function section_vat_settings( $sections ) {
146
-        if ( !empty( $sections ) ) {
147
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
145
+    public static function section_vat_settings($sections) {
146
+        if (!empty($sections)) {
147
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
148 148
             
149
-            if ( self::allow_vat_classes() ) {
150
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
149
+            if (self::allow_vat_classes()) {
150
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
151 151
             }
152 152
         }
153 153
         return $sections;
@@ -156,52 +156,52 @@  discard block
 block discarded – undo
156 156
     public static function vat_rates_settings() {
157 157
         $vat_classes = self::get_rate_classes();
158 158
         $vat_rates = array();
159
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
160
-        $current_url = remove_query_arg( 'wpi_sub' );
159
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
160
+        $current_url = remove_query_arg('wpi_sub');
161 161
         
162 162
         $vat_rates['vat_rates_header'] = array(
163 163
             'id' => 'vat_rates_header',
164
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
164
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
165 165
             'desc' => '',
166 166
             'type' => 'header',
167 167
             'size' => 'regular'
168 168
         );
169 169
         $vat_rates['vat_rates_class'] = array(
170 170
             'id'          => 'vat_rates_class',
171
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
172
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
171
+            'name'        => __('Edit VAT Rates', 'invoicing'),
172
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
173 173
             'type'        => 'select',
174
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
175
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
174
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
175
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
176 176
             'selected'    => $vat_class,
177 177
             'class'       => 'wpi_select2',
178 178
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
179 179
         );
180 180
         
181
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
181
+        if ($vat_class != '_standard' && $vat_class != '_new') {
182 182
             $vat_rates['vat_rate_delete'] = array(
183 183
                 'id'   => 'vat_rate_delete',
184 184
                 'type' => 'vat_rate_delete',
185 185
             );
186 186
         }
187 187
                     
188
-        if ( $vat_class == '_new' ) {
188
+        if ($vat_class == '_new') {
189 189
             $vat_rates['vat_rates_settings'] = array(
190 190
                 'id' => 'vat_rates_settings',
191
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
191
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
192 192
                 'type' => 'header',
193 193
             );
194 194
             $vat_rates['vat_rate_name'] = array(
195 195
                 'id'   => 'vat_rate_name',
196
-                'name' => __( 'Name', 'invoicing' ),
197
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
196
+                'name' => __('Name', 'invoicing'),
197
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
198 198
                 'type' => 'text',
199 199
                 'size' => 'regular',
200 200
             );
201 201
             $vat_rates['vat_rate_desc'] = array(
202 202
                 'id'   => 'vat_rate_desc',
203
-                'name' => __( 'Description', 'invoicing' ),
204
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
203
+                'name' => __('Description', 'invoicing'),
204
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
205 205
                 'type' => 'text',
206 206
                 'size' => 'regular',
207 207
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             $vat_rates['vat_rates'] = array(
214 214
                 'id'   => 'vat_rates',
215 215
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
216
-                'desc' => self::get_class_desc( $vat_class ),
216
+                'desc' => self::get_class_desc($vat_class),
217 217
                 'type' => 'vat_rates',
218 218
             );
219 219
         }
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
         return $vat_rates;
222 222
     }
223 223
     
224
-    public static function vat_settings( $settings ) {
225
-        if ( !empty( $settings ) ) {    
224
+    public static function vat_settings($settings) {
225
+        if (!empty($settings)) {    
226 226
             $vat_settings = array();
227 227
             $vat_settings['vat_company_title'] = array(
228 228
                 'id' => 'vat_company_title',
229
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
229
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
230 230
                 'desc' => '',
231 231
                 'type' => 'header',
232 232
                 'size' => 'regular'
@@ -234,22 +234,22 @@  discard block
 block discarded – undo
234 234
             
235 235
             $vat_settings['vat_company_name'] = array(
236 236
                 'id' => 'vat_company_name',
237
-                'name' => __( 'Your Company Name', 'invoicing' ),
238
-                '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>' ),
237
+                'name' => __('Your Company Name', 'invoicing'),
238
+                '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>'),
239 239
                 'type' => 'text',
240 240
                 'size' => 'regular',
241 241
             );
242 242
             
243 243
             $vat_settings['vat_number'] = array(
244 244
                 'id'   => 'vat_number',
245
-                'name' => __( 'Your VAT Number', 'invoicing' ),
245
+                'name' => __('Your VAT Number', 'invoicing'),
246 246
                 'type' => 'vat_number',
247 247
                 'size' => 'regular',
248 248
             );
249 249
 
250 250
             $vat_settings['vat_settings_title'] = array(
251 251
                 'id' => 'vat_settings_title',
252
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
252
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
253 253
                 'desc' => '',
254 254
                 'type' => 'header',
255 255
                 'size' => 'regular'
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 
258 258
             $vat_settings['apply_vat_rules'] = array(
259 259
                 'id' => 'apply_vat_rules',
260
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
261
-                '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>',
260
+                'name' => __('Enable VAT Rules', 'invoicing'),
261
+                '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>',
262 262
                 'type' => 'checkbox',
263 263
                 'std' => '1'
264 264
             );
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 
275 275
             $vat_settings['vat_prevent_b2c_purchase'] = array(
276 276
                 'id' => 'vat_prevent_b2c_purchase',
277
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
278
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
277
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
278
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
279 279
                 'type' => 'checkbox'
280 280
             );
281 281
 
@@ -283,22 +283,22 @@  discard block
 block discarded – undo
283 283
 
284 284
             $vat_settings['vat_same_country_rule'] = array(
285 285
                 'id'          => 'vat_same_country_rule',
286
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
287
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
286
+                'name'        => __('Same Country Rule', 'invoicing'),
287
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
288 288
                 'type'        => 'select',
289 289
                 'options'     => array(
290
-                    ''          => __( 'Normal', 'invoicing' ),
291
-                    'no'        => __( 'No VAT', 'invoicing' ),
292
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
290
+                    ''          => __('Normal', 'invoicing'),
291
+                    'no'        => __('No VAT', 'invoicing'),
292
+                    'always'    => __('Always apply VAT', 'invoicing'),
293 293
                 ),
294
-                'placeholder' => __( 'Select an option', 'invoicing' ),
294
+                'placeholder' => __('Select an option', 'invoicing'),
295 295
                 'std'         => '',
296 296
                 'class'   => 'wpi_select2',
297 297
             );
298 298
 
299 299
             $vat_settings['vat_checkout_title'] = array(
300 300
                 'id' => 'vat_checkout_title',
301
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
301
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
302 302
                 'desc' => '',
303 303
                 'type' => 'header',
304 304
                 'size' => 'regular'
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 
307 307
             $vat_settings['vat_disable_fields'] = array(
308 308
                 'id' => 'vat_disable_fields',
309
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
310
-                '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>',
309
+                'name' => __('Disable VAT Fields', 'invoicing'),
310
+                '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>',
311 311
                 'type' => 'checkbox'
312 312
             );
313 313
 
314 314
             $vat_settings['vat_ip_lookup'] = array(
315 315
                 'id'   => 'vat_ip_lookup',
316
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
316
+                'name' => __('IP Country Look-up', 'invoicing'),
317 317
                 'type' => 'vat_ip_lookup',
318 318
                 'size' => 'regular',
319 319
                 'std' => 'default',
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 
323 323
             $vat_settings['hide_ip_address'] = array(
324 324
                 'id' => 'hide_ip_address',
325
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
326
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
325
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
326
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vat_ip_country_default'] = array(
331 331
                 'id' => 'vat_ip_country_default',
332
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
333
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
332
+                'name' => __('Enable IP Country as Default', 'invoicing'),
333
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
334 334
                 'type' => 'checkbox'
335 335
             );
336 336
 
337 337
             $vat_settings['vies_validation_title'] = array(
338 338
                 'id' => 'vies_validation_title',
339
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
339
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
340 340
                 'desc' => '',
341 341
                 'type' => 'header',
342 342
                 'size' => 'regular'
@@ -344,37 +344,37 @@  discard block
 block discarded – undo
344 344
 
345 345
             $vat_settings['vat_vies_check'] = array(
346 346
                 'id' => 'vat_vies_check',
347
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
348
-                '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>' ),
347
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
348
+                '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>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_disable_company_name_check'] = array(
353 353
                 'id' => 'vat_disable_company_name_check',
354
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
355
-                '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>' ),
354
+                'name' => __('Disable VIES Name Check', 'invoicing'),
355
+                '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>'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
 
359 359
             $vat_settings['vat_offline_check'] = array(
360 360
                 'id' => 'vat_offline_check',
361
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
362
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
361
+                'name' => __('Disable Basic Checks', 'invoicing'),
362
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
363 363
                 'type' => 'checkbox'
364 364
             );
365 365
             
366 366
 
367 367
             $settings['vat'] = $vat_settings;
368 368
             
369
-            if ( self::allow_vat_classes() ) {
369
+            if (self::allow_vat_classes()) {
370 370
                 $settings['vat_rates'] = self::vat_rates_settings();
371 371
             }
372 372
             
373 373
             $eu_fallback_rate = array(
374 374
                 'id'   => 'eu_fallback_rate',
375
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
375
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
376 376
                 'type' => 'eu_fallback_rate',
377
-                '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' ),
377
+                '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'),
378 378
                 'std'  => '20',
379 379
                 'size' => 'small'
380 380
             );
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
391 391
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
392 392
         
393
-        if ( !is_dir( $destination_dir ) ) { 
394
-            mkdir( $destination_dir );
393
+        if (!is_dir($destination_dir)) { 
394
+            mkdir($destination_dir);
395 395
         }
396 396
         
397
-        $database_files     = array(
397
+        $database_files = array(
398 398
             'country'   => array(
399 399
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
400 400
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -405,57 +405,57 @@  discard block
 block discarded – undo
405 405
             )
406 406
         );
407 407
 
408
-        foreach( $database_files as $database => $files ) {
409
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
408
+        foreach ($database_files as $database => $files) {
409
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
410 410
             
411
-            if ( empty( $result['success'] ) ) {
411
+            if (empty($result['success'])) {
412 412
                 echo $result['message'];
413 413
                 exit;
414 414
             }
415 415
             
416
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
417
-            echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
416
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
417
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
418 418
         }
419 419
         
420 420
         exit;
421 421
     }
422 422
     
423
-    public static function geoip2_download_file( $source_url, $destination_file ) {
423
+    public static function geoip2_download_file($source_url, $destination_file) {
424 424
         $success    = false;
425 425
         $message    = '';
426 426
         
427
-        if ( !function_exists( 'download_url' ) ) {
428
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
427
+        if (!function_exists('download_url')) {
428
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
429 429
         }
430 430
 
431
-        $temp_file  = download_url( $source_url );
431
+        $temp_file = download_url($source_url);
432 432
         
433
-        if ( is_wp_error( $temp_file ) ) {
434
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
433
+        if (is_wp_error($temp_file)) {
434
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
435 435
         } else {
436
-            $handle = gzopen( $temp_file, 'rb' );
436
+            $handle = gzopen($temp_file, 'rb');
437 437
             
438
-            if ( $handle ) {
439
-                $fopen  = fopen( $destination_file, 'wb' );
440
-                if ( $fopen ) {
441
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
442
-                        fwrite( $fopen, $data );
438
+            if ($handle) {
439
+                $fopen = fopen($destination_file, 'wb');
440
+                if ($fopen) {
441
+                    while (($data = gzread($handle, 4096)) != false) {
442
+                        fwrite($fopen, $data);
443 443
                     }
444 444
 
445
-                    gzclose( $handle );
446
-                    fclose( $fopen );
445
+                    gzclose($handle);
446
+                    fclose($fopen);
447 447
                         
448 448
                     $success = true;
449 449
                 } else {
450
-                    gzclose( $handle );
451
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
450
+                    gzclose($handle);
451
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
452 452
                 }
453 453
             } else {
454
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
454
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
455 455
             }
456 456
             
457
-            if ( file_exists( $temp_file ) ) {
458
-                unlink( $temp_file );
457
+            if (file_exists($temp_file)) {
458
+                unlink($temp_file);
459 459
             }
460 460
         }
461 461
         
@@ -467,11 +467,11 @@  discard block
 block discarded – undo
467 467
     }
468 468
     
469 469
     public static function load_geoip2() {
470
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
470
+        if (defined('WPINV_GEOIP2_LODDED')) {
471 471
             return;
472 472
         }
473 473
         
474
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
474
+        if (!class_exists('\MaxMind\Db\Reader')) {
475 475
             $maxmind_db_files = array(
476 476
                 'Reader/Decoder.php',
477 477
                 'Reader/InvalidDatabaseException.php',
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
                 'Reader.php',
481 481
             );
482 482
             
483
-            foreach ( $maxmind_db_files as $key => $file ) {
484
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
483
+            foreach ($maxmind_db_files as $key => $file) {
484
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
485 485
             }
486 486
         }
487 487
         
488
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
488
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
489 489
             $geoip2_files = array(
490 490
                 'ProviderInterface.php',
491 491
                 'Compat/JsonSerializable.php',
@@ -519,23 +519,23 @@  discard block
 block discarded – undo
519 519
                 'WebService/Client.php',
520 520
             );
521 521
             
522
-            foreach ( $geoip2_files as $key => $file ) {
523
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
522
+            foreach ($geoip2_files as $key => $file) {
523
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
524 524
             }
525 525
         }
526 526
 
527
-        define( 'WPINV_GEOIP2_LODDED', true );
527
+        define('WPINV_GEOIP2_LODDED', true);
528 528
     }
529 529
 
530 530
     public static function geoip2_country_dbfile() {
531 531
         $upload_dir = wp_upload_dir();
532 532
 
533
-        if ( !isset( $upload_dir['basedir'] ) ) {
533
+        if (!isset($upload_dir['basedir'])) {
534 534
             return false;
535 535
         }
536 536
 
537 537
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
538
-        if ( !file_exists( $filename ) ) {
538
+        if (!file_exists($filename)) {
539 539
             return false;
540 540
         }
541 541
         
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
     public static function geoip2_city_dbfile() {
546 546
         $upload_dir = wp_upload_dir();
547 547
 
548
-        if ( !isset( $upload_dir['basedir'] ) ) {
548
+        if (!isset($upload_dir['basedir'])) {
549 549
             return false;
550 550
         }
551 551
 
552 552
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
553
-        if ( !file_exists( $filename ) ) {
553
+        if (!file_exists($filename)) {
554 554
             return false;
555 555
         }
556 556
         
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
         try {
562 562
             self::load_geoip2();
563 563
 
564
-            if ( $filename = self::geoip2_country_dbfile() ) {
565
-                return new \GeoIp2\Database\Reader( $filename );
564
+            if ($filename = self::geoip2_country_dbfile()) {
565
+                return new \GeoIp2\Database\Reader($filename);
566 566
             }
567
-        } catch( Exception $e ) {
567
+        } catch (Exception $e) {
568 568
             return false;
569 569
         }
570 570
         
@@ -575,183 +575,183 @@  discard block
 block discarded – undo
575 575
         try {
576 576
             self::load_geoip2();
577 577
 
578
-            if ( $filename = self::geoip2_city_dbfile() ) {
579
-                return new \GeoIp2\Database\Reader( $filename );
578
+            if ($filename = self::geoip2_city_dbfile()) {
579
+                return new \GeoIp2\Database\Reader($filename);
580 580
             }
581
-        } catch( Exception $e ) {
581
+        } catch (Exception $e) {
582 582
             return false;
583 583
         }
584 584
         
585 585
         return false;
586 586
     }
587 587
 
588
-    public static function geoip2_country_record( $ip_address ) {
588
+    public static function geoip2_country_record($ip_address) {
589 589
         try {
590 590
             $reader = self::geoip2_country_reader();
591 591
 
592
-            if ( $reader ) {
593
-                $record = $reader->country( $ip_address );
592
+            if ($reader) {
593
+                $record = $reader->country($ip_address);
594 594
                 
595
-                if ( !empty( $record->country->isoCode ) ) {
595
+                if (!empty($record->country->isoCode)) {
596 596
                     return $record;
597 597
                 }
598 598
             }
599
-        } catch(\InvalidArgumentException $e) {
600
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
599
+        } catch (\InvalidArgumentException $e) {
600
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
601 601
             
602 602
             return false;
603
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
604
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
603
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
604
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
605 605
             
606 606
             return false;
607
-        } catch( Exception $e ) {
607
+        } catch (Exception $e) {
608 608
             return false;
609 609
         }
610 610
         
611 611
         return false;
612 612
     }
613 613
 
614
-    public static function geoip2_city_record( $ip_address ) {
614
+    public static function geoip2_city_record($ip_address) {
615 615
         try {
616 616
             $reader = self::geoip2_city_reader();
617 617
 
618
-            if ( $reader ) {
619
-                $record = $reader->city( $ip_address );
618
+            if ($reader) {
619
+                $record = $reader->city($ip_address);
620 620
                 
621
-                if ( !empty( $record->country->isoCode ) ) {
621
+                if (!empty($record->country->isoCode)) {
622 622
                     return $record;
623 623
                 }
624 624
             }
625
-        } catch(\InvalidArgumentException $e) {
626
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
625
+        } catch (\InvalidArgumentException $e) {
626
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
627 627
             
628 628
             return false;
629
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
630
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
629
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
630
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
631 631
             
632 632
             return false;
633
-        } catch( Exception $e ) {
633
+        } catch (Exception $e) {
634 634
             return false;
635 635
         }
636 636
         
637 637
         return false;
638 638
     }
639 639
 
640
-    public static function geoip2_country_code( $ip_address ) {
641
-        $record = self::geoip2_country_record( $ip_address );
642
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
640
+    public static function geoip2_country_code($ip_address) {
641
+        $record = self::geoip2_country_record($ip_address);
642
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
643 643
     }
644 644
 
645 645
     // Find country by IP address.
646
-    public static function get_country_by_ip( $ip = '' ) {
646
+    public static function get_country_by_ip($ip = '') {
647 647
         global $wpinv_ip_address_country;
648 648
         
649
-        if ( !empty( $wpinv_ip_address_country ) ) {
649
+        if (!empty($wpinv_ip_address_country)) {
650 650
             return $wpinv_ip_address_country;
651 651
         }
652 652
         
653
-        if ( empty( $ip ) ) {
653
+        if (empty($ip)) {
654 654
             $ip = wpinv_get_ip();
655 655
         }
656 656
 
657
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
658
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
657
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
658
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
659 659
 
660
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
661
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
660
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
661
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
662 662
                 try {
663
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
664
-                } catch( Exception $e ) {
665
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
663
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
664
+                } catch (Exception $e) {
665
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
666 666
                 }
667
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
668
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
669
-            } else if ( function_exists( 'simplexml_load_file' ) && ini_get('allow_url_fopen') && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
670
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
667
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
668
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
669
+            } else if (function_exists('simplexml_load_file') && ini_get('allow_url_fopen') && ($ip_country_service === 'geoplugin' || $is_default)) {
670
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
671 671
                 
672
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
673
-                    $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
672
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
673
+                    $wpinv_ip_address_country = (string) $load_xml->geoplugin_countryCode;
674 674
                 }
675
-            }elseif(!empty( $ip )){
675
+            }elseif (!empty($ip)) {
676 676
                 $url = 'http://ip-api.com/json/' . $ip;
677 677
                 $response = wp_remote_get($url);
678 678
 
679
-                if ( is_array( $response ) && wp_remote_retrieve_response_code( $response ) == '200' ) {
680
-                    $data = json_decode(wp_remote_retrieve_body( $response ),true);
681
-                    if(!empty($data['countryCode'])){
682
-                        $wpinv_ip_address_country = (string)$data['countryCode'];
679
+                if (is_array($response) && wp_remote_retrieve_response_code($response) == '200') {
680
+                    $data = json_decode(wp_remote_retrieve_body($response), true);
681
+                    if (!empty($data['countryCode'])) {
682
+                        $wpinv_ip_address_country = (string) $data['countryCode'];
683 683
                     }
684 684
                 }
685 685
             }
686 686
         }
687 687
 
688
-        if ( empty( $wpinv_ip_address_country ) ) {
688
+        if (empty($wpinv_ip_address_country)) {
689 689
             $wpinv_ip_address_country = wpinv_get_default_country();
690 690
         }
691 691
 
692 692
         return $wpinv_ip_address_country;
693 693
     }
694 694
     
695
-    public static function sanitize_vat_settings( $input ) {
695
+    public static function sanitize_vat_settings($input) {
696 696
         global $wpinv_options;
697 697
         
698 698
         $valid      = false;
699 699
         $message    = '';
700 700
         
701
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
702
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
703
-                $valid = self::offline_check( $input['vat_number'] );
701
+        if (!empty($wpinv_options['vat_vies_check'])) {
702
+            if (empty($wpinv_options['vat_offline_check'])) {
703
+                $valid = self::offline_check($input['vat_number']);
704 704
             } else {
705 705
                 $valid = true;
706 706
             }
707 707
             
708
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
708
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
709 709
         } else {
710
-            $result = self::check_vat( $input['vat_number'] );
710
+            $result = self::check_vat($input['vat_number']);
711 711
             
712
-            if ( empty( $result['valid'] ) ) {
712
+            if (empty($result['valid'])) {
713 713
                 $valid      = false;
714 714
                 $message    = $result['message'];
715 715
             } else {
716
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
717
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
716
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
717
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
718 718
             }
719 719
         }
720 720
 
721
-        if ( $message && self::is_vat_validated() != $valid ) {
722
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
721
+        if ($message && self::is_vat_validated() != $valid) {
722
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
723 723
         }
724 724
 
725 725
         $input['vat_valid'] = $valid;
726 726
         return $input;
727 727
     }
728 728
     
729
-    public static function sanitize_vat_rates( $input ) {
730
-        if( !wpinv_current_user_can_manage_invoicing() ) {
731
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
729
+    public static function sanitize_vat_rates($input) {
730
+        if (!wpinv_current_user_can_manage_invoicing()) {
731
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
732 732
             return $input;
733 733
         }
734 734
         
735 735
         $vat_classes = self::get_rate_classes();
736
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
736
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
737 737
         
738
-        if ( empty( $vat_class ) ) {
739
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
738
+        if (empty($vat_class)) {
739
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
740 740
             
741 741
             return $input;
742 742
         }
743 743
 
744
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
744
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
745 745
 
746
-        if ( $vat_class === '_standard' ) {
746
+        if ($vat_class === '_standard') {
747 747
             // Save the active rates in the invoice settings
748
-            update_option( 'wpinv_tax_rates', $new_rates );
748
+            update_option('wpinv_tax_rates', $new_rates);
749 749
         } else {
750 750
             // Get the existing set of rates
751 751
             $rates = self::get_non_standard_rates();
752 752
             $rates[$vat_class] = $new_rates;
753 753
 
754
-            update_option( 'wpinv_vat_rates', $rates );
754
+            update_option('wpinv_vat_rates', $rates);
755 755
         }
756 756
         
757 757
         return $input;
@@ -761,71 +761,71 @@  discard block
 block discarded – undo
761 761
         $response = array();
762 762
         $response['success'] = false;
763 763
         
764
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
765
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
766
-            wp_send_json( $response );
764
+        if (!wpinv_current_user_can_manage_invoicing()) {
765
+            $response['error'] = __('Invalid access!', 'invoicing');
766
+            wp_send_json($response);
767 767
         }
768 768
         
769
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
770
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
769
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
770
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
771 771
         
772
-        if ( empty( $vat_class_name ) ) {
773
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
774
-            wp_send_json( $response );
772
+        if (empty($vat_class_name)) {
773
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
774
+            wp_send_json($response);
775 775
         }
776 776
         
777
-        $vat_classes = (array)self::get_rate_classes();
777
+        $vat_classes = (array) self::get_rate_classes();
778 778
 
779
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
780
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
781
-            wp_send_json( $response );
779
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
780
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
781
+            wp_send_json($response);
782 782
         }
783 783
         
784
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
785
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
784
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
785
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
786 786
         
787
-        $vat_classes = (array)self::get_rate_classes( true );
788
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
787
+        $vat_classes = (array) self::get_rate_classes(true);
788
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
789 789
         
790
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
790
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
791 791
         
792 792
         $response['success'] = true;
793
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
793
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
794 794
         
795
-        wp_send_json( $response );
795
+        wp_send_json($response);
796 796
     }
797 797
     
798 798
     public static function delete_class() {
799 799
         $response = array();
800 800
         $response['success'] = false;
801 801
         
802
-        if ( !wpinv_current_user_can_manage_invoicing() || !isset( $_POST['class'] ) ) {
803
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
804
-            wp_send_json( $response );
802
+        if (!wpinv_current_user_can_manage_invoicing() || !isset($_POST['class'])) {
803
+            $response['error'] = __('Invalid access!', 'invoicing');
804
+            wp_send_json($response);
805 805
         }
806 806
         
807
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
808
-        $vat_classes = (array)self::get_rate_classes();
807
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
808
+        $vat_classes = (array) self::get_rate_classes();
809 809
 
810
-        if ( !isset( $vat_classes[$vat_class] ) ) {
811
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
812
-            wp_send_json( $response );
810
+        if (!isset($vat_classes[$vat_class])) {
811
+            $response['error'] = __('Requested class does not exists', 'invoicing');
812
+            wp_send_json($response);
813 813
         }
814 814
         
815
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
816
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
817
-            wp_send_json( $response );
815
+        if ($vat_class == '_new' || $vat_class == '_standard') {
816
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
817
+            wp_send_json($response);
818 818
         }
819 819
             
820
-        $vat_classes = (array)self::get_rate_classes( true );
821
-        unset( $vat_classes[$vat_class] );
820
+        $vat_classes = (array) self::get_rate_classes(true);
821
+        unset($vat_classes[$vat_class]);
822 822
         
823
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
823
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
824 824
         
825 825
         $response['success'] = true;
826
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
826
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
827 827
         
828
-        wp_send_json( $response );
828
+        wp_send_json($response);
829 829
     }
830 830
     
831 831
     public static function update_eu_rates() {        
@@ -834,72 +834,72 @@  discard block
 block discarded – undo
834 834
         $response['error']      = null;
835 835
         $response['data']       = null;
836 836
         
837
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
838
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
839
-            wp_send_json( $response );
837
+        if (!wpinv_current_user_can_manage_invoicing()) {
838
+            $response['error'] = __('Invalid access!', 'invoicing');
839
+            wp_send_json($response);
840 840
         }
841 841
         
842
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
843
-        $euvatrates = self::request_euvatrates( $group );
842
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
843
+        $euvatrates = self::request_euvatrates($group);
844 844
         
845
-        if ( !empty( $euvatrates ) ) {
846
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
845
+        if (!empty($euvatrates)) {
846
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
847 847
                 $response['success']        = true;
848 848
                 $response['data']['rates']  = $euvatrates['rates'];
849
-            } else if ( !empty( $euvatrates['error'] ) ) {
849
+            } else if (!empty($euvatrates['error'])) {
850 850
                 $response['error']          = $euvatrates['error'];
851 851
             }
852 852
         }
853 853
             
854
-        wp_send_json( $response );
854
+        wp_send_json($response);
855 855
     }
856 856
     
857 857
     public static function hide_vat_fields() {
858
-        $hide = wpinv_get_option( 'vat_disable_fields' );
858
+        $hide = wpinv_get_option('vat_disable_fields');
859 859
         
860
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
860
+        return apply_filters('wpinv_hide_vat_fields', $hide);
861 861
     }
862 862
     
863 863
     public static function same_country_rule() {
864
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
864
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
865 865
         
866
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
866
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
867 867
     }
868 868
     
869 869
     public static function get_vat_name() {
870
-        $vat_name   = wpinv_get_option( 'vat_name' );
871
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
870
+        $vat_name   = wpinv_get_option('vat_name');
871
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
872 872
         
873
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
873
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
874 874
     }
875 875
     
876 876
     public static function get_company_name() {
877
-        $company_name = wpinv_get_option( 'vat_company_name' );
877
+        $company_name = wpinv_get_option('vat_company_name');
878 878
         
879
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
879
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
880 880
     }
881 881
     
882 882
     public static function get_vat_number() {
883
-        $vat_number = wpinv_get_option( 'vat_number' );
883
+        $vat_number = wpinv_get_option('vat_number');
884 884
         
885
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
885
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
886 886
     }
887 887
     
888 888
     public static function is_vat_validated() {
889
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
889
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
890 890
         
891
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
891
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
892 892
     }
893 893
     
894
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
895
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
894
+    public static function sanitize_vat($vat_number, $country_code = '') {        
895
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
896 896
         
897
-        if ( empty( $country_code ) ) {
898
-            $country_code = substr( $vat_number, 0, 2 );
897
+        if (empty($country_code)) {
898
+            $country_code = substr($vat_number, 0, 2);
899 899
         }
900 900
         
901
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
902
-            $vat = str_replace( $country_code, '', $vat_number );
901
+        if (strpos($vat_number, $country_code) === 0) {
902
+            $vat = str_replace($country_code, '', $vat_number);
903 903
         } else {
904 904
             $vat = $country_code . $vat_number;
905 905
         }
@@ -912,140 +912,140 @@  discard block
 block discarded – undo
912 912
         return $return;
913 913
     }
914 914
     
915
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
916
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
915
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
916
+        $vat            = self::sanitize_vat($vat_number, $country_code);
917 917
         $vat_number     = $vat['vat_number'];
918 918
         $country_code   = $vat['iso'];
919 919
         $regex          = array();
920 920
         
921
-        switch ( $country_code ) {
921
+        switch ($country_code) {
922 922
             case 'AT':
923
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
923
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
924 924
                 break;
925 925
             case 'BE':
926
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
926
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
927 927
                 break;
928 928
             case 'BG':
929
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
929
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
930 930
                 break;
931 931
             case 'CH':
932 932
             case 'CHE':
933
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
933
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
934 934
                 break;
935 935
             case 'CY':
936
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
936
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
937 937
                 break;
938 938
             case 'CZ':
939
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
939
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
940 940
                 break;
941 941
             case 'DE':
942
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
942
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
943 943
                 break;
944 944
             case 'DK':
945
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
945
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
946 946
                 break;
947 947
             case 'EE':
948
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
948
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
949 949
                 break;
950 950
             case 'EL':
951
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
951
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
952 952
                 break;
953 953
             case 'ES':
954
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
955
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
956
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
957
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
954
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
955
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
956
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
957
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
958 958
                 break;
959 959
             case 'EU':
960
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
960
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
961 961
                 break;
962 962
             case 'FI':
963
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
963
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
964 964
                 break;
965 965
             case 'FR':
966
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
967
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
968
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
969
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
966
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
967
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
968
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
969
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
970 970
                 break;
971 971
             case 'GB':
972
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
973
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
974
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
975
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
972
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
973
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
974
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
975
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
976 976
                 break;
977 977
             case 'GR':
978
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
978
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
979 979
                 break;
980 980
             case 'HR':
981
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
981
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
982 982
                 break;
983 983
             case 'HU':
984
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
984
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
985 985
                 break;
986 986
             case 'IE':
987
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
988
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
989
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
987
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
988
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
989
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
990 990
                 break;
991 991
             case 'IT':
992
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
992
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
993 993
                 break;
994 994
             case 'LV':
995
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
995
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
996 996
                 break;
997 997
             case 'LT':
998
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
998
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
999 999
                 break;
1000 1000
             case 'LU':
1001
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
1001
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
1002 1002
                 break;
1003 1003
             case 'MT':
1004
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
1004
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
1005 1005
                 break;
1006 1006
             case 'NL':
1007
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
1007
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
1008 1008
                 break;
1009 1009
             case 'NO':
1010
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
1010
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
1011 1011
                 break;
1012 1012
             case 'PL':
1013
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1013
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1014 1014
                 break;
1015 1015
             case 'PT':
1016
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1016
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1017 1017
                 break;
1018 1018
             case 'RO':
1019
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1019
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1020 1020
                 break;
1021 1021
             case 'RS':
1022
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1022
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1023 1023
                 break;
1024 1024
             case 'SI':
1025
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1025
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1026 1026
                 break;
1027 1027
             case 'SK':
1028
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1028
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1029 1029
                 break;
1030 1030
             case 'SE':
1031
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1031
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1032 1032
                 break;
1033 1033
             default:
1034 1034
                 $regex = array();
1035 1035
             break;
1036 1036
         }
1037 1037
         
1038
-        if ( empty( $regex ) ) {
1038
+        if (empty($regex)) {
1039 1039
             return false;
1040 1040
         }
1041 1041
         
1042
-        foreach ( $regex as $pattern ) {
1042
+        foreach ($regex as $pattern) {
1043 1043
             $matches = null;
1044
-            preg_match_all( $pattern, $vat_number, $matches );
1044
+            preg_match_all($pattern, $vat_number, $matches);
1045 1045
             
1046
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1047
-                if ( $formatted ) {
1048
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1046
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1047
+                if ($formatted) {
1048
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1049 1049
                 } else {
1050 1050
                     return true;
1051 1051
                 }
@@ -1055,75 +1055,75 @@  discard block
 block discarded – undo
1055 1055
         return false;
1056 1056
     }
1057 1057
     
1058
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1059
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1058
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1059
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1060 1060
         $vat_number     = $vat['vat'];
1061 1061
         $iso            = $vat['iso'];
1062 1062
         
1063
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1063
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1064 1064
         
1065
-        if ( ini_get( 'allow_url_fopen' ) ) {
1066
-            $response = file_get_contents( $url );
1067
-        } else if ( function_exists( 'curl_init' ) ) {
1065
+        if (ini_get('allow_url_fopen')) {
1066
+            $response = file_get_contents($url);
1067
+        } else if (function_exists('curl_init')) {
1068 1068
             $ch = curl_init();
1069 1069
             
1070
-            curl_setopt( $ch, CURLOPT_URL, $url );
1071
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1072
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1073
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1074
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1070
+            curl_setopt($ch, CURLOPT_URL, $url);
1071
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1072
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1073
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1074
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1075 1075
             
1076
-            $response = curl_exec( $ch );
1076
+            $response = curl_exec($ch);
1077 1077
             
1078
-            if ( curl_errno( $ch ) ) {
1079
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1078
+            if (curl_errno($ch)) {
1079
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1080 1080
                 $response = '';
1081 1081
             }
1082 1082
             
1083
-            curl_close( $ch );
1083
+            curl_close($ch);
1084 1084
         } else {
1085
-            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' );
1085
+            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');
1086 1086
         }
1087 1087
         
1088
-        if ( empty( $response ) ) {
1088
+        if (empty($response)) {
1089 1089
             return $result;
1090 1090
         }
1091 1091
 
1092
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1092
+        if (preg_match('/invalid VAT number/i', $response)) {
1093 1093
             return false;
1094
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1095
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1094
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1095
+            $content = explode("valid VAT number", htmlentities($response));
1096 1096
             
1097
-            if ( !empty( $content[1] ) ) {
1098
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1097
+            if (!empty($content[1])) {
1098
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1099 1099
                 
1100
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1100
+                if (!empty($matches[2]) && $matches[3]) {
1101 1101
                     $return = array();
1102 1102
                     
1103
-                    foreach ( $matches[2] as $key => $label ) {
1104
-                        $label = trim( $label );
1103
+                    foreach ($matches[2] as $key => $label) {
1104
+                        $label = trim($label);
1105 1105
                         
1106
-                        switch ( strtolower( $label ) ) {
1106
+                        switch (strtolower($label)) {
1107 1107
                             case 'member state':
1108
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1108
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1109 1109
                             break;
1110 1110
                             case 'vat number':
1111
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1111
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1112 1112
                             break;
1113 1113
                             case 'name':
1114
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1114
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1115 1115
                             break;
1116 1116
                             case 'address':
1117
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1118
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1117
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1118
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1119 1119
                             break;
1120 1120
                             case 'consultation number':
1121
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1121
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1122 1122
                             break;
1123 1123
                         }
1124 1124
                     }
1125 1125
                     
1126
-                    if ( !empty( $return ) ) {
1126
+                    if (!empty($return)) {
1127 1127
                         return $return;
1128 1128
                     }
1129 1129
                 }
@@ -1135,63 +1135,63 @@  discard block
 block discarded – undo
1135 1135
         }
1136 1136
     }
1137 1137
     
1138
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1138
+    public static function check_vat($vat_number, $country_code = '') {        
1139 1139
         $vat_name           = self::get_vat_name();
1140 1140
         
1141 1141
         $return             = array();
1142 1142
         $return['valid']    = false;
1143
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1143
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1144 1144
                 
1145
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1145
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1146 1146
             return $return;
1147 1147
         }
1148 1148
             
1149
-        $response = self::vies_check( $vat_number, $country_code );
1149
+        $response = self::vies_check($vat_number, $country_code);
1150 1150
         
1151
-        if ( $response ) {
1152
-            $return['valid']    = true;
1151
+        if ($response) {
1152
+            $return['valid'] = true;
1153 1153
             
1154
-            if ( is_array( $response ) ) {
1155
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1156
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1154
+            if (is_array($response)) {
1155
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1156
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1157 1157
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1158 1158
             }
1159 1159
         } else {
1160 1160
             $return['valid']    = false;
1161
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1161
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1162 1162
         }
1163 1163
         
1164 1164
         return $return;
1165 1165
     }
1166 1166
     
1167
-    public static function request_euvatrates( $group ) {
1167
+    public static function request_euvatrates($group) {
1168 1168
         $response               = array();
1169 1169
         $response['success']    = false;
1170 1170
         $response['error']      = null;
1171 1171
         $response['eurates']    = null;
1172 1172
         
1173 1173
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1174
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1175
-        $api_response   = wp_remote_get( $euvatrates_url );
1174
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1175
+        $api_response   = wp_remote_get($euvatrates_url);
1176 1176
     
1177 1177
         try {
1178
-            if ( is_wp_error( $api_response ) ) {
1179
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1178
+            if (is_wp_error($api_response)) {
1179
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1180 1180
             } else {
1181
-                $body = json_decode( $api_response['body'] );
1181
+                $body = json_decode($api_response['body']);
1182 1182
                 
1183
-                if ( isset( $body->rates ) ) {
1183
+                if (isset($body->rates)) {
1184 1184
                     $rates = array();
1185 1185
                     
1186
-                    foreach ( $body->rates as $country_code => $rate ) {
1186
+                    foreach ($body->rates as $country_code => $rate) {
1187 1187
                         $vat_rate = array();
1188 1188
                         $vat_rate['country']        = $rate->country;
1189
-                        $vat_rate['standard']       = (float)$rate->standard_rate;
1190
-                        $vat_rate['reduced']        = (float)$rate->reduced_rate;
1191
-                        $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1192
-                        $vat_rate['parking']        = (float)$rate->parking_rate;
1189
+                        $vat_rate['standard']       = (float) $rate->standard_rate;
1190
+                        $vat_rate['reduced']        = (float) $rate->reduced_rate;
1191
+                        $vat_rate['superreduced']   = (float) $rate->super_reduced_rate;
1192
+                        $vat_rate['parking']        = (float) $rate->parking_rate;
1193 1193
                         
1194
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1194
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1195 1195
                             $vat_rate_group = array();
1196 1196
                             $vat_rate_group['country'] = $rate->country;
1197 1197
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1203,79 +1203,79 @@  discard block
 block discarded – undo
1203 1203
                     }
1204 1204
                     
1205 1205
                     $response['success']    = true;                                
1206
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1206
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1207 1207
                 } else {
1208
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1208
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1209 1209
                 }
1210 1210
             }
1211
-        } catch ( Exception $e ) {
1212
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1211
+        } catch (Exception $e) {
1212
+            $response['error'] = __($e->getMessage(), 'invoicing');
1213 1213
         }
1214 1214
         
1215
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1215
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1216 1216
     }    
1217 1217
     
1218
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1218
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1219 1219
         global $wpi_item_id, $wpi_country;
1220 1220
         
1221
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1222
-            $country_code = trim( $_POST['wpinv_country'] );
1223
-        } else if ( !empty( $_POST['country'] ) ) {
1224
-            $country_code = trim( $_POST['country'] );
1225
-        } else if ( !empty( $wpi_country ) ) {
1221
+        if (!empty($_POST['wpinv_country'])) {
1222
+            $country_code = trim($_POST['wpinv_country']);
1223
+        } else if (!empty($_POST['country'])) {
1224
+            $country_code = trim($_POST['country']);
1225
+        } else if (!empty($wpi_country)) {
1226 1226
             $country_code = $wpi_country;
1227 1227
         } else {
1228
-            $country_code = self::get_user_country( '', $user_id );
1228
+            $country_code = self::get_user_country('', $user_id);
1229 1229
         }
1230 1230
         
1231
-        if ( $is_digital === null && $wpi_item_id ) {
1232
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1231
+        if ($is_digital === null && $wpi_item_id) {
1232
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1233 1233
         }
1234 1234
         
1235
-        if ( !empty( $country_code ) ) {
1236
-            $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 ) );
1235
+        if (!empty($country_code)) {
1236
+            $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));
1237 1237
         }
1238 1238
         
1239
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1239
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1240 1240
     }
1241 1241
     
1242
-    public static function tax_label( $label = '' ) {
1242
+    public static function tax_label($label = '') {
1243 1243
         global $wpi_requires_vat;
1244 1244
         
1245
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1246
-            $wpi_requires_vat = self::requires_vat( 0, false );
1245
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1246
+            $wpi_requires_vat = self::requires_vat(0, false);
1247 1247
         }
1248 1248
         
1249
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1249
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1250 1250
     }
1251 1251
     
1252 1252
     public static function standard_rates_label() {
1253
-        return __( 'Standard Rates', 'invoicing' );
1253
+        return __('Standard Rates', 'invoicing');
1254 1254
     }
1255 1255
     
1256
-    public static function get_rate_classes( $with_desc = false ) {        
1257
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1258
-        $classes = maybe_unserialize( $rate_classes_option );
1256
+    public static function get_rate_classes($with_desc = false) {        
1257
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1258
+        $classes = maybe_unserialize($rate_classes_option);
1259 1259
 
1260
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1260
+        if (empty($classes) || !is_array($classes)) {
1261 1261
             $classes = array();
1262 1262
         }
1263 1263
 
1264 1264
         $rate_classes = array();
1265
-        if ( !array_key_exists( '_standard', $classes ) ) {
1266
-            if ( $with_desc ) {
1267
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1265
+        if (!array_key_exists('_standard', $classes)) {
1266
+            if ($with_desc) {
1267
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1268 1268
             } else {
1269 1269
                 $rate_classes['_standard'] = self::standard_rates_label();
1270 1270
             }
1271 1271
         }
1272 1272
         
1273
-        foreach ( $classes as $key => $class ) {
1274
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1275
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1273
+        foreach ($classes as $key => $class) {
1274
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1275
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1276 1276
             
1277
-            if ( $with_desc ) {
1278
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1277
+            if ($with_desc) {
1278
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1279 1279
             } else {
1280 1280
                 $rate_classes[$key] = $name;
1281 1281
             }
@@ -1286,15 +1286,15 @@  discard block
 block discarded – undo
1286 1286
     
1287 1287
     public static function get_all_classes() {        
1288 1288
         $classes            = self::get_rate_classes();
1289
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1289
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1290 1290
         
1291
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1291
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1292 1292
     }
1293 1293
     
1294
-    public static function get_class_desc( $rate_class ) {        
1295
-        $rate_classes = self::get_rate_classes( true );
1294
+    public static function get_class_desc($rate_class) {        
1295
+        $rate_classes = self::get_rate_classes(true);
1296 1296
 
1297
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1297
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1298 1298
             return $rate_classes[$rate_class]['desc'];
1299 1299
         }
1300 1300
         
@@ -1310,107 +1310,107 @@  discard block
 block discarded – undo
1310 1310
             'increased'     => 'Increased'
1311 1311
         );
1312 1312
         
1313
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1313
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1314 1314
     }
1315 1315
 
1316 1316
     public static function get_rules() {
1317 1317
         $vat_rules = array(
1318
-            'digital' => __( 'Digital Product', 'invoicing' ),
1319
-            'physical' => __( 'Physical Product', 'invoicing' ),    
1320
-            '_exempt' => __( 'Tax-Free Product', 'invoicing' ),
1318
+            'digital' => __('Digital Product', 'invoicing'),
1319
+            'physical' => __('Physical Product', 'invoicing'),    
1320
+            '_exempt' => __('Tax-Free Product', 'invoicing'),
1321 1321
         );
1322
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1322
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1323 1323
     }
1324 1324
 
1325
-    public static function get_vat_rates( $class ) {
1326
-        if ( $class === '_standard' ) {
1325
+    public static function get_vat_rates($class) {
1326
+        if ($class === '_standard') {
1327 1327
             return wpinv_get_tax_rates();
1328 1328
         }
1329 1329
 
1330 1330
         $rates = self::get_non_standard_rates();
1331 1331
 
1332
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1332
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1333 1333
     }
1334 1334
 
1335 1335
     public static function get_non_standard_rates() {
1336
-        $option = get_option( 'wpinv_vat_rates', array());
1337
-        return is_array( $option ) ? $option : array();
1336
+        $option = get_option('wpinv_vat_rates', array());
1337
+        return is_array($option) ? $option : array();
1338 1338
     }
1339 1339
     
1340 1340
     public static function allow_vat_rules() {
1341
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1341
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1342 1342
     }
1343 1343
     
1344 1344
     public static function allow_vat_classes() {
1345 1345
         return false; // TODO
1346
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1346
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1347 1347
     }
1348 1348
     
1349
-    public static function get_item_class( $postID ) {
1350
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1349
+    public static function get_item_class($postID) {
1350
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1351 1351
 
1352
-        if ( empty( $class ) ) {
1352
+        if (empty($class)) {
1353 1353
             $class = '_standard';
1354 1354
         }
1355 1355
         
1356
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1356
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1357 1357
     }
1358 1358
     
1359
-    public static function item_class_label( $postID ) {        
1359
+    public static function item_class_label($postID) {        
1360 1360
         $vat_classes = self::get_all_classes();
1361 1361
         
1362
-        $class = self::get_item_class( $postID );
1363
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1362
+        $class = self::get_item_class($postID);
1363
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1364 1364
         
1365
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1365
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1366 1366
     }
1367 1367
     
1368
-    public static function get_item_rule( $postID ) {        
1369
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1368
+    public static function get_item_rule($postID) {        
1369
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1370 1370
 
1371
-        if ( empty( $rule_type ) ) {        
1371
+        if (empty($rule_type)) {        
1372 1372
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1373 1373
         }
1374 1374
         
1375
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1375
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1376 1376
     }
1377 1377
     
1378
-    public static function item_rule_label( $postID ) {
1378
+    public static function item_rule_label($postID) {
1379 1379
         $vat_rules  = self::get_rules();
1380
-        $vat_rule   = self::get_item_rule( $postID );
1381
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1380
+        $vat_rule   = self::get_item_rule($postID);
1381
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1382 1382
         
1383
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1383
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1384 1384
     }
1385 1385
     
1386
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1387
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1386
+    public static function item_has_digital_rule($item_id = 0) {        
1387
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1388 1388
     }
1389 1389
 
1390
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1391
-        if ( !self::allow_vat_rules() ) {
1390
+    public static function invoice_has_digital_rule($invoice = 0) {        
1391
+        if (!self::allow_vat_rules()) {
1392 1392
             return false;
1393 1393
         }
1394 1394
         
1395
-        if ( empty( $invoice ) ) {
1395
+        if (empty($invoice)) {
1396 1396
             return true;
1397 1397
         }
1398 1398
         
1399
-        if ( is_int( $invoice ) ) {
1400
-            $invoice = new WPInv_Invoice( $invoice );
1399
+        if (is_int($invoice)) {
1400
+            $invoice = new WPInv_Invoice($invoice);
1401 1401
         }
1402 1402
         
1403
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1403
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1404 1404
             return true;
1405 1405
         }
1406 1406
         
1407
-        $cart_items  = $invoice->get_cart_details();
1407
+        $cart_items = $invoice->get_cart_details();
1408 1408
         
1409
-        if ( !empty( $cart_items ) ) {
1409
+        if (!empty($cart_items)) {
1410 1410
             $has_digital_rule = false;
1411 1411
             
1412
-            foreach ( $cart_items as $key => $item ) {
1413
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1412
+            foreach ($cart_items as $key => $item) {
1413
+                if (self::item_has_digital_rule($item['id'])) {
1414 1414
                     $has_digital_rule = true;
1415 1415
                     break;
1416 1416
                 }
@@ -1422,71 +1422,71 @@  discard block
 block discarded – undo
1422 1422
         return $has_digital_rule;
1423 1423
     }
1424 1424
     
1425
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1426
-        if ( !wpinv_use_taxes() ) {
1425
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1426
+        if (!wpinv_use_taxes()) {
1427 1427
             return false;
1428 1428
         }
1429 1429
 
1430 1430
         $is_taxable = true;
1431 1431
 
1432
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1432
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1433 1433
             $is_taxable = false;
1434 1434
         }
1435 1435
 
1436
-        if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) {
1436
+        if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') {
1437 1437
             $is_taxable = false;
1438 1438
         }
1439 1439
 
1440
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1440
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1441 1441
     }
1442 1442
     
1443
-    public static function find_rate( $country, $state, $rate, $class ) {
1443
+    public static function find_rate($country, $state, $rate, $class) {
1444 1444
         global $wpi_zero_tax;
1445 1445
 
1446
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1446
+        if ($class === '_exempt' || $wpi_zero_tax) {
1447 1447
             return 0;
1448 1448
         }
1449 1449
 
1450
-        $tax_rates   = wpinv_get_tax_rates();
1450
+        $tax_rates = wpinv_get_tax_rates();
1451 1451
         
1452
-        if ( $class !== '_standard' ) {
1453
-            $class_rates = self::get_vat_rates( $class );
1452
+        if ($class !== '_standard') {
1453
+            $class_rates = self::get_vat_rates($class);
1454 1454
             
1455
-            if ( is_array( $class_rates ) ) {
1455
+            if (is_array($class_rates)) {
1456 1456
                 $indexed_class_rates = array();
1457 1457
                 
1458
-                foreach ( $class_rates as $key => $cr ) {
1458
+                foreach ($class_rates as $key => $cr) {
1459 1459
                     $indexed_class_rates[$cr['country']] = $cr;
1460 1460
                 }
1461 1461
 
1462
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1462
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1463 1463
                     $tr_country = $tr['country'];
1464
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1464
+                    if (!isset($indexed_class_rates[$tr_country])) {
1465 1465
                         return $tr;
1466 1466
                     }
1467 1467
                     $icr = $indexed_class_rates[$tr_country];
1468
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1468
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1469 1469
 
1470
-                }, $tax_rates, $class_rates );
1470
+                }, $tax_rates, $class_rates);
1471 1471
             }
1472 1472
         }
1473 1473
 
1474
-        if ( !empty( $tax_rates ) ) {
1475
-            foreach ( $tax_rates as $key => $tax_rate ) {
1476
-                if ( $country != $tax_rate['country'] )
1474
+        if (!empty($tax_rates)) {
1475
+            foreach ($tax_rates as $key => $tax_rate) {
1476
+                if ($country != $tax_rate['country'])
1477 1477
                     continue;
1478 1478
 
1479
-                if ( !empty( $tax_rate['global'] ) ) {
1480
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1481
-                        $rate = number_format( $tax_rate['rate'], 4 );
1479
+                if (!empty($tax_rate['global'])) {
1480
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1481
+                        $rate = number_format($tax_rate['rate'], 4);
1482 1482
                     }
1483 1483
                 } else {
1484
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1484
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1485 1485
                         continue;
1486 1486
 
1487 1487
                     $state_rate = $tax_rate['rate'];
1488
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1489
-                        $rate = number_format( $state_rate, 4 );
1488
+                    if (0 !== $state_rate || !empty($state_rate)) {
1489
+                        $rate = number_format($state_rate, 4);
1490 1490
                     }
1491 1491
                 }
1492 1492
             }
@@ -1495,84 +1495,84 @@  discard block
 block discarded – undo
1495 1495
         return $rate;
1496 1496
     }
1497 1497
     
1498
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1498
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1499 1499
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1500 1500
         
1501 1501
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1502 1502
         $allow_vat_classes = self::allow_vat_classes();
1503
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1503
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1504 1504
 
1505
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1505
+        if ($class === '_exempt' || $wpi_zero_tax) {
1506 1506
             return 0;
1507
-        } else if ( !$allow_vat_classes ) {
1507
+        } else if (!$allow_vat_classes) {
1508 1508
             $class = '_standard';
1509 1509
         }
1510 1510
 
1511
-        if( !empty( $_POST['wpinv_country'] ) ) {
1511
+        if (!empty($_POST['wpinv_country'])) {
1512 1512
             $post_country = $_POST['wpinv_country'];
1513
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1513
+        } elseif (!empty($_POST['wpinv_country'])) {
1514 1514
             $post_country = $_POST['wpinv_country'];
1515
-        } elseif( !empty( $_POST['country'] ) ) {
1515
+        } elseif (!empty($_POST['country'])) {
1516 1516
             $post_country = $_POST['country'];
1517 1517
         } else {
1518 1518
             $post_country = '';
1519 1519
         }
1520 1520
 
1521
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1522
-        $base_country   = wpinv_is_base_country( $country );
1521
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1522
+        $base_country   = wpinv_is_base_country($country);
1523 1523
         
1524
-        $requires_vat   = self::requires_vat( 0, false );
1525
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1526
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1524
+        $requires_vat   = self::requires_vat(0, false);
1525
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1526
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1527 1527
           
1528
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1528
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1529 1529
             $rate = 0;
1530
-        } else if ( $requires_vat ) {
1531
-            $vat_number = self::get_user_vat_number( '', 0, true );
1530
+        } else if ($requires_vat) {
1531
+            $vat_number = self::get_user_vat_number('', 0, true);
1532 1532
             $vat_info   = self::current_vat_data();
1533 1533
             
1534
-            if ( is_array( $vat_info ) ) {
1535
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1534
+            if (is_array($vat_info)) {
1535
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1536 1536
             }
1537 1537
             
1538
-            if ( $country == 'UK' ) {
1538
+            if ($country == 'UK') {
1539 1539
                 $country = 'GB';
1540 1540
             }
1541 1541
 
1542
-            if ( !empty( $vat_number ) ) {
1542
+            if (!empty($vat_number)) {
1543 1543
                 $rate = 0;
1544 1544
             } else {
1545
-                $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
1545
+                $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
1546 1546
             }
1547 1547
 
1548
-            if ( empty( $vat_number ) && !$is_digital ) {
1549
-                if ( $base_country ) {
1550
-                    $rate = self::find_rate( $country, null, $rate, $class );
1548
+            if (empty($vat_number) && !$is_digital) {
1549
+                if ($base_country) {
1550
+                    $rate = self::find_rate($country, null, $rate, $class);
1551 1551
                 } else {
1552
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1552
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1553 1553
                         $rate = $wpinv_options['eu_fallback_rate'];
1554
-                    } else if( !empty( $country ) ) {
1555
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1554
+                    } else if (!empty($country)) {
1555
+                        $rate = self::find_rate($country, $state, $rate, $class);
1556 1556
                     }
1557 1557
                 }
1558
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1559
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1558
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1559
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1560 1560
                     $rate = $wpinv_options['eu_fallback_rate'];
1561
-                } else if( !empty( $country ) ) {
1562
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1561
+                } else if (!empty($country)) {
1562
+                    $rate = self::find_rate($country, $state, $rate, $class);
1563 1563
                 }
1564 1564
             }
1565 1565
         } else {
1566
-            if ( $is_digital ) {
1566
+            if ($is_digital) {
1567 1567
                 $ip_country_code = self::get_country_by_ip();
1568 1568
                 
1569
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1570
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1569
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1570
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1571 1571
                 } else {
1572
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1572
+                    $rate = self::find_rate($country, $state, $rate, $class);
1573 1573
                 }
1574 1574
             } else {
1575
-                $rate = self::find_rate( $country, $state, $rate, $class );
1575
+                $rate = self::find_rate($country, $state, $rate, $class);
1576 1576
             }
1577 1577
         }
1578 1578
 
@@ -1582,48 +1582,48 @@  discard block
 block discarded – undo
1582 1582
     public static function current_vat_data() {
1583 1583
         global $wpi_session;
1584 1584
         
1585
-        return $wpi_session->get( 'user_vat_data' );
1585
+        return $wpi_session->get('user_vat_data');
1586 1586
     }
1587 1587
     
1588
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1589
-        $user_address = wpinv_get_user_address( $user_id, false );
1588
+    public static function get_user_country($country = '', $user_id = 0) {
1589
+        $user_address = wpinv_get_user_address($user_id, false);
1590 1590
         
1591
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1591
+        if (wpinv_get_option('vat_ip_country_default')) {
1592 1592
             $country = '';
1593 1593
         }
1594 1594
         
1595
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1596
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1595
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1596
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1597 1597
 
1598
-        if ( empty( $result ) ) {
1598
+        if (empty($result)) {
1599 1599
             $result = self::get_country_by_ip();
1600 1600
         }
1601 1601
 
1602 1602
         return $result;
1603 1603
     }
1604 1604
     
1605
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1605
+    public static function set_user_country($country = '', $user_id = 0) {
1606 1606
         global $wpi_userID;
1607 1607
         
1608
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1608
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1609 1609
             $country = wpinv_get_default_country();
1610 1610
         }
1611 1611
         
1612 1612
         return $country;
1613 1613
     }
1614 1614
     
1615
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1615
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1616 1616
         global $wpi_current_id, $wpi_userID;
1617 1617
         
1618
-        if ( !empty( $_POST['new_user'] ) ) {
1618
+        if (!empty($_POST['new_user'])) {
1619 1619
             return '';
1620 1620
         }
1621 1621
         
1622
-        if ( empty( $user_id ) ) {
1623
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1622
+        if (empty($user_id)) {
1623
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1624 1624
         }
1625 1625
 
1626
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1626
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1627 1627
         
1628 1628
         /* TODO
1629 1629
         if ( $is_valid && $vat_number ) {
@@ -1634,38 +1634,38 @@  discard block
 block discarded – undo
1634 1634
         }
1635 1635
         */
1636 1636
 
1637
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1637
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1638 1638
     }
1639 1639
     
1640
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1640
+    public static function get_user_company($company = '', $user_id = 0) {
1641 1641
         global $wpi_current_id, $wpi_userID;
1642 1642
         
1643
-        if ( empty( $user_id ) ) {
1644
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1643
+        if (empty($user_id)) {
1644
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1645 1645
         }
1646 1646
 
1647
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1647
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1648 1648
 
1649
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1649
+        return apply_filters('wpinv_user_company', $company, $user_id);
1650 1650
     }
1651 1651
     
1652
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1653
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1652
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1653
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1654 1654
 
1655
-        if ( is_user_logged_in() && $save ) {
1655
+        if (is_user_logged_in() && $save) {
1656 1656
             $user_id = get_current_user_id();
1657 1657
 
1658
-            if ( !empty( $vat_number ) ) {
1659
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1658
+            if (!empty($vat_number)) {
1659
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1660 1660
             } else {
1661
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1661
+                delete_user_meta($user_id, '_wpinv_vat_number');
1662 1662
             }
1663 1663
 
1664
-            if ( !empty( $company ) ) {
1665
-                update_user_meta( $user_id, '_wpinv_company', $company );
1664
+            if (!empty($company)) {
1665
+                update_user_meta($user_id, '_wpinv_company', $company);
1666 1666
             } else {
1667
-                delete_user_meta( $user_id, '_wpinv_company');
1668
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1667
+                delete_user_meta($user_id, '_wpinv_company');
1668
+                delete_user_meta($user_id, '_wpinv_vat_number');
1669 1669
             }
1670 1670
         }
1671 1671
 
@@ -1675,113 +1675,113 @@  discard block
 block discarded – undo
1675 1675
     public static function ajax_vat_validate() {
1676 1676
         global $wpinv_options, $wpi_session;
1677 1677
         
1678
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1678
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1679 1679
         $response               = array();
1680 1680
         $response['success']    = false;
1681 1681
         
1682
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1683
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1684
-            wp_send_json( $response );
1682
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1683
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1684
+            wp_send_json($response);
1685 1685
         }
1686 1686
         
1687
-        $vat_name   = self::get_vat_name();
1687
+        $vat_name = self::get_vat_name();
1688 1688
         
1689
-        if ( $is_checkout ) {
1689
+        if ($is_checkout) {
1690 1690
             $invoice = wpinv_get_invoice_cart();
1691 1691
             
1692
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1692
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1693 1693
                 $vat_info = array();
1694
-                $wpi_session->set( 'user_vat_data', $vat_info );
1694
+                $wpi_session->set('user_vat_data', $vat_info);
1695 1695
 
1696 1696
                 self::save_user_vat_details();
1697 1697
                 
1698 1698
                 $response['success'] = true;
1699
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1700
-                wp_send_json( $response );
1699
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1700
+                wp_send_json($response);
1701 1701
             }
1702 1702
         }
1703 1703
         
1704
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1705
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1704
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1705
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1706 1706
         
1707
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1708
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1709
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1707
+        $vat_info = $wpi_session->get('user_vat_data');
1708
+        if (!is_array($vat_info) || empty($vat_info)) {
1709
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1710 1710
         }
1711 1711
         
1712
-        if ( empty( $vat_number ) ) {
1713
-            if ( $is_checkout ) {
1712
+        if (empty($vat_number)) {
1713
+            if ($is_checkout) {
1714 1714
                 $response['success'] = true;
1715
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1715
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1716 1716
                 
1717
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1717
+                $vat_info = $wpi_session->get('user_vat_data');
1718 1718
                 $vat_info['number'] = "";
1719 1719
                 $vat_info['valid'] = true;
1720 1720
                 
1721
-                self::save_user_vat_details( $company );
1721
+                self::save_user_vat_details($company);
1722 1722
             } else {
1723
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1723
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1724 1724
                 
1725 1725
                 $vat_info['valid'] = false;
1726 1726
             }
1727 1727
 
1728
-            $wpi_session->set( 'user_vat_data', $vat_info );
1729
-            wp_send_json( $response );
1728
+            $wpi_session->set('user_vat_data', $vat_info);
1729
+            wp_send_json($response);
1730 1730
         }
1731 1731
         
1732
-        if ( empty( $company ) ) {
1732
+        if (empty($company)) {
1733 1733
             $vat_info['valid'] = false;
1734
-            $wpi_session->set( 'user_vat_data', $vat_info );
1734
+            $wpi_session->set('user_vat_data', $vat_info);
1735 1735
             
1736
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1737
-            wp_send_json( $response );
1736
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1737
+            wp_send_json($response);
1738 1738
         }
1739 1739
         
1740
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1741
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1740
+        if (!empty($wpinv_options['vat_vies_check'])) {
1741
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1742 1742
                 $vat_info['valid'] = false;
1743
-                $wpi_session->set( 'user_vat_data', $vat_info );
1743
+                $wpi_session->set('user_vat_data', $vat_info);
1744 1744
                 
1745
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1746
-                wp_send_json( $response );
1745
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1746
+                wp_send_json($response);
1747 1747
             }
1748 1748
             
1749 1749
             $response['success'] = true;
1750
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1750
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1751 1751
         } else {
1752
-            $result = self::check_vat( $vat_number );
1752
+            $result = self::check_vat($vat_number);
1753 1753
             
1754
-            if ( empty( $result['valid'] ) ) {
1754
+            if (empty($result['valid'])) {
1755 1755
                 $response['error'] = $result['message'];
1756
-                wp_send_json( $response );
1756
+                wp_send_json($response);
1757 1757
             }
1758 1758
             
1759
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1760
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1759
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1760
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1761 1761
             
1762
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1762
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1763 1763
 
1764
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1764
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1765 1765
                 $response['success'] = true;
1766
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1766
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1767 1767
             } else {           
1768 1768
                 $vat_info['valid'] = false;
1769
-                $wpi_session->set( 'user_vat_data', $vat_info );
1769
+                $wpi_session->set('user_vat_data', $vat_info);
1770 1770
                 
1771 1771
                 $response['success'] = false;
1772
-                $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 );
1773
-                wp_send_json( $response );
1772
+                $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);
1773
+                wp_send_json($response);
1774 1774
             }
1775 1775
         }
1776 1776
         
1777
-        if ( $is_checkout ) {
1778
-            self::save_user_vat_details( $company, $vat_number );
1777
+        if ($is_checkout) {
1778
+            self::save_user_vat_details($company, $vat_number);
1779 1779
 
1780
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1781
-            $wpi_session->set( 'user_vat_data', $vat_info );
1780
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1781
+            $wpi_session->set('user_vat_data', $vat_info);
1782 1782
         }
1783 1783
 
1784
-        wp_send_json( $response );
1784
+        wp_send_json($response);
1785 1785
     }
1786 1786
     
1787 1787
     public static function ajax_vat_reset() {
@@ -1790,161 +1790,161 @@  discard block
 block discarded – undo
1790 1790
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1791 1791
         $vat_number = self::get_user_vat_number();
1792 1792
         
1793
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1794
-        $wpi_session->set( 'user_vat_data', $vat_info );
1793
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1794
+        $wpi_session->set('user_vat_data', $vat_info);
1795 1795
         
1796 1796
         $response                       = array();
1797 1797
         $response['success']            = true;
1798 1798
         $response['data']['company']    = $company;
1799 1799
         $response['data']['number']     = $vat_number;
1800 1800
         
1801
-        wp_send_json( $response );
1801
+        wp_send_json($response);
1802 1802
     }
1803 1803
     
1804
-    public static function checkout_vat_validate( $valid_data, $post ) {
1804
+    public static function checkout_vat_validate($valid_data, $post) {
1805 1805
         global $wpinv_options, $wpi_session;
1806 1806
         
1807
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1807
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1808 1808
         
1809
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1810
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1809
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1810
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1811 1811
             return;
1812 1812
         }
1813 1813
         
1814
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1815
-        $wpi_session->set( 'user_vat_data', null );
1814
+        $vat_saved = $wpi_session->get('user_vat_data');
1815
+        $wpi_session->set('user_vat_data', null);
1816 1816
         
1817 1817
         $invoice        = wpinv_get_invoice_cart();
1818 1818
         $amount         = $invoice->get_total();
1819
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1820
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1819
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1820
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1821 1821
         
1822
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1823
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1824
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1825
-        if ( empty( $country ) ) {
1822
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1823
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1824
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1825
+        if (empty($country)) {
1826 1826
             $country = wpinv_default_billing_country();
1827 1827
         }
1828 1828
         
1829
-        if ( !$is_digital && $no_vat ) {
1829
+        if (!$is_digital && $no_vat) {
1830 1830
             return;
1831 1831
         }
1832 1832
             
1833
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1833
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1834 1834
         
1835 1835
         $ip_country_code    = self::get_country_by_ip();
1836
-        $is_eu_state        = self::is_eu_state( $country );
1837
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1836
+        $is_eu_state        = self::is_eu_state($country);
1837
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1838 1838
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1839 1839
         
1840
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1840
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1841 1841
             $vat_data['adddress_confirmed'] = false;
1842 1842
             
1843
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1844
-                if ( $ip_country_code != $country ) {
1845
-                    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>' ) );
1843
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1844
+                if ($ip_country_code != $country) {
1845
+                    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>'));
1846 1846
                 }
1847 1847
             } else {
1848 1848
                 $vat_data['adddress_confirmed'] = true;
1849 1849
             }
1850 1850
         }
1851 1851
         
1852
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1853
-            if ( $is_eu_state ) {
1854
-                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 ) );
1855
-            } else if ( $is_digital && $is_eu_state_ip ) {
1856
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1852
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1853
+            if ($is_eu_state) {
1854
+                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));
1855
+            } else if ($is_digital && $is_eu_state_ip) {
1856
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1857 1857
             }
1858 1858
         }
1859 1859
         
1860
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1860
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1861 1861
             return;
1862 1862
         }
1863 1863
 
1864
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1865
-            $vat_data['valid']  = $vat_saved['valid'];
1864
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1865
+            $vat_data['valid'] = $vat_saved['valid'];
1866 1866
         }
1867 1867
             
1868
-        if ( $company !== null ) {
1868
+        if ($company !== null) {
1869 1869
             $vat_data['company'] = $company;
1870 1870
         }
1871 1871
 
1872 1872
         $message = '';
1873
-        if ( $vat_number !== null ) {
1873
+        if ($vat_number !== null) {
1874 1874
             $vat_data['number'] = $vat_number;
1875 1875
             
1876
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1877
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1878
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1876
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1877
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1878
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1879 1879
                         $vat_data['valid'] = false;
1880 1880
                     }
1881 1881
                 } else {
1882
-                    $result = self::check_vat( $vat_number );
1882
+                    $result = self::check_vat($vat_number);
1883 1883
                     
1884
-                    if ( !empty( $result['valid'] ) ) {                
1884
+                    if (!empty($result['valid'])) {                
1885 1885
                         $vat_data['valid'] = true;
1886
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1887
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1886
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1887
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1888 1888
                     
1889
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1889
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1890 1890
 
1891
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1891
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1892 1892
                             $vat_data['valid'] = false;
1893 1893
                             
1894
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1894
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1895 1895
                         }
1896 1896
                     } else {
1897
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1897
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1898 1898
                     }
1899 1899
                 }
1900 1900
                 
1901
-                if ( !$vat_data['valid'] ) {
1902
-                    $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 . ' )' : '' );
1903
-                    wpinv_set_error( 'vat_validation', $error );
1901
+                if (!$vat_data['valid']) {
1902
+                    $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 . ' )' : '');
1903
+                    wpinv_set_error('vat_validation', $error);
1904 1904
                 }
1905 1905
             }
1906 1906
         }
1907 1907
 
1908
-        $wpi_session->set( 'user_vat_data', $vat_data );
1908
+        $wpi_session->set('user_vat_data', $vat_data);
1909 1909
     }
1910 1910
     
1911
-    public static function checkout_vat_fields( $billing_details ) {
1911
+    public static function checkout_vat_fields($billing_details) {
1912 1912
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1913 1913
         
1914 1914
         $ip_address         = wpinv_get_ip();
1915 1915
         $ip_country_code    = self::get_country_by_ip();
1916 1916
         
1917
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1917
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1918 1918
         $invoice            = wpinv_get_invoice_cart();
1919
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1919
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1920 1920
         $wpi_country        = $invoice->country;
1921 1921
         
1922
-        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital );
1922
+        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital);
1923 1923
         $wpi_requires_vat   = $requires_vat;
1924 1924
         
1925 1925
         $company            = self::get_user_company();
1926 1926
         $vat_number         = self::get_user_vat_number();
1927 1927
         
1928
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1929
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1928
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1929
+        $vat_info           = $wpi_session->get('user_vat_data');
1930 1930
 
1931
-        if ( is_array( $vat_info ) ) {
1932
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1933
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1934
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1931
+        if (is_array($vat_info)) {
1932
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1933
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1934
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1935 1935
         }
1936 1936
         
1937 1937
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1938 1938
 
1939
-        if ( $ip_country_code == 'UK' ) {
1939
+        if ($ip_country_code == 'UK') {
1940 1940
             $ip_country_code = 'GB';
1941 1941
         }
1942 1942
         
1943
-        if ( $selected_country == 'UK' ) {
1943
+        if ($selected_country == 'UK') {
1944 1944
             $selected_country = 'GB';
1945 1945
         }
1946 1946
         
1947
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1947
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1948 1948
             $requires_vat = false;
1949 1949
         }
1950 1950
 
@@ -1952,52 +1952,52 @@  discard block
 block discarded – undo
1952 1952
         $display_validate_btn   = 'none';
1953 1953
         $display_reset_btn      = 'none';
1954 1954
         
1955
-        if ( !empty( $vat_number ) && $validated ) {
1956
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1955
+        if (!empty($vat_number) && $validated) {
1956
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1957 1957
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1958 1958
             $display_reset_btn      = 'block';
1959 1959
         } else {
1960
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1961
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1960
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1961
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1962 1962
             $display_validate_btn   = 'block';
1963 1963
         }
1964 1964
         
1965
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1965
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1966 1966
         ?>
1967 1967
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1968 1968
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1969
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1969
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1970 1970
                 <div id="wpinv-fields-box" class="panel-body">
1971 1971
                     <p id="wpi_show_vat_note">
1972
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1972
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1973 1973
                     </p>
1974 1974
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1975 1975
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1976
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1976
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1977 1977
                             <?php
1978
-                            echo wpinv_html_text( array(
1978
+                            echo wpinv_html_text(array(
1979 1979
                                     'id'            => 'wpinv_company',
1980 1980
                                     'name'          => 'wpinv_company',
1981 1981
                                     'value'         => $company,
1982 1982
                                     'class'         => 'wpi-input form-control',
1983
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1984
-                                ) );
1983
+                                    'placeholder'   => __('Company name', 'invoicing'),
1984
+                                ));
1985 1985
                             ?>
1986 1986
                         </p>
1987 1987
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1988
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1988
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1989 1989
                             <span id="wpinv_vat_number-wrap">
1990 1990
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1991
-                                <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">
1992
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1991
+                                <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">
1992
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1993 1993
                             </span>
1994 1994
                         </p>
1995 1995
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1996
-                            <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>
1997
-                            <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>
1996
+                            <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>
1997
+                            <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>
1998 1998
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1999 1999
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
2000
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
2000
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
2001 2001
                         </p>
2002 2002
                     </div>
2003 2003
                 </div>
@@ -2011,32 +2011,32 @@  discard block
 block discarded – undo
2011 2011
                 </span>
2012 2012
             </div>
2013 2013
         </div>
2014
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
2015
-            $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>';
2014
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
2015
+            $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>';
2016 2016
         ?>
2017 2017
         <div class="wpi-ip-info clearfix panel panel-info">
2018 2018
             <div id="wpinv-fields-box" class="panel-body">
2019
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
2019
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
2020 2020
             </div>
2021 2021
         </div>
2022 2022
         <?php }
2023 2023
     }
2024 2024
     
2025
-    public static function show_vat_notice( $invoice ) {
2026
-        if ( empty( $invoice ) ) {
2025
+    public static function show_vat_notice($invoice) {
2026
+        if (empty($invoice)) {
2027 2027
             return NULL;
2028 2028
         }
2029 2029
         
2030
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2031
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2032
-        if ( $label || $notice ) {
2030
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2031
+        $notice     = wpinv_get_option('vat_invoice_notice');
2032
+        if ($label || $notice) {
2033 2033
         ?>
2034 2034
         <div class="row wpinv-vat-notice">
2035 2035
             <div class="col-sm-12">
2036
-                <?php if ( $label ) { ?>
2037
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2038
-                <?php } if ( $notice ) { ?>
2039
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2036
+                <?php if ($label) { ?>
2037
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2038
+                <?php } if ($notice) { ?>
2039
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2040 2040
                 <?php } ?>
2041 2041
             </div>
2042 2042
         </div>
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  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
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -33,34 +33,34 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array(&$this, 'wpinv_actions'));
48 48
         
49
-        if ( class_exists( 'BuddyPress' ) ) {
50
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
49
+        if (class_exists('BuddyPress')) {
50
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
51 51
         }
52 52
 
53
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
-        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
55
-        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
53
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
54
+        add_action('widgets_init', array(&$this, 'register_widgets'));
55
+        add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
56 56
 
57
-        if ( is_admin() ) {
58
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
59
-            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
60
-            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
57
+        if (is_admin()) {
58
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
59
+            add_filter('admin_body_class', array(&$this, 'admin_body_class'));
60
+            add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
61 61
 
62 62
         } else {
63
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
63
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
64 64
         }
65 65
         
66 66
         /**
@@ -70,28 +70,28 @@  discard block
 block discarded – undo
70 70
          *
71 71
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
72 72
          */
73
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
73
+        do_action_ref_array('wpinv_actions', array(&$this));
74 74
 
75
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
75
+        add_action('admin_init', array(&$this, 'activation_redirect'));
76 76
     }
77 77
 
78 78
     /**
79 79
      * Maybe show the AyeCode Connect Notice.
80 80
      */
81
-    public function init_ayecode_connect_helper(){
81
+    public function init_ayecode_connect_helper() {
82 82
         // AyeCode Connect notice
83
-        if ( is_admin() ){
83
+        if (is_admin()) {
84 84
             // set the strings so they can be translated
85 85
             $strings = array(
86
-                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
87
-                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
88
-                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
89
-                'connect_button'    => __("Connect Site","invoicing"),
90
-                'connecting_button'    => __("Connecting...","invoicing"),
91
-                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
92
-                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
86
+                'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
87
+                'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
88
+                'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
89
+                'connect_button'    => __("Connect Site", "invoicing"),
90
+                'connecting_button'    => __("Connecting...", "invoicing"),
91
+                'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
92
+                'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
93 93
             );
94
-            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
94
+            new AyeCode_Connect_Helper($strings, array('wpi-addons'));
95 95
         }
96 96
     }
97 97
     
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
         /* Internationalize the text strings used. */
100 100
         $this->load_textdomain();
101 101
 
102
-        do_action( 'wpinv_loaded' );
102
+        do_action('wpinv_loaded');
103 103
 
104 104
         // Fix oxygen page builder conflict
105
-        if ( function_exists( 'ct_css_output' ) ) {
105
+        if (function_exists('ct_css_output')) {
106 106
             wpinv_oxygen_fix_conflict();
107 107
         }
108 108
     }
@@ -112,237 +112,237 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @since 1.0
114 114
      */
115
-    public function load_textdomain( $locale = NULL ) {
116
-        if ( empty( $locale ) ) {
117
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
115
+    public function load_textdomain($locale = NULL) {
116
+        if (empty($locale)) {
117
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
118 118
         }
119 119
 
120
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
120
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
121 121
         
122
-        unload_textdomain( 'invoicing' );
123
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
124
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
122
+        unload_textdomain('invoicing');
123
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
124
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
125 125
         
126 126
         /**
127 127
          * Define language constants.
128 128
          */
129
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
129
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
130 130
     }
131 131
         
132 132
     public function includes() {
133 133
         global $wpinv_options;
134 134
         
135
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
135
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
136 136
         $wpinv_options = wpinv_get_settings();
137 137
         
138
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
139
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
140
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
141
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
142
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
143
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
144
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
145
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
146
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
148
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
149
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
150
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
151
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
153
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
154
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
155
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
156
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
157
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
158
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
160
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
161
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
162
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
164
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
165
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
166
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
168
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
169
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
170
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
171
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
173
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
174
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
175
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
176
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
177
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
178
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
179
-        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
180
-        require_once( WPINV_PLUGIN_DIR . 'widgets/payment-form.php' );
181
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
182
-
183
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
184
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
138
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
139
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
140
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
141
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
142
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
143
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
144
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
145
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
146
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
148
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
149
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
150
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
151
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
153
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
154
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
155
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php');
156
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
157
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
158
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
160
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
161
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
162
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
164
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
165
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
166
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
168
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
169
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
170
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
171
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
173
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
174
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
175
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
176
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
177
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
178
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
179
+        require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
180
+        require_once(WPINV_PLUGIN_DIR . 'widgets/payment-form.php');
181
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
182
+
183
+        if (!class_exists('WPInv_EUVat')) {
184
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
185 185
         }
186 186
         
187
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
188
-        if ( !empty( $gateways ) ) {
189
-            foreach ( $gateways as $gateway ) {
190
-                if ( $gateway == 'manual' ) {
187
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
188
+        if (!empty($gateways)) {
189
+            foreach ($gateways as $gateway) {
190
+                if ($gateway == 'manual') {
191 191
                     continue;
192 192
                 }
193 193
                 
194 194
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
195 195
                 
196
-                if ( file_exists( $gateway_file ) ) {
197
-                    require_once( $gateway_file );
196
+                if (file_exists($gateway_file)) {
197
+                    require_once($gateway_file);
198 198
                 }
199 199
             }
200 200
         }
201
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
201
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
202 202
         
203
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
204
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
205
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
206
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
203
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
204
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
205
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
206
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
207 207
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
208
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
209
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
210
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
211
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
212
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
213
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
214
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
215
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
208
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
209
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
210
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
211
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
212
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
213
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
214
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
215
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
216 216
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
217 217
             // load the user class only on the users.php page
218 218
             global $pagenow;
219
-            if($pagenow=='users.php'){
219
+            if ($pagenow == 'users.php') {
220 220
                 new WPInv_Admin_Users();
221 221
             }
222 222
         }
223 223
 
224 224
         // Register cli commands
225
-        if ( defined( 'WP_CLI' ) && WP_CLI ) {
226
-            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
227
-            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
225
+        if (defined('WP_CLI') && WP_CLI) {
226
+            require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
227
+            WP_CLI::add_command('invoicing', 'WPInv_CLI');
228 228
         }
229 229
         
230 230
         // include css inliner
231
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
232
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
231
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
232
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
233 233
         }
234 234
         
235
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
235
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
236 236
     }
237 237
     
238 238
     public function init() {
239 239
     }
240 240
     
241 241
     public function admin_init() {
242
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
242
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
243 243
     }
244 244
 
245 245
     public function activation_redirect() {
246 246
         // Bail if no activation redirect
247
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
247
+        if (!get_transient('_wpinv_activation_redirect')) {
248 248
             return;
249 249
         }
250 250
 
251 251
         // Delete the redirect transient
252
-        delete_transient( '_wpinv_activation_redirect' );
252
+        delete_transient('_wpinv_activation_redirect');
253 253
 
254 254
         // Bail if activating from network, or bulk
255
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
255
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
256 256
             return;
257 257
         }
258 258
 
259
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
259
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
260 260
         exit;
261 261
     }
262 262
     
263 263
     public function enqueue_scripts() {
264
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
264
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
265 265
         
266
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
267
-        wp_enqueue_style( 'wpinv_front_style' );
266
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
267
+        wp_enqueue_style('wpinv_front_style');
268 268
                
269 269
         // Register scripts
270
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
271
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
270
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
271
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
272 272
 
273 273
         $localize                         = array();
274
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
275
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
274
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
275
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
276 276
         $localize['currency_symbol']      = wpinv_currency_symbol();
277 277
         $localize['currency_pos']         = wpinv_currency_position();
278 278
         $localize['thousand_sep']         = wpinv_thousands_separator();
279 279
         $localize['decimal_sep']          = wpinv_decimal_separator();
280 280
         $localize['decimals']             = wpinv_decimals();
281
-        $localize['txtComplete']          = __( 'Complete', 'invoicing' );
281
+        $localize['txtComplete']          = __('Complete', 'invoicing');
282 282
         $localize['UseTaxes']             = wpinv_use_taxes();
283
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
283
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
284 284
 
285
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
285
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
286 286
         
287
-        wp_enqueue_script( 'jquery-blockui' );
287
+        wp_enqueue_script('jquery-blockui');
288 288
         $autofill_api = wpinv_get_option('address_autofill_api');
289 289
         $autofill_active = wpinv_get_option('address_autofill_active');
290
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
291
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
292
-                wp_dequeue_script( 'google-maps-api' );
290
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
291
+            if (wp_script_is('google-maps-api', 'enqueued')) {
292
+                wp_dequeue_script('google-maps-api');
293 293
             }
294
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
295
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
294
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
295
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
296 296
         }
297 297
 
298
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
299
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
298
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
299
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
300 300
 
301
-        wp_enqueue_script( 'wpinv-front-script' );
302
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
301
+        wp_enqueue_script('wpinv-front-script');
302
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
303 303
 
304
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
305
-        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ),  $version, true );
304
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
305
+        wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script'), $version, true);
306 306
     }
307 307
 
308
-    public function admin_enqueue_scripts( $hook ) {
308
+    public function admin_enqueue_scripts($hook) {
309 309
         global $post, $pagenow;
310 310
         
311 311
         $post_type  = wpinv_admin_post_type();
312
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
313
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
312
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
313
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
314 314
 
315 315
         $jquery_ui_css = false;
316
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
316
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
317 317
             $jquery_ui_css = true;
318
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
318
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
319 319
             $jquery_ui_css = true;
320 320
         }
321
-        if ( $jquery_ui_css ) {
322
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
323
-            wp_enqueue_style( 'jquery-ui-css' );
321
+        if ($jquery_ui_css) {
322
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
323
+            wp_enqueue_style('jquery-ui-css');
324 324
         }
325 325
 
326
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
327
-        wp_enqueue_style( 'wpinv_meta_box_style' );
326
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
327
+        wp_enqueue_style('wpinv_meta_box_style');
328 328
         
329
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
330
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
331
-        wp_enqueue_style( 'wpinv_admin_style' );
329
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
330
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
331
+        wp_enqueue_style('wpinv_admin_style');
332 332
 
333
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
334
-        if ( $page == 'wpinv-subscriptions' ) {
335
-            wp_enqueue_script( 'jquery-ui-datepicker' );
333
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
334
+        if ($page == 'wpinv-subscriptions') {
335
+            wp_enqueue_script('jquery-ui-datepicker');
336 336
         }
337 337
         
338
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
339
-            wp_enqueue_script( 'jquery-ui-datepicker' );
338
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
339
+            wp_enqueue_script('jquery-ui-datepicker');
340 340
         }
341 341
 
342
-        wp_enqueue_style( 'wp-color-picker' );
343
-        wp_enqueue_script( 'wp-color-picker' );
342
+        wp_enqueue_style('wp-color-picker');
343
+        wp_enqueue_script('wp-color-picker');
344 344
         
345
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
345
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
346 346
 
347 347
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
348 348
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -353,21 +353,21 @@  discard block
 block discarded – undo
353 353
             }
354 354
         }
355 355
 
356
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
357
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
356
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
357
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
358 358
 
359
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
360
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
361
-        wp_enqueue_script( 'wpinv-admin-script' );
359
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
360
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
361
+        wp_enqueue_script('wpinv-admin-script');
362 362
         
363 363
         $localize                               = array();
364
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
365
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
366
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
367
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
368
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
369
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
370
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
364
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
365
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
366
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
367
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
368
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
369
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
370
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
371 371
         $localize['tax']                        = wpinv_tax_amount();
372 372
         $localize['discount']                   = wpinv_discount_amount();
373 373
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -375,95 +375,95 @@  discard block
 block discarded – undo
375 375
         $localize['thousand_sep']               = wpinv_thousands_separator();
376 376
         $localize['decimal_sep']                = wpinv_decimal_separator();
377 377
         $localize['decimals']                   = wpinv_decimals();
378
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
379
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
380
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
381
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
382
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
383
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
384
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
385
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
386
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
387
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
388
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
389
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
390
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
391
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
392
-
393
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
394
-
395
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
378
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
379
+        $localize['status_publish']             = wpinv_status_nicename('publish');
380
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
381
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
382
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
383
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
384
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
385
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
386
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
387
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
388
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
389
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
390
+        $localize['action_edit']                = __('Edit', 'invoicing');
391
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
392
+
393
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
394
+
395
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
396 396
 
397 397
         // Load payment form scripts on our admin pages only.
398
-        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
398
+        if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
399 399
 
400
-            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
401
-            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
402
-            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
400
+            wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
401
+            wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
402
+            wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
403 403
 
404
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
405
-            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
404
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
405
+            wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
406 406
         
407
-            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
407
+            wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
408 408
                 'elements'      => $this->form_elements->get_elements(),
409
-                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
409
+                'form_elements' => $this->form_elements->get_form_elements($post->ID),
410 410
                 'all_items'     => $this->form_elements->get_published_items(),
411 411
                 'currency'      => wpinv_currency_symbol(),
412 412
                 'position'      => wpinv_currency_position(),
413 413
                 'decimals'      => (int) wpinv_decimals(),
414 414
                 'thousands_sep' => wpinv_thousands_separator(),
415 415
                 'decimals_sep'  => wpinv_decimal_separator(),
416
-                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
417
-            ) );
416
+                'form_items'    => $this->form_elements->get_form_items($post->ID),
417
+            ));
418 418
 
419
-            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
419
+            wp_enqueue_script('wpinv-admin-payment-form-script');
420 420
         }
421 421
 
422
-        if ( $page == 'wpinv-subscriptions' ) {
423
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
424
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
422
+        if ($page == 'wpinv-subscriptions') {
423
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
424
+            wp_enqueue_script('wpinv-sub-admin-script');
425 425
         }
426 426
 
427 427
     }
428 428
 
429
-    public function admin_body_class( $classes ) {
429
+    public function admin_body_class($classes) {
430 430
         global $pagenow, $post, $current_screen;
431 431
         
432
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
432
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
433 433
             $classes .= ' wpinv-cpt';
434 434
         }
435 435
         
436
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
436
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
437 437
 
438
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
439
-        if ( $add_class ) {
440
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
438
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
439
+        if ($add_class) {
440
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
441 441
         }
442 442
         
443 443
         $settings_class = array();
444
-        if ( $page == 'wpinv-settings' ) {
445
-            if ( !empty( $_REQUEST['tab'] ) ) {
446
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
444
+        if ($page == 'wpinv-settings') {
445
+            if (!empty($_REQUEST['tab'])) {
446
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
447 447
             }
448 448
             
449
-            if ( !empty( $_REQUEST['section'] ) ) {
450
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
449
+            if (!empty($_REQUEST['section'])) {
450
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
451 451
             }
452 452
             
453
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
453
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
454 454
         }
455 455
         
456
-        if ( !empty( $settings_class ) ) {
457
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
456
+        if (!empty($settings_class)) {
457
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
458 458
         }
459 459
         
460 460
         $post_type = wpinv_admin_post_type();
461 461
 
462
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
462
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
463 463
             return $classes .= ' wpinv';
464 464
         }
465 465
         
466
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
466
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
467 467
             $classes .= ' wpi-editable-n';
468 468
         }
469 469
 
@@ -475,21 +475,21 @@  discard block
 block discarded – undo
475 475
     }
476 476
     
477 477
     public function wpinv_actions() {
478
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
479
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
478
+        if (isset($_REQUEST['wpi_action'])) {
479
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
480 480
         }
481 481
     }
482 482
     
483
-    public function pre_get_posts( $wp_query ) {
484
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
485
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
483
+    public function pre_get_posts($wp_query) {
484
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
485
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
486 486
         }
487 487
         
488 488
         return $wp_query;
489 489
     }
490 490
     
491 491
     public function bp_invoicing_init() {
492
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
492
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
493 493
     }
494 494
 
495 495
 	/**
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 */
499 499
 	public function register_widgets() {
500
-		register_widget( "WPInv_Checkout_Widget" );
501
-		register_widget( "WPInv_History_Widget" );
502
-		register_widget( "WPInv_Receipt_Widget" );
503
-		register_widget( "WPInv_Subscriptions_Widget" );
504
-		register_widget( "WPInv_Buy_Item_Widget" );
505
-        register_widget( "WPInv_Messages_Widget" );
506
-        register_widget( 'WPInv_Payment_Form_Widget' );
500
+		register_widget("WPInv_Checkout_Widget");
501
+		register_widget("WPInv_History_Widget");
502
+		register_widget("WPInv_Receipt_Widget");
503
+		register_widget("WPInv_Subscriptions_Widget");
504
+		register_widget("WPInv_Buy_Item_Widget");
505
+        register_widget("WPInv_Messages_Widget");
506
+        register_widget('WPInv_Payment_Form_Widget');
507 507
 	}
508 508
     
509 509
     /**
@@ -512,10 +512,10 @@  discard block
 block discarded – undo
512 512
      * @since 1.0.19
513 513
      * @param int[] $excluded_posts_ids
514 514
      */
515
-    function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
515
+    function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
516 516
 
517 517
         // Ensure that we have an array.
518
-        if ( ! is_array( $excluded_posts_ids ) ) {
518
+        if (!is_array($excluded_posts_ids)) {
519 519
             $excluded_posts_ids = array();
520 520
         }
521 521
 
@@ -523,24 +523,24 @@  discard block
 block discarded – undo
523 523
         $our_pages = array();
524 524
     
525 525
         // Checkout page.
526
-        $our_pages[] = wpinv_get_option( 'checkout_page', false );
526
+        $our_pages[] = wpinv_get_option('checkout_page', false);
527 527
 
528 528
         // Success page.
529
-        $our_pages[] = wpinv_get_option( 'success_page', false );
529
+        $our_pages[] = wpinv_get_option('success_page', false);
530 530
 
531 531
         // Failure page.
532
-        $our_pages[] = wpinv_get_option( 'failure_page', false );
532
+        $our_pages[] = wpinv_get_option('failure_page', false);
533 533
 
534 534
         // History page.
535
-        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
535
+        $our_pages[] = wpinv_get_option('invoice_history_page', false);
536 536
 
537 537
         // Subscriptions page.
538
-        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
538
+        $our_pages[] = wpinv_get_option('invoice_subscription_page', false);
539 539
 
540
-        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
540
+        $our_pages   = array_map('intval', array_filter($our_pages));
541 541
 
542 542
         $excluded_posts_ids = $excluded_posts_ids + $our_pages;
543
-        return array_unique( $excluded_posts_ids );
543
+        return array_unique($excluded_posts_ids);
544 544
 
545 545
     }
546 546
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +743 added lines, -743 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array) $template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,159 +208,159 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
244
+function wpinv_add_body_classes($class) {
245
+	$classes = (array) $class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
 
334 334
     $options = array(
335
-        '1'  => __( 'January', 'invoicing' ),
336
-        '2'  => __( 'February', 'invoicing' ),
337
-        '3'  => __( 'March', 'invoicing' ),
338
-        '4'  => __( 'April', 'invoicing' ),
339
-        '5'  => __( 'May', 'invoicing' ),
340
-        '6'  => __( 'June', 'invoicing' ),
341
-        '7'  => __( 'July', 'invoicing' ),
342
-        '8'  => __( 'August', 'invoicing' ),
343
-        '9'  => __( 'September', 'invoicing' ),
344
-        '10' => __( 'October', 'invoicing' ),
345
-        '11' => __( 'November', 'invoicing' ),
346
-        '12' => __( 'December', 'invoicing' ),
335
+        '1'  => __('January', 'invoicing'),
336
+        '2'  => __('February', 'invoicing'),
337
+        '3'  => __('March', 'invoicing'),
338
+        '4'  => __('April', 'invoicing'),
339
+        '5'  => __('May', 'invoicing'),
340
+        '6'  => __('June', 'invoicing'),
341
+        '7'  => __('July', 'invoicing'),
342
+        '8'  => __('August', 'invoicing'),
343
+        '9'  => __('September', 'invoicing'),
344
+        '10' => __('October', 'invoicing'),
345
+        '11' => __('November', 'invoicing'),
346
+        '12' => __('December', 'invoicing'),
347 347
     );
348 348
 
349 349
     // If no month is selected, default to the current month
350
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
350
+    $selected = empty($selected) ? date('n') : $selected;
351 351
 
352
-    $output = wpinv_html_select( array(
352
+    $output = wpinv_html_select(array(
353 353
         'name'             => $name,
354 354
         'selected'         => $selected,
355 355
         'options'          => $options,
356 356
         'show_option_all'  => false,
357 357
         'show_option_none' => false
358
-    ) );
358
+    ));
359 359
 
360 360
     return $output;
361 361
 }
362 362
 
363
-function wpinv_html_select( $args = array() ) {
363
+function wpinv_html_select($args = array()) {
364 364
     $defaults = array(
365 365
         'options'          => array(),
366 366
         'name'             => null,
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
         'selected'         => 0,
370 370
         'placeholder'      => null,
371 371
         'multiple'         => false,
372
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
373
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
372
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
373
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
374 374
         'data'             => array(),
375 375
         'onchange'         => null,
376 376
         'required'         => false,
@@ -378,74 +378,74 @@  discard block
 block discarded – undo
378 378
         'readonly'         => false,
379 379
     );
380 380
 
381
-    $args = wp_parse_args( $args, $defaults );
381
+    $args = wp_parse_args($args, $defaults);
382 382
 
383 383
     $data_elements = '';
384
-    foreach ( $args['data'] as $key => $value ) {
385
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
384
+    foreach ($args['data'] as $key => $value) {
385
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
386 386
     }
387 387
 
388
-    if( $args['multiple'] ) {
388
+    if ($args['multiple']) {
389 389
         $multiple = ' MULTIPLE';
390 390
     } else {
391 391
         $multiple = '';
392 392
     }
393 393
 
394
-    if( $args['placeholder'] ) {
394
+    if ($args['placeholder']) {
395 395
         $placeholder = $args['placeholder'];
396 396
     } else {
397 397
         $placeholder = '';
398 398
     }
399 399
     
400 400
     $options = '';
401
-    if( !empty( $args['onchange'] ) ) {
402
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
401
+    if (!empty($args['onchange'])) {
402
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
403 403
     }
404 404
     
405
-    if( !empty( $args['required'] ) ) {
405
+    if (!empty($args['required'])) {
406 406
         $options .= ' required="required"';
407 407
     }
408 408
     
409
-    if( !empty( $args['disabled'] ) ) {
409
+    if (!empty($args['disabled'])) {
410 410
         $options .= ' disabled';
411 411
     }
412 412
     
413
-    if( !empty( $args['readonly'] ) ) {
413
+    if (!empty($args['readonly'])) {
414 414
         $options .= ' readonly';
415 415
     }
416 416
 
417
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
418
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
417
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
418
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
419 419
 
420
-    if ( $args['show_option_all'] ) {
421
-        if( $args['multiple'] ) {
422
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
420
+    if ($args['show_option_all']) {
421
+        if ($args['multiple']) {
422
+            $selected = selected(true, in_array(0, $args['selected']), false);
423 423
         } else {
424
-            $selected = selected( $args['selected'], 0, false );
424
+            $selected = selected($args['selected'], 0, false);
425 425
         }
426
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
426
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
427 427
     }
428 428
 
429
-    if ( !empty( $args['options'] ) ) {
429
+    if (!empty($args['options'])) {
430 430
 
431
-        if ( $args['show_option_none'] ) {
432
-            if( $args['multiple'] ) {
433
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
431
+        if ($args['show_option_none']) {
432
+            if ($args['multiple']) {
433
+                $selected = selected(true, in_array("", $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'] === "", true, false );
435
+                $selected = selected($args['selected'] === "", true, false);
436 436
             }
437
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
437
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
438 438
         }
439 439
 
440
-        foreach( $args['options'] as $key => $option ) {
440
+        foreach ($args['options'] as $key => $option) {
441 441
 
442
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
443
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
442
+            if ($args['multiple'] && is_array($args['selected'])) {
443
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
444 444
             } else {
445
-                $selected = selected( $args['selected'], $key, false );
445
+                $selected = selected($args['selected'], $key, false);
446 446
             }
447 447
 
448
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
448
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
449 449
         }
450 450
     }
451 451
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     return $output;
455 455
 }
456 456
 
457
-function wpinv_item_dropdown( $args = array() ) {
457
+function wpinv_item_dropdown($args = array()) {
458 458
     $defaults = array(
459 459
         'name'              => 'wpi_item',
460 460
         'id'                => 'wpi_item',
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
         'multiple'          => false,
463 463
         'selected'          => 0,
464 464
         'number'            => 100,
465
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
466
-        'data'              => array( 'search-type' => 'item' ),
465
+        'placeholder'       => __('Choose a item', 'invoicing'),
466
+        'data'              => array('search-type' => 'item'),
467 467
         'show_option_all'   => false,
468 468
         'show_option_none'  => false,
469 469
         'show_recurring'    => false,
470 470
     );
471 471
 
472
-    $args = wp_parse_args( $args, $defaults );
472
+    $args = wp_parse_args($args, $defaults);
473 473
 
474 474
     $item_args = array(
475 475
         'post_type'      => 'wpi_item',
@@ -478,44 +478,44 @@  discard block
 block discarded – undo
478 478
         'posts_per_page' => $args['number']
479 479
     );
480 480
     
481
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
481
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
482 482
 
483
-    $items      = get_posts( $item_args );
483
+    $items      = get_posts($item_args);
484 484
     $options    = array();
485
-    if ( $items ) {
486
-        foreach ( $items as $item ) {
487
-            $title = esc_html( $item->post_title );
485
+    if ($items) {
486
+        foreach ($items as $item) {
487
+            $title = esc_html($item->post_title);
488 488
             
489
-            if ( !empty( $args['show_recurring'] ) ) {
490
-                $title .= wpinv_get_item_suffix( $item->ID, false );
489
+            if (!empty($args['show_recurring'])) {
490
+                $title .= wpinv_get_item_suffix($item->ID, false);
491 491
             }
492 492
             
493
-            $options[ absint( $item->ID ) ] = $title;
493
+            $options[absint($item->ID)] = $title;
494 494
         }
495 495
     }
496 496
 
497 497
     // This ensures that any selected items are included in the drop down
498
-    if( is_array( $args['selected'] ) ) {
499
-        foreach( $args['selected'] as $item ) {
500
-            if( ! in_array( $item, $options ) ) {
501
-                $title = get_the_title( $item );
502
-                if ( !empty( $args['show_recurring'] ) ) {
503
-                    $title .= wpinv_get_item_suffix( $item, false );
498
+    if (is_array($args['selected'])) {
499
+        foreach ($args['selected'] as $item) {
500
+            if (!in_array($item, $options)) {
501
+                $title = get_the_title($item);
502
+                if (!empty($args['show_recurring'])) {
503
+                    $title .= wpinv_get_item_suffix($item, false);
504 504
                 }
505 505
                 $options[$item] = $title;
506 506
             }
507 507
         }
508
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
509
-        if ( ! in_array( $args['selected'], $options ) ) {
510
-            $title = get_the_title( $args['selected'] );
511
-            if ( !empty( $args['show_recurring'] ) ) {
512
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
508
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
509
+        if (!in_array($args['selected'], $options)) {
510
+            $title = get_the_title($args['selected']);
511
+            if (!empty($args['show_recurring'])) {
512
+                $title .= wpinv_get_item_suffix($args['selected'], false);
513 513
             }
514
-            $options[$args['selected']] = get_the_title( $args['selected'] );
514
+            $options[$args['selected']] = get_the_title($args['selected']);
515 515
         }
516 516
     }
517 517
 
518
-    $output = wpinv_html_select( array(
518
+    $output = wpinv_html_select(array(
519 519
         'name'             => $args['name'],
520 520
         'selected'         => $args['selected'],
521 521
         'id'               => $args['id'],
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
         'show_option_all'  => $args['show_option_all'],
527 527
         'show_option_none' => $args['show_option_none'],
528 528
         'data'             => $args['data'],
529
-    ) );
529
+    ));
530 530
 
531 531
     return $output;
532 532
 }
533 533
 
534
-function wpinv_html_checkbox( $args = array() ) {
534
+function wpinv_html_checkbox($args = array()) {
535 535
     $defaults = array(
536 536
         'name'     => null,
537 537
         'current'  => null,
@@ -542,38 +542,38 @@  discard block
 block discarded – undo
542 542
         )
543 543
     );
544 544
 
545
-    $args = wp_parse_args( $args, $defaults );
545
+    $args = wp_parse_args($args, $defaults);
546 546
 
547
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
547
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
548 548
     $options = '';
549
-    if ( ! empty( $args['options']['disabled'] ) ) {
549
+    if (!empty($args['options']['disabled'])) {
550 550
         $options .= ' disabled="disabled"';
551
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
551
+    } elseif (!empty($args['options']['readonly'])) {
552 552
         $options .= ' readonly';
553 553
     }
554 554
 
555
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
555
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
556 556
 
557 557
     return $output;
558 558
 }
559 559
 
560
-function wpinv_html_text( $args = array() ) {
560
+function wpinv_html_text($args = array()) {
561 561
     // Backwards compatibility
562
-    if ( func_num_args() > 1 ) {
562
+    if (func_num_args() > 1) {
563 563
         $args = func_get_args();
564 564
 
565 565
         $name  = $args[0];
566
-        $value = isset( $args[1] ) ? $args[1] : '';
567
-        $label = isset( $args[2] ) ? $args[2] : '';
568
-        $desc  = isset( $args[3] ) ? $args[3] : '';
566
+        $value = isset($args[1]) ? $args[1] : '';
567
+        $label = isset($args[2]) ? $args[2] : '';
568
+        $desc  = isset($args[3]) ? $args[3] : '';
569 569
     }
570 570
 
571 571
     $defaults = array(
572 572
         'id'           => '',
573
-        'name'         => isset( $name )  ? $name  : 'text',
574
-        'value'        => isset( $value ) ? $value : null,
575
-        'label'        => isset( $label ) ? $label : null,
576
-        'desc'         => isset( $desc )  ? $desc  : null,
573
+        'name'         => isset($name) ? $name : 'text',
574
+        'value'        => isset($value) ? $value : null,
575
+        'label'        => isset($label) ? $label : null,
576
+        'desc'         => isset($desc) ? $desc : null,
577 577
         'placeholder'  => '',
578 578
         'class'        => 'regular-text',
579 579
         'disabled'     => false,
@@ -583,51 +583,51 @@  discard block
 block discarded – undo
583 583
         'data'         => false
584 584
     );
585 585
 
586
-    $args = wp_parse_args( $args, $defaults );
586
+    $args = wp_parse_args($args, $defaults);
587 587
 
588
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
588
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
589 589
     $options = '';
590
-    if( $args['required'] ) {
590
+    if ($args['required']) {
591 591
         $options .= ' required="required"';
592 592
     }
593
-    if( $args['readonly'] ) {
593
+    if ($args['readonly']) {
594 594
         $options .= ' readonly';
595 595
     }
596
-    if( $args['readonly'] ) {
596
+    if ($args['readonly']) {
597 597
         $options .= ' readonly';
598 598
     }
599 599
 
600 600
     $data = '';
601
-    if ( !empty( $args['data'] ) ) {
602
-        foreach ( $args['data'] as $key => $value ) {
603
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
601
+    if (!empty($args['data'])) {
602
+        foreach ($args['data'] as $key => $value) {
603
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
604 604
         }
605 605
     }
606 606
 
607
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
608
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
609
-    if ( ! empty( $args['desc'] ) ) {
610
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
607
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
608
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
609
+    if (!empty($args['desc'])) {
610
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
611 611
     }
612 612
 
613
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
613
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
614 614
 
615 615
     $output .= '</span>';
616 616
 
617 617
     return $output;
618 618
 }
619 619
 
620
-function wpinv_html_date_field( $args = array() ) {
621
-    if( empty( $args['class'] ) ) {
620
+function wpinv_html_date_field($args = array()) {
621
+    if (empty($args['class'])) {
622 622
         $args['class'] = 'wpiDatepicker';
623
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
623
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
624 624
         $args['class'] .= ' wpiDatepicker';
625 625
     }
626 626
 
627
-    return wpinv_html_text( $args );
627
+    return wpinv_html_text($args);
628 628
 }
629 629
 
630
-function wpinv_html_textarea( $args = array() ) {
630
+function wpinv_html_textarea($args = array()) {
631 631
     $defaults = array(
632 632
         'name'        => 'textarea',
633 633
         'value'       => null,
@@ -638,31 +638,31 @@  discard block
 block discarded – undo
638 638
         'placeholder' => '',
639 639
     );
640 640
 
641
-    $args = wp_parse_args( $args, $defaults );
641
+    $args = wp_parse_args($args, $defaults);
642 642
 
643
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
643
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
644 644
     $disabled = '';
645
-    if( $args['disabled'] ) {
645
+    if ($args['disabled']) {
646 646
         $disabled = ' disabled="disabled"';
647 647
     }
648 648
 
649
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
650
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
651
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
649
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
650
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
651
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
652 652
 
653
-    if ( ! empty( $args['desc'] ) ) {
654
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
653
+    if (!empty($args['desc'])) {
654
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
655 655
     }
656 656
     $output .= '</span>';
657 657
 
658 658
     return $output;
659 659
 }
660 660
 
661
-function wpinv_html_ajax_user_search( $args = array() ) {
661
+function wpinv_html_ajax_user_search($args = array()) {
662 662
     $defaults = array(
663 663
         'name'        => 'user_id',
664 664
         'value'       => null,
665
-        'placeholder' => __( 'Enter username', 'invoicing' ),
665
+        'placeholder' => __('Enter username', 'invoicing'),
666 666
         'label'       => null,
667 667
         'desc'        => null,
668 668
         'class'       => '',
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         'data'        => false
672 672
     );
673 673
 
674
-    $args = wp_parse_args( $args, $defaults );
674
+    $args = wp_parse_args($args, $defaults);
675 675
 
676 676
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
677 677
 
678 678
     $output  = '<span class="wpinv_user_search_wrap">';
679
-        $output .= wpinv_html_text( $args );
680
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
679
+        $output .= wpinv_html_text($args);
680
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
681 681
     $output .= '</span>';
682 682
 
683 683
     return $output;
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 function wpinv_ip_geolocation() {
687 687
     global $wpinv_euvat;
688 688
     
689
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
689
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
690 690
     $content    = '';
691 691
     $iso        = '';
692 692
     $country    = '';
@@ -697,69 +697,69 @@  discard block
 block discarded – undo
697 697
     $credit     = '';
698 698
     $address    = '';
699 699
     
700
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
700
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
701 701
         try {
702 702
             $iso        = $geoip2_city->country->isoCode;
703 703
             $country    = $geoip2_city->country->name;
704
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
704
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
705 705
             $city       = $geoip2_city->city->name;
706 706
             $longitude  = $geoip2_city->location->longitude;
707 707
             $latitude   = $geoip2_city->location->latitude;
708
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
709
-        } catch( Exception $e ) { }
708
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
709
+        } catch (Exception $e) { }
710 710
     }
711 711
     
712
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
712
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
713 713
         try {
714
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
714
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
715 715
             
716
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
716
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
717 717
                 $iso        = $load_xml->geoplugin_countryCode;
718 718
                 $country    = $load_xml->geoplugin_countryName;
719
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
720
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
719
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
720
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
721 721
                 $longitude  = $load_xml->geoplugin_longitude;
722 722
                 $latitude   = $load_xml->geoplugin_latitude;
723 723
                 $credit     = $load_xml->geoplugin_credit;
724
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
724
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
725 725
             }
726
-        } catch( Exception $e ) { }
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( $iso && $longitude && $latitude ) {
730
-        if ( $city ) {
729
+    if ($iso && $longitude && $latitude) {
730
+        if ($city) {
731 731
             $address .= $city . ', ';
732 732
         }
733 733
         
734
-        if ( $region ) {
734
+        if ($region) {
735 735
             $address .= $region . ', ';
736 736
         }
737 737
         
738 738
         $address .= $country . ' (' . $iso . ')';
739
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
740
-        $content .= '<p>'. $credit . '</p>';
739
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
740
+        $content .= '<p>' . $credit . '</p>';
741 741
     } else {
742
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
742
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
743 743
     }
744 744
     ?>
745 745
 <!DOCTYPE html>
746
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
746
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
747 747
 <body>
748
-    <?php if ( $latitude && $latitude ) { ?>
748
+    <?php if ($latitude && $latitude) { ?>
749 749
     <div id="map"></div>
750 750
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
751 751
         <script type="text/javascript">
752 752
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
753 753
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
754 754
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
755
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
755
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
756 756
 
757 757
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
758 758
 
759 759
         var marker = new L.Marker(latlng);
760 760
         map.addLayer(marker);
761 761
 
762
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
762
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
763 763
     </script>
764 764
     <?php } ?>
765 765
     <div style="height:100px"><?php echo $content; ?></div>
@@ -767,18 +767,18 @@  discard block
 block discarded – undo
767 767
 <?php
768 768
     exit;
769 769
 }
770
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
771
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
770
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
771
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
772 772
 
773 773
 // Set up the template for the invoice.
774
-function wpinv_template( $template ) {
774
+function wpinv_template($template) {
775 775
     global $post, $wp_query;
776 776
     
777
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
778
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
779
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
777
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
778
+        if (wpinv_user_can_view_invoice($post->ID)) {
779
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
780 780
         } else {
781
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
781
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
782 782
         }
783 783
     }
784 784
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 
788 788
 function wpinv_get_business_address() {
789 789
     $business_address   = wpinv_store_address();
790
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
790
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
791 791
     
792 792
     /*
793 793
     $default_country    = wpinv_get_default_country();
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
     
812 812
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
813 813
     
814
-    return apply_filters( 'wpinv_get_business_address', $business_address );
814
+    return apply_filters('wpinv_get_business_address', $business_address);
815 815
 }
816 816
 
817 817
 function wpinv_display_from_address() {
@@ -821,107 +821,107 @@  discard block
 block discarded – undo
821 821
     if (empty($from_name)) {
822 822
         $from_name = wpinv_get_business_name();
823 823
     }
824
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
824
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
825 825
     <div class="wrapper col-xs-10">
826
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
827
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
828
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
826
+        <div class="name"><?php echo esc_html($from_name); ?></div>
827
+        <?php if ($address = wpinv_get_business_address()) { ?>
828
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
829 829
         <?php } ?>
830
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
831
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
830
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
831
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
832 832
         <?php } ?>
833 833
     </div>
834 834
     <?php
835 835
 }
836 836
 
837
-function wpinv_watermark( $id = 0 ) {
838
-    $output = wpinv_get_watermark( $id );
837
+function wpinv_watermark($id = 0) {
838
+    $output = wpinv_get_watermark($id);
839 839
     
840
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
840
+    return apply_filters('wpinv_get_watermark', $output, $id);
841 841
 }
842 842
 
843
-function wpinv_get_watermark( $id ) {
844
-    if ( !$id > 0 ) {
843
+function wpinv_get_watermark($id) {
844
+    if (!$id > 0) {
845 845
         return NULL;
846 846
     }
847
-    $invoice = wpinv_get_invoice( $id );
847
+    $invoice = wpinv_get_invoice($id);
848 848
     
849
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
850
-        if ( $invoice->is_paid() ) {
851
-            return __( 'Paid', 'invoicing' );
849
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
850
+        if ($invoice->is_paid()) {
851
+            return __('Paid', 'invoicing');
852 852
         }
853
-        if ( $invoice->is_refunded() ) {
854
-            return __( 'Refunded', 'invoicing' );
853
+        if ($invoice->is_refunded()) {
854
+            return __('Refunded', 'invoicing');
855 855
         }
856
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
857
-            return __( 'Cancelled', 'invoicing' );
856
+        if ($invoice->has_status(array('wpi-cancelled'))) {
857
+            return __('Cancelled', 'invoicing');
858 858
         }
859 859
     }
860 860
     
861 861
     return NULL;
862 862
 }
863 863
 
864
-function wpinv_display_invoice_details( $invoice ) {
864
+function wpinv_display_invoice_details($invoice) {
865 865
     global $wpinv_euvat;
866 866
     
867 867
     $invoice_id = $invoice->ID;
868 868
     $vat_name   = $wpinv_euvat->get_vat_name();
869 869
     $use_taxes  = wpinv_use_taxes();
870 870
     
871
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
871
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
872 872
     ?>
873 873
     <table class="table table-bordered table-sm">
874
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
874
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
875 875
             <tr class="wpi-row-number">
876
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
877
-                <td><?php echo esc_html( $invoice_number ); ?></td>
876
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
877
+                <td><?php echo esc_html($invoice_number); ?></td>
878 878
             </tr>
879 879
         <?php } ?>
880 880
         <tr class="wpi-row-status">
881
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
882
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
881
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
882
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
883 883
         </tr>
884
-        <?php if ( $invoice->is_renewal() ) { ?>
884
+        <?php if ($invoice->is_renewal()) { ?>
885 885
         <tr class="wpi-row-parent">
886
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
887
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
886
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
887
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
888 888
         </tr>
889 889
         <?php } ?>
890
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
890
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
891 891
             <tr class="wpi-row-gateway">
892
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
892
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
893 893
                 <td><?php echo $gateway_name; ?></td>
894 894
             </tr>
895 895
         <?php } ?>
896
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
896
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
897 897
             <tr class="wpi-row-date">
898
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
898
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
899 899
                 <td><?php echo $invoice_date; ?></td>
900 900
             </tr>
901 901
         <?php } ?>
902
-        <?php do_action( 'wpinv_display_details_before_due_date', $invoice_id ); ?>
903
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
902
+        <?php do_action('wpinv_display_details_before_due_date', $invoice_id); ?>
903
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
904 904
             <tr class="wpi-row-date">
905
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
905
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
906 906
                 <td><?php echo $due_date; ?></td>
907 907
             </tr>
908 908
         <?php } ?>
909
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
910
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
909
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
910
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
911 911
             <tr class="wpi-row-ovatno">
912
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
912
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
913 913
                 <td><?php echo $owner_vat_number; ?></td>
914 914
             </tr>
915 915
         <?php } ?>
916
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
916
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
917 917
             <tr class="wpi-row-uvatno">
918
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
918
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
919 919
                 <td><?php echo $user_vat_number; ?></td>
920 920
             </tr>
921 921
         <?php } ?>
922 922
         <tr class="table-active tr-total wpi-row-total">
923
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
924
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
923
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
924
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
925 925
         </tr>
926 926
     </table>
927 927
 <?php
@@ -937,84 +937,84 @@  discard block
 block discarded – undo
937 937
  * @param  string $separator How to separate address lines.
938 938
  * @return string
939 939
  */
940
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
940
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
941 941
 
942 942
     // Retrieve the address markup...
943
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
944
-    $format = wpinv_get_full_address_format( $country );
943
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
944
+    $format = wpinv_get_full_address_format($country);
945 945
 
946 946
     // ... and the replacements.
947
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
947
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
948 948
 
949
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
949
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
950 950
     
951 951
 	// Remove unavailable tags.
952
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
952
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
953 953
 
954 954
     // Clean up white space.
955
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
956
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
955
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
956
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
957 957
     
958 958
     // Break newlines apart and remove empty lines/trim commas and white space.
959
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
959
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
960 960
 
961 961
     // Add html breaks.
962
-	$formatted_address = implode( $separator, $formatted_address );
962
+	$formatted_address = implode($separator, $formatted_address);
963 963
 
964 964
 	// We're done!
965 965
 	return $formatted_address;
966 966
     
967 967
 }
968 968
 
969
-function wpinv_display_to_address( $invoice_id = 0 ) {
970
-    $invoice = wpinv_get_invoice( $invoice_id );
969
+function wpinv_display_to_address($invoice_id = 0) {
970
+    $invoice = wpinv_get_invoice($invoice_id);
971 971
     
972
-    if ( empty( $invoice ) ) {
972
+    if (empty($invoice)) {
973 973
         return NULL;
974 974
     }
975 975
     
976 976
     $billing_details = $invoice->get_user_info();
977
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
977
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
978 978
     $output .= '<div class="wrapper col-xs-10">';
979 979
     
980 980
     ob_start();
981
-    do_action( 'wpinv_display_to_address_top', $invoice );
981
+    do_action('wpinv_display_to_address_top', $invoice);
982 982
     $output .= ob_get_clean();
983 983
     
984
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
984
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
985 985
 
986
-    if ( $address_row ) {
986
+    if ($address_row) {
987 987
         $output .= '<div class="address">' . $address_row . '</div>';
988 988
     }
989 989
 
990
-    if ( $phone = $invoice->get_phone() ) {
991
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
990
+    if ($phone = $invoice->get_phone()) {
991
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
992 992
     }
993
-    if ( $email = $invoice->get_email() ) {
994
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
993
+    if ($email = $invoice->get_email()) {
994
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
995 995
     }
996 996
 
997 997
     ob_start();
998
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
998
+    do_action('wpinv_display_to_address_bottom', $invoice);
999 999
     $output .= ob_get_clean();
1000 1000
     
1001 1001
     $output .= '</div>';
1002
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1002
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1003 1003
 
1004 1004
     echo $output;
1005 1005
 }
1006 1006
 
1007
-function wpinv_display_line_items( $invoice_id = 0 ) {
1007
+function wpinv_display_line_items($invoice_id = 0) {
1008 1008
     global $wpinv_euvat, $ajax_cart_details;
1009
-    $invoice            = wpinv_get_invoice( $invoice_id );
1009
+    $invoice            = wpinv_get_invoice($invoice_id);
1010 1010
     $quantities_enabled = wpinv_item_quantities_enabled();
1011 1011
     $use_taxes          = wpinv_use_taxes();
1012
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
1012
+    if (!$use_taxes && (float) $invoice->get_tax() > 0) {
1013 1013
         $use_taxes = true;
1014 1014
     }
1015
-    $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1016
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1017
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1015
+    $zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
1016
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1017
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1018 1018
 
1019 1019
     $cart_details       = $invoice->get_cart_details();
1020 1020
     $ajax_cart_details  = $cart_details;
@@ -1023,67 +1023,67 @@  discard block
 block discarded – undo
1023 1023
     <table class="table table-sm table-bordered">
1024 1024
         <thead>
1025 1025
             <tr>
1026
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1027
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1026
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1027
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1028 1028
                 <?php if ($quantities_enabled) { ?>
1029
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1029
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1030 1030
                 <?php } ?>
1031 1031
                 <?php if ($use_taxes && !$zero_tax) { ?>
1032 1032
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1033 1033
                 <?php } ?>
1034
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1034
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1035 1035
             </tr>
1036 1036
         </thead>
1037 1037
         <tbody>
1038 1038
         <?php 
1039
-            if ( !empty( $cart_details ) ) {
1040
-                do_action( 'wpinv_display_line_items_start', $invoice );
1039
+            if (!empty($cart_details)) {
1040
+                do_action('wpinv_display_line_items_start', $invoice);
1041 1041
 
1042 1042
                 $count = 0;
1043 1043
                 $cols  = 3;
1044
-                foreach ( $cart_details as $key => $cart_item ) {
1045
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1046
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1047
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1048
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1044
+                foreach ($cart_details as $key => $cart_item) {
1045
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1046
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1047
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1048
+                    $quantity   = !empty($cart_item['quantity']) && (int) $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1049 1049
 
1050
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1050
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1051 1051
                     $summary    = '';
1052
-	                $item_name    = '';
1052
+	                $item_name = '';
1053 1053
                     $cols       = 3;
1054
-                    if ( !empty($item) ) {
1054
+                    if (!empty($item)) {
1055 1055
                         $item_name  = $item->get_name();
1056 1056
                         $summary    = $item->get_summary();
1057 1057
                     }
1058
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1058
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1059 1059
 
1060
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1060
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1061 1061
 
1062 1062
                     $item_tax       = '';
1063 1063
                     $tax_rate       = '';
1064
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1065
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1066
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1067
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1064
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1065
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1066
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1067
+                        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1068 1068
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1069 1069
                     }
1070 1070
 
1071 1071
                     $line_item_tax = $item_tax . $tax_rate;
1072 1072
 
1073
-                    if ( $line_item_tax === '' ) {
1073
+                    if ($line_item_tax === '') {
1074 1074
                         $line_item_tax = 0; // Zero tax
1075 1075
                     }
1076 1076
 
1077
-                    $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols );
1077
+                    $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols);
1078 1078
 
1079
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1080
-                        $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1081
-                        if ( $summary !== '' ) {
1082
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1079
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1080
+                        $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1081
+                        if ($summary !== '') {
1082
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1083 1083
                         }
1084 1084
                         $line_item .= '</td>';
1085 1085
 
1086
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1086
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1087 1087
                         if ($quantities_enabled) {
1088 1088
                             $cols++;
1089 1089
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1092,55 +1092,55 @@  discard block
 block discarded – undo
1092 1092
                             $cols++;
1093 1093
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1094 1094
                         }
1095
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1095
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1096 1096
                     $line_item .= '</tr>';
1097 1097
 
1098
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1098
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1099 1099
 
1100 1100
                     $count++;
1101 1101
                 }
1102 1102
 
1103
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1103
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1104 1104
                 ?>
1105 1105
                 <tr class="row-sub-total row_odd">
1106
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1107
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1106
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1107
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1108 1108
                 </tr>
1109 1109
                 <?php
1110
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1110
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1111 1111
                 
1112
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1113
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1112
+                if (wpinv_discount($invoice_id, false) > 0) {
1113
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1114 1114
                     ?>
1115 1115
                         <tr class="row-discount">
1116
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1117
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1116
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1117
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1118 1118
                         </tr>
1119 1119
                     <?php
1120
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1120
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1121 1121
                 }
1122 1122
 
1123
-                if ( $use_taxes ) {
1124
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1123
+                if ($use_taxes) {
1124
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1125 1125
                     ?>
1126 1126
                     <tr class="row-tax">
1127
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1128
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1127
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1128
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1129 1129
                     </tr>
1130 1130
                     <?php
1131
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1131
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1132 1132
                 }
1133 1133
 
1134
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1134
+                do_action('wpinv_display_before_total', $invoice, $cols);
1135 1135
                 ?>
1136 1136
                 <tr class="table-active row-total">
1137
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1138
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1137
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1138
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1139 1139
                 </tr>
1140 1140
                 <?php
1141
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1141
+                do_action('wpinv_display_after_total', $invoice, $cols);
1142 1142
 
1143
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1143
+                do_action('wpinv_display_line_end', $invoice, $cols);
1144 1144
             }
1145 1145
         ?>
1146 1146
         </tbody>
@@ -1152,56 +1152,56 @@  discard block
 block discarded – undo
1152 1152
 /**
1153 1153
  * @param WPInv_Invoice $invoice
1154 1154
  */
1155
-function wpinv_display_invoice_notes( $invoice ) {
1155
+function wpinv_display_invoice_notes($invoice) {
1156 1156
 
1157
-    $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' );
1157
+    $notes = wpinv_get_invoice_notes($invoice->ID, 'customer');
1158 1158
 
1159
-    if ( empty( $notes ) ) {
1159
+    if (empty($notes)) {
1160 1160
         return;
1161 1161
     }
1162 1162
 
1163 1163
     echo '<div class="wpi_invoice_notes_container">';
1164
-    echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>';
1164
+    echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>';
1165 1165
     echo '<ul class="wpi_invoice_notes">';
1166 1166
 
1167
-    foreach( $notes as $note ) {
1168
-        wpinv_get_invoice_note_line_item( $note );
1167
+    foreach ($notes as $note) {
1168
+        wpinv_get_invoice_note_line_item($note);
1169 1169
     }
1170 1170
 
1171 1171
     echo '</ul>';
1172 1172
     echo '</div>';
1173 1173
 }
1174
-add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' );
1174
+add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes');
1175 1175
 
1176
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1176
+function wpinv_display_invoice_totals($invoice_id = 0) {
1177 1177
     $use_taxes = wpinv_use_taxes();
1178 1178
 
1179
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1179
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1180 1180
     ?>
1181 1181
     <table class="table table-sm table-bordered table-responsive">
1182 1182
         <tbody>
1183
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1183
+            <?php do_action('wpinv_before_display_totals'); ?>
1184 1184
             <tr class="row-sub-total">
1185
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1186
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1185
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1186
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1187 1187
             </tr>
1188
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1189
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1188
+            <?php do_action('wpinv_after_display_totals'); ?>
1189
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1190 1190
                 <tr class="row-discount">
1191
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1192
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1191
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1192
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1193 1193
                 </tr>
1194
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1194
+            <?php do_action('wpinv_after_display_discount'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $use_taxes ) { ?>
1196
+            <?php if ($use_taxes) { ?>
1197 1197
             <tr class="row-tax">
1198
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1199
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1198
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1199
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1200 1200
             </tr>
1201
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1201
+            <?php do_action('wpinv_after_display_tax'); ?>
1202 1202
             <?php } ?>
1203
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1204
-                <?php foreach ( $fees as $fee ) { ?>
1203
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1204
+                <?php foreach ($fees as $fee) { ?>
1205 1205
                     <tr class="row-fee">
1206 1206
                         <td class="rate"><?php echo $fee['label']; ?></td>
1207 1207
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1209,82 +1209,82 @@  discard block
 block discarded – undo
1209 1209
                 <?php } ?>
1210 1210
             <?php } ?>
1211 1211
             <tr class="table-active row-total">
1212
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1213
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1212
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1213
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1214 1214
             </tr>
1215
-            <?php do_action( 'wpinv_after_totals' ); ?>
1215
+            <?php do_action('wpinv_after_totals'); ?>
1216 1216
         </tbody>
1217 1217
 
1218 1218
     </table>
1219 1219
 
1220
-    <?php do_action( 'wpinv_after_totals_table' );
1220
+    <?php do_action('wpinv_after_totals_table');
1221 1221
 }
1222 1222
 
1223
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1224
-    $invoice = wpinv_get_invoice( $invoice_id );
1223
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1224
+    $invoice = wpinv_get_invoice($invoice_id);
1225 1225
 
1226 1226
     ob_start();
1227
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1228
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1227
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1228
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1229 1229
         ?>
1230 1230
         <div class="wpi-payment-info">
1231
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1232
-            <?php if ( $gateway_title ) { ?>
1233
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1231
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1232
+            <?php if ($gateway_title) { ?>
1233
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1234 1234
             <?php } ?>
1235 1235
         </div>
1236 1236
         <?php
1237 1237
     }
1238
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1238
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1239 1239
     $outout = ob_get_clean();
1240 1240
 
1241
-    if ( $echo ) {
1241
+    if ($echo) {
1242 1242
         echo $outout;
1243 1243
     } else {
1244 1244
         return $outout;
1245 1245
     }
1246 1246
 }
1247 1247
 
1248
-function wpinv_display_style( $invoice ) {
1249
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1248
+function wpinv_display_style($invoice) {
1249
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1250 1250
 
1251
-    wp_print_styles( 'open-sans' );
1252
-    wp_print_styles( 'wpinv-single-style' );
1251
+    wp_print_styles('open-sans');
1252
+    wp_print_styles('wpinv-single-style');
1253 1253
 
1254 1254
     $custom_css = wpinv_get_option('template_custom_css');
1255
-    if(isset($custom_css) && !empty($custom_css)){
1256
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1257
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1255
+    if (isset($custom_css) && !empty($custom_css)) {
1256
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1257
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1258 1258
         echo '<style type="text/css">';
1259 1259
         echo $custom_css;
1260 1260
         echo '</style>';
1261 1261
     }
1262 1262
 }
1263
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1264
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1263
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1264
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1265 1265
 
1266 1266
 function wpinv_checkout_billing_details() {
1267
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
1267
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
1268 1268
     if (empty($invoice_id)) {
1269
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1269
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1270 1270
         return null;
1271 1271
     }
1272 1272
 
1273
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1273
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1274 1274
     if (empty($invoice)) {
1275
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1275
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1276 1276
         return null;
1277 1277
     }
1278 1278
     $user_id        = $invoice->get_user_id();
1279 1279
     $user_info      = $invoice->get_user_info();
1280
-    $address_info   = wpinv_get_user_address( $user_id );
1280
+    $address_info   = wpinv_get_user_address($user_id);
1281 1281
 
1282
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1282
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1283 1283
         $user_info['first_name'] = $user_info['first_name'];
1284 1284
         $user_info['last_name'] = $user_info['last_name'];
1285 1285
     }
1286 1286
 
1287
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1287
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1288 1288
         $user_info['country']   = $address_info['country'];
1289 1289
         $user_info['state']     = $address_info['state'];
1290 1290
         $user_info['city']      = $address_info['city'];
@@ -1300,99 +1300,99 @@  discard block
 block discarded – undo
1300 1300
         'address'
1301 1301
     );
1302 1302
 
1303
-    foreach ( $address_fields as $field ) {
1304
-        if ( empty( $user_info[$field] ) ) {
1303
+    foreach ($address_fields as $field) {
1304
+        if (empty($user_info[$field])) {
1305 1305
             $user_info[$field] = $address_info[$field];
1306 1306
         }
1307 1307
     }
1308 1308
 
1309
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1309
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1310 1310
 }
1311 1311
 
1312 1312
 function wpinv_admin_get_line_items($invoice = array()) {
1313 1313
     $item_quantities    = wpinv_item_quantities_enabled();
1314 1314
     $use_taxes          = wpinv_use_taxes();
1315 1315
 
1316
-    if ( empty( $invoice ) ) {
1316
+    if (empty($invoice)) {
1317 1317
         return NULL;
1318 1318
     }
1319 1319
 
1320 1320
     $cart_items = $invoice->get_cart_details();
1321
-    if ( empty( $cart_items ) ) {
1321
+    if (empty($cart_items)) {
1322 1322
         return NULL;
1323 1323
     }
1324 1324
 
1325 1325
     ob_start();
1326 1326
 
1327
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1327
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1328 1328
 
1329 1329
     $count = 0;
1330
-    foreach ( $cart_items as $key => $cart_item ) {
1330
+    foreach ($cart_items as $key => $cart_item) {
1331 1331
         $item_id    = $cart_item['id'];
1332
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1332
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1333 1333
 
1334 1334
         if (empty($wpi_item)) {
1335 1335
             continue;
1336 1336
         }
1337 1337
 
1338
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1339
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1338
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1339
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1341 1341
         $can_remove     = true;
1342 1342
 
1343
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1343
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1344 1344
 
1345 1345
         $item_tax       = '';
1346 1346
         $tax_rate       = '';
1347
-        if ( $invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1348
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1349
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1350
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1347
+        if ($invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1348
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1349
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1350
+            $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1351 1351
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1352 1352
         }
1353 1353
         $line_item_tax = $item_tax . $tax_rate;
1354 1354
 
1355
-        if ( $line_item_tax === '' ) {
1355
+        if ($line_item_tax === '') {
1356 1356
             $line_item_tax = 0; // Zero tax
1357 1357
         }
1358 1358
 
1359
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1359
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1360 1360
             $line_item .= '<td class="id">' . $item_id . '</td>';
1361
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1362
-            if ( $summary !== '' ) {
1363
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1361
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1362
+            if ($summary !== '') {
1363
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1364 1364
             }
1365 1365
             $line_item .= '</td>';
1366 1366
             $line_item .= '<td class="price">' . $item_price . '</td>';
1367 1367
             
1368
-            if ( $item_quantities ) {
1369
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1368
+            if ($item_quantities) {
1369
+                if (count($cart_items) == 1 && $quantity <= 1) {
1370 1370
                     $can_remove = false;
1371 1371
                 }
1372 1372
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1373 1373
             } else {
1374
-                if ( count( $cart_items ) == 1 ) {
1374
+                if (count($cart_items) == 1) {
1375 1375
                     $can_remove = false;
1376 1376
                 }
1377 1377
             }
1378 1378
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1379 1379
             
1380
-            if ( $use_taxes ) {
1380
+            if ($use_taxes) {
1381 1381
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1382 1382
             }
1383 1383
             $line_item .= '<td class="action">';
1384
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
1384
+            if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1385 1385
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1386 1386
             }
1387 1387
             $line_item .= '</td>';
1388 1388
         $line_item .= '</tr>';
1389 1389
 
1390
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1390
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1391 1391
 
1392 1392
         $count++;
1393 1393
     } 
1394 1394
 
1395
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1395
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1396 1396
 
1397 1397
     return ob_get_clean();
1398 1398
 }
@@ -1404,32 +1404,32 @@  discard block
 block discarded – undo
1404 1404
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1405 1405
 
1406 1406
     //Maybe update the prices
1407
-    if(! empty( $_GET['wpi_dynamic_item'] ) && ! empty( $_GET['wpi_dynamic_price'] ) ) {
1407
+    if (!empty($_GET['wpi_dynamic_item']) && !empty($_GET['wpi_dynamic_price'])) {
1408 1408
 
1409 1409
         //If the invoice exists, update it with new pricing details
1410
-        if (! empty( $wpi_checkout_id ) ) {
1410
+        if (!empty($wpi_checkout_id)) {
1411 1411
 
1412 1412
             $_invoice       = wpinv_get_invoice_cart();
1413 1413
             $_cart_details  = $_invoice->get_cart_details();
1414
-            $_dynamic_item  = sanitize_text_field( $_GET['wpi_dynamic_item'] );
1414
+            $_dynamic_item  = sanitize_text_field($_GET['wpi_dynamic_item']);
1415 1415
 
1416 1416
             //First, fetch the item
1417
-            $item    = new WPInv_Item( $_dynamic_item );
1417
+            $item = new WPInv_Item($_dynamic_item);
1418 1418
     
1419 1419
             //Next, ensure it supports dynamic pricing...
1420
-            if( $item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing() ) {
1420
+            if ($item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing()) {
1421 1421
                 
1422 1422
                 //... and that the new price is not lower than the minimum price
1423
-                $_dynamic_price = (float) wpinv_sanitize_amount( sanitize_text_field( $_GET['wpi_dynamic_price'] ) );
1424
-                if( $_dynamic_price < $item->get_minimum_price() ) {
1423
+                $_dynamic_price = (float) wpinv_sanitize_amount(sanitize_text_field($_GET['wpi_dynamic_price']));
1424
+                if ($_dynamic_price < $item->get_minimum_price()) {
1425 1425
                     $_dynamic_price = $item->get_minimum_price();
1426 1426
                 }
1427 1427
 
1428 1428
                 //Finally, update our invoice with the new price
1429
-                if ( !empty( $_cart_details ) ) {
1429
+                if (!empty($_cart_details)) {
1430 1430
 
1431
-                    foreach ( $_cart_details as $key => $item ) {
1432
-                        if ( !empty( $item['id'] ) && $_dynamic_item == $item['id'] ) {
1431
+                    foreach ($_cart_details as $key => $item) {
1432
+                        if (!empty($item['id']) && $_dynamic_item == $item['id']) {
1433 1433
                             $_cart_details[$key]['custom_price'] = $_dynamic_price;
1434 1434
                             $_cart_details[$key]['item_price']   = $_dynamic_price;
1435 1435
                         }
@@ -1437,8 +1437,8 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
                     $_meta = $_invoice->get_meta();
1439 1439
                     $_meta['cart_details'] = $_cart_details;
1440
-                    $_invoice->set( 'payment_meta', $_meta );
1441
-                    $_invoice->set( 'cart_details', $_cart_details );
1440
+                    $_invoice->set('payment_meta', $_meta);
1441
+                    $_invoice->set('cart_details', $_cart_details);
1442 1442
                     $_invoice->recalculate_totals();
1443 1443
 
1444 1444
                 }
@@ -1449,60 +1449,60 @@  discard block
 block discarded – undo
1449 1449
 
1450 1450
     }
1451 1451
 
1452
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1452
+    $form_action = esc_url(wpinv_get_checkout_uri());
1453 1453
 
1454 1454
     ob_start();
1455
-	    do_action( 'wpinv_checkout_content_before' );
1455
+	    do_action('wpinv_checkout_content_before');
1456 1456
         echo '<div id="wpinv_checkout_wrap">';
1457 1457
 
1458
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1458
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1459 1459
             ?>
1460 1460
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1461
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1461
+                <?php do_action('wpinv_before_checkout_form'); ?>
1462 1462
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1463 1463
                     <?php
1464
-                    do_action( 'wpinv_checkout_form_top' );
1465
-                    do_action( 'wpinv_checkout_billing_info' );
1466
-                    do_action( 'wpinv_checkout_cart' );
1467
-                    do_action( 'wpinv_payment_mode_select'  );
1468
-                    do_action( 'wpinv_checkout_form_bottom' )
1464
+                    do_action('wpinv_checkout_form_top');
1465
+                    do_action('wpinv_checkout_billing_info');
1466
+                    do_action('wpinv_checkout_cart');
1467
+                    do_action('wpinv_payment_mode_select');
1468
+                    do_action('wpinv_checkout_form_bottom')
1469 1469
                     ?>
1470 1470
                 </form>
1471
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1471
+                <?php do_action('wpinv_after_purchase_form'); ?>
1472 1472
             </div><!--end #wpinv_checkout_form_wrap-->
1473 1473
         <?php
1474 1474
         } else {
1475
-            do_action( 'wpinv_cart_empty' );
1475
+            do_action('wpinv_cart_empty');
1476 1476
         }
1477 1477
         echo '</div><!--end #wpinv_checkout_wrap-->';
1478
-	    do_action( 'wpinv_checkout_content_after' );
1478
+	    do_action('wpinv_checkout_content_after');
1479 1479
     return ob_get_clean();
1480 1480
 }
1481 1481
 
1482
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1482
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1483 1483
     global $ajax_cart_details;
1484 1484
     $ajax_cart_details = $cart_details;
1485 1485
 
1486 1486
     ob_start();
1487
-    do_action( 'wpinv_before_checkout_cart' );
1487
+    do_action('wpinv_before_checkout_cart');
1488 1488
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1489 1489
         echo '<div id="wpinv_checkout_cart_wrap">';
1490
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1490
+            wpinv_get_template_part('wpinv-checkout-cart');
1491 1491
         echo '</div>';
1492 1492
     echo '</div>';
1493
-    do_action( 'wpinv_after_checkout_cart' );
1493
+    do_action('wpinv_after_checkout_cart');
1494 1494
     $content = ob_get_clean();
1495 1495
 
1496
-    if ( $echo ) {
1496
+    if ($echo) {
1497 1497
         echo $content;
1498 1498
     } else {
1499 1499
         return $content;
1500 1500
     }
1501 1501
 }
1502
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1502
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1503 1503
 
1504 1504
 function wpinv_empty_cart_message() {
1505
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1505
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1506 1506
 }
1507 1507
 
1508 1508
 /**
@@ -1514,83 +1514,83 @@  discard block
 block discarded – undo
1514 1514
 function wpinv_empty_checkout_cart() {
1515 1515
 	echo wpinv_empty_cart_message();
1516 1516
 }
1517
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1517
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1518 1518
 
1519 1519
 function wpinv_update_cart_button() {
1520
-    if ( !wpinv_item_quantities_enabled() )
1520
+    if (!wpinv_item_quantities_enabled())
1521 1521
         return;
1522 1522
 ?>
1523
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1523
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1524 1524
     <input type="hidden" name="wpi_action" value="update_cart"/>
1525 1525
 <?php
1526 1526
 }
1527 1527
 
1528 1528
 function wpinv_checkout_cart_columns() {
1529 1529
     $default = 3;
1530
-    if ( wpinv_item_quantities_enabled() ) {
1530
+    if (wpinv_item_quantities_enabled()) {
1531 1531
         $default++;
1532 1532
     }
1533 1533
     
1534
-    if ( wpinv_use_taxes() ) {
1534
+    if (wpinv_use_taxes()) {
1535 1535
         $default++;
1536 1536
     }
1537 1537
 
1538
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1538
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_display_cart_messages() {
1542 1542
     global $wpi_session;
1543 1543
 
1544
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1544
+    $messages = $wpi_session->get('wpinv_cart_messages');
1545 1545
 
1546
-    if ( $messages ) {
1547
-        foreach ( $messages as $message_id => $message ) {
1546
+    if ($messages) {
1547
+        foreach ($messages as $message_id => $message) {
1548 1548
             // Try and detect what type of message this is
1549
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1549
+            if (strpos(strtolower($message), 'error')) {
1550 1550
                 $type = 'error';
1551
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1551
+            } elseif (strpos(strtolower($message), 'success')) {
1552 1552
                 $type = 'success';
1553 1553
             } else {
1554 1554
                 $type = 'info';
1555 1555
             }
1556 1556
 
1557
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1557
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1558 1558
 
1559
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1559
+            echo '<div class="' . implode(' ', $classes) . '">';
1560 1560
                 // Loop message codes and display messages
1561 1561
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1562 1562
             echo '</div>';
1563 1563
         }
1564 1564
 
1565 1565
         // Remove all of the cart saving messages
1566
-        $wpi_session->set( 'wpinv_cart_messages', null );
1566
+        $wpi_session->set('wpinv_cart_messages', null);
1567 1567
     }
1568 1568
 }
1569
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1569
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1570 1570
 
1571 1571
 function wpinv_discount_field() {
1572
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1572
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1573 1573
         return; // Only show before a payment method has been selected if ajax is disabled
1574 1574
     }
1575 1575
 
1576
-    if ( !wpinv_is_checkout() ) {
1576
+    if (!wpinv_is_checkout()) {
1577 1577
         return;
1578 1578
     }
1579 1579
 
1580
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1580
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1581 1581
     ?>
1582 1582
     <div id="wpinv-discount-field" class="panel panel-default">
1583 1583
         <div class="panel-body">
1584 1584
             <p>
1585
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1586
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1585
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1586
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1587 1587
             </p>
1588 1588
             <div class="form-group row">
1589 1589
                 <div class="col-sm-4">
1590
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1590
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1591 1591
                 </div>
1592 1592
                 <div class="col-sm-3">
1593
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1593
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1594 1594
                 </div>
1595 1595
                 <div style="clear:both"></div>
1596 1596
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1603,10 +1603,10 @@  discard block
 block discarded – undo
1603 1603
 <?php
1604 1604
     }
1605 1605
 }
1606
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1606
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1607 1607
 
1608 1608
 function wpinv_agree_to_terms_js() {
1609
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1609
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1610 1610
 ?>
1611 1611
 <script type="text/javascript">
1612 1612
     jQuery(document).ready(function($){
@@ -1621,125 +1621,125 @@  discard block
 block discarded – undo
1621 1621
 <?php
1622 1622
     }
1623 1623
 }
1624
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1624
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1625 1625
 
1626 1626
 function wpinv_payment_mode_select() {
1627
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1628
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1629
-    $invoice = wpinv_get_invoice( 0, true );
1627
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1628
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1629
+    $invoice = wpinv_get_invoice(0, true);
1630 1630
 
1631 1631
     do_action('wpinv_payment_mode_top');
1632
-    $invoice_id = (int)$invoice->ID;
1633
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1632
+    $invoice_id = (int) $invoice->ID;
1633
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1634 1634
     ?>
1635
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;" data-free="1"' : '' ); ?>>
1636
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1635
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;" data-free="1"' : ''); ?>>
1636
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1637 1637
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1638
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1638
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1639 1639
                 <div class="panel-body list-group wpi-payment_methods">
1640 1640
                     <?php
1641
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1642
-
1643
-                    if ( !empty( $gateways ) ) {
1644
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1645
-                            $checked       = checked( $gateway_id, $chosen_gateway, false );
1646
-                            $button_label  = wpinv_get_gateway_button_label( $gateway_id );
1647
-                            $gateway_label = wpinv_get_gateway_checkout_label( $gateway_id );
1648
-                            $description   = wpinv_get_gateway_description( $gateway_id );
1641
+                    do_action('wpinv_payment_mode_before_gateways');
1642
+
1643
+                    if (!empty($gateways)) {
1644
+                        foreach ($gateways as $gateway_id => $gateway) {
1645
+                            $checked       = checked($gateway_id, $chosen_gateway, false);
1646
+                            $button_label  = wpinv_get_gateway_button_label($gateway_id);
1647
+                            $gateway_label = wpinv_get_gateway_checkout_label($gateway_id);
1648
+                            $description   = wpinv_get_gateway_description($gateway_id);
1649 1649
                             ?>
1650 1650
                             <div class="list-group-item">
1651 1651
                                 <div class="radio">
1652
-                                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway_label ); ?></label>
1652
+                                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway_label); ?></label>
1653 1653
                                 </div>
1654
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1655
-                                    <?php if ( !empty( $description ) ) { ?>
1656
-                                        <div class="wpi-gateway-desc alert alert-info"><?php _e( $description, 'invoicing' ); ?></div>
1654
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1655
+                                    <?php if (!empty($description)) { ?>
1656
+                                        <div class="wpi-gateway-desc alert alert-info"><?php _e($description, 'invoicing'); ?></div>
1657 1657
                                     <?php } ?>
1658
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1658
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1659 1659
                                 </div>
1660 1660
                             </div>
1661 1661
                             <?php
1662 1662
                         }
1663 1663
                     } else {
1664
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1664
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1665 1665
                     }
1666 1666
 
1667
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1667
+                    do_action('wpinv_payment_mode_after_gateways');
1668 1668
                     ?>
1669 1669
                 </div>
1670 1670
             </div>
1671
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1671
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1672 1672
     </div>
1673 1673
     <?php
1674 1674
     do_action('wpinv_payment_mode_bottom');
1675 1675
 }
1676
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1676
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1677 1677
 
1678 1678
 function wpinv_checkout_billing_info() {
1679
-    if ( wpinv_is_checkout() ) {
1679
+    if (wpinv_is_checkout()) {
1680 1680
         $billing_details    = wpinv_checkout_billing_details();
1681
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1681
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1682 1682
         ?>
1683 1683
         <div id="wpinv-fields" class="clearfix">
1684 1684
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1685
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1685
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1686 1686
                 <div id="wpinv-fields-box" class="panel-body">
1687
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1687
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1688 1688
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1689
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1689
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1690 1690
                         <?php
1691
-                        echo wpinv_html_text( array(
1691
+                        echo wpinv_html_text(array(
1692 1692
                                 'id'            => 'wpinv_first_name',
1693 1693
                                 'name'          => 'wpinv_first_name',
1694 1694
                                 'value'         => $billing_details['first_name'],
1695 1695
                                 'class'         => 'wpi-input form-control',
1696
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1697
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1698
-                            ) );
1696
+                                'placeholder'   => __('First name', 'invoicing'),
1697
+                                'required'      => (bool) wpinv_get_option('fname_mandatory'),
1698
+                            ));
1699 1699
                         ?>
1700 1700
                     </p>
1701 1701
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1702
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1702
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1703 1703
                         <?php
1704
-                        echo wpinv_html_text( array(
1704
+                        echo wpinv_html_text(array(
1705 1705
                                 'id'            => 'wpinv_last_name',
1706 1706
                                 'name'          => 'wpinv_last_name',
1707 1707
                                 'value'         => $billing_details['last_name'],
1708 1708
                                 'class'         => 'wpi-input form-control',
1709
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1710
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1711
-                            ) );
1709
+                                'placeholder'   => __('Last name', 'invoicing'),
1710
+                                'required'      => (bool) wpinv_get_option('lname_mandatory'),
1711
+                            ));
1712 1712
                         ?>
1713 1713
                     </p>
1714 1714
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1715
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1715
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1716 1716
                         <?php
1717
-                        echo wpinv_html_text( array(
1717
+                        echo wpinv_html_text(array(
1718 1718
                                 'id'            => 'wpinv_address',
1719 1719
                                 'name'          => 'wpinv_address',
1720 1720
                                 'value'         => $billing_details['address'],
1721 1721
                                 'class'         => 'wpi-input form-control',
1722
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1723
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1724
-                            ) );
1722
+                                'placeholder'   => __('Address', 'invoicing'),
1723
+                                'required'      => (bool) wpinv_get_option('address_mandatory'),
1724
+                            ));
1725 1725
                         ?>
1726 1726
                     </p>
1727 1727
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1728
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1728
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1729 1729
                         <?php
1730
-                        echo wpinv_html_text( array(
1730
+                        echo wpinv_html_text(array(
1731 1731
                                 'id'            => 'wpinv_city',
1732 1732
                                 'name'          => 'wpinv_city',
1733 1733
                                 'value'         => $billing_details['city'],
1734 1734
                                 'class'         => 'wpi-input form-control',
1735
-                                'placeholder'   => __( 'City', 'invoicing' ),
1736
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1737
-                            ) );
1735
+                                'placeholder'   => __('City', 'invoicing'),
1736
+                                'required'      => (bool) wpinv_get_option('city_mandatory'),
1737
+                            ));
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1741
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
-                        <?php echo wpinv_html_select( array(
1741
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
+                        <?php echo wpinv_html_select(array(
1743 1743
                             'options'          => wpinv_get_country_list(),
1744 1744
                             'name'             => 'wpinv_country',
1745 1745
                             'id'               => 'wpinv_country',
@@ -1747,16 +1747,16 @@  discard block
 block discarded – undo
1747 1747
                             'show_option_all'  => false,
1748 1748
                             'show_option_none' => false,
1749 1749
                             'class'            => 'wpi-input form-control wpi_select2',
1750
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1751
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1752
-                        ) ); ?>
1750
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1751
+                            'required'         => (bool) wpinv_get_option('country_mandatory'),
1752
+                        )); ?>
1753 1753
                     </p>
1754 1754
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1755
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1755
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1756 1756
                         <?php
1757
-                        $states = wpinv_get_country_states( $selected_country );
1758
-                        if( !empty( $states ) ) {
1759
-                            echo wpinv_html_select( array(
1757
+                        $states = wpinv_get_country_states($selected_country);
1758
+                        if (!empty($states)) {
1759
+                            echo wpinv_html_select(array(
1760 1760
                                 'options'          => $states,
1761 1761
                                 'name'             => 'wpinv_state',
1762 1762
                                 'id'               => 'wpinv_state',
@@ -1764,61 +1764,61 @@  discard block
 block discarded – undo
1764 1764
                                 'show_option_all'  => false,
1765 1765
                                 'show_option_none' => false,
1766 1766
                                 'class'            => 'wpi-input form-control wpi_select2',
1767
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1768
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1769
-                            ) );
1767
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1768
+                                'required'         => (bool) wpinv_get_option('state_mandatory'),
1769
+                            ));
1770 1770
                         } else {
1771
-                            echo wpinv_html_text( array(
1771
+                            echo wpinv_html_text(array(
1772 1772
                                 'name'          => 'wpinv_state',
1773 1773
                                 'value'         => $billing_details['state'],
1774 1774
                                 'id'            => 'wpinv_state',
1775 1775
                                 'class'         => 'wpi-input form-control',
1776
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1777
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1778
-                            ) );
1776
+                                'placeholder'   => __('State / Province', 'invoicing'),
1777
+                                'required'      => (bool) wpinv_get_option('state_mandatory'),
1778
+                            ));
1779 1779
                         }
1780 1780
                         ?>
1781 1781
                     </p>
1782 1782
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1783
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1783
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1784 1784
                         <?php
1785
-                        echo wpinv_html_text( array(
1785
+                        echo wpinv_html_text(array(
1786 1786
                                 'name'          => 'wpinv_zip',
1787 1787
                                 'value'         => $billing_details['zip'],
1788 1788
                                 'id'            => 'wpinv_zip',
1789 1789
                                 'class'         => 'wpi-input form-control',
1790
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1791
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1792
-                            ) );
1790
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1791
+                                'required'      => (bool) wpinv_get_option('zip_mandatory'),
1792
+                            ));
1793 1793
                         ?>
1794 1794
                     </p>
1795 1795
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1796
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1796
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1797 1797
                         <?php
1798
-                        echo wpinv_html_text( array(
1798
+                        echo wpinv_html_text(array(
1799 1799
                                 'id'            => 'wpinv_phone',
1800 1800
                                 'name'          => 'wpinv_phone',
1801 1801
                                 'value'         => $billing_details['phone'],
1802 1802
                                 'class'         => 'wpi-input form-control',
1803
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1804
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1805
-                            ) );
1803
+                                'placeholder'   => __('Phone', 'invoicing'),
1804
+                                'required'      => (bool) wpinv_get_option('phone_mandatory'),
1805
+                            ));
1806 1806
                         ?>
1807 1807
                     </p>
1808
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1808
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1809 1809
                     <div class="clearfix"></div>
1810 1810
                 </div>
1811 1811
             </div>
1812
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1812
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1813 1813
         </div>
1814 1814
         <?php
1815 1815
     }
1816 1816
 }
1817
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1817
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1818 1818
 
1819 1819
 function wpinv_checkout_hidden_fields() {
1820 1820
 ?>
1821
-    <?php if ( is_user_logged_in() ) { ?>
1821
+    <?php if (is_user_logged_in()) { ?>
1822 1822
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1823 1823
     <?php } ?>
1824 1824
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1828,9 +1828,9 @@  discard block
 block discarded – undo
1828 1828
 function wpinv_checkout_button_purchase() {
1829 1829
     ob_start();
1830 1830
 ?>
1831
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1831
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1832 1832
 <?php
1833
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1833
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1834 1834
 }
1835 1835
 
1836 1836
 function wpinv_checkout_total() {
@@ -1839,84 +1839,84 @@  discard block
 block discarded – undo
1839 1839
 <div id="wpinv_checkout_total" class="panel panel-info">
1840 1840
     <div class="panel-body">
1841 1841
     <?php
1842
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1842
+    do_action('wpinv_purchase_form_before_checkout_total');
1843 1843
     ?>
1844
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1844
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1845 1845
     <?php
1846
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1846
+    do_action('wpinv_purchase_form_after_checkout_total');
1847 1847
     ?>
1848 1848
     </div>
1849 1849
 </div>
1850 1850
 <?php
1851 1851
 }
1852
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1852
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1853 1853
 
1854 1854
 function wpinv_checkout_accept_tandc() {
1855
-    $page = wpinv_get_option( 'tandc_page' );
1855
+    $page = wpinv_get_option('tandc_page');
1856 1856
     ?>
1857 1857
     <div id="wpinv_checkout_tandc" class="panel panel-success">
1858 1858
         <div class="panel-body">
1859 1859
             <?php echo wpinv_get_policy_text(); ?>
1860 1860
             <?php
1861
-            if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1862
-                $terms_link = esc_url( get_permalink( $page ) );
1861
+            if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1862
+                $terms_link = esc_url(get_permalink($page));
1863 1863
                 ?>
1864 1864
                 <label class="">
1865
-                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked( apply_filters( 'wpinv_terms_is_checked_default', isset( $_POST['wpi_terms'] ) ), true ); ?>> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing' ), $terms_link ); ?></span> <span class="wpi-required">*</span>
1865
+                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked(apply_filters('wpinv_terms_is_checked_default', isset($_POST['wpi_terms'])), true); ?>> <span><?php printf(__('I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing'), $terms_link); ?></span> <span class="wpi-required">*</span>
1866 1866
                 </label>
1867 1867
             <?php } ?>
1868 1868
         </div>
1869 1869
     </div>
1870 1870
     <?php
1871 1871
 }
1872
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995 );
1872
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995);
1873 1873
 
1874 1874
 function wpinv_checkout_submit() {
1875 1875
 ?>
1876 1876
 <div id="wpinv_purchase_submit" class="panel panel-success">
1877 1877
     <div class="panel-body text-center">
1878 1878
     <?php
1879
-    do_action( 'wpinv_purchase_form_before_submit' );
1879
+    do_action('wpinv_purchase_form_before_submit');
1880 1880
     wpinv_checkout_hidden_fields();
1881 1881
     echo wpinv_checkout_button_purchase();
1882
-    do_action( 'wpinv_purchase_form_after_submit' );
1882
+    do_action('wpinv_purchase_form_after_submit');
1883 1883
     ?>
1884 1884
     </div>
1885 1885
 </div>
1886 1886
 <?php
1887 1887
 }
1888
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1888
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1889 1889
 
1890
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1891
-    $invoice = wpinv_get_invoice( $invoice_id );
1890
+function wpinv_receipt_billing_address($invoice_id = 0) {
1891
+    $invoice = wpinv_get_invoice($invoice_id);
1892 1892
 
1893
-    if ( empty( $invoice ) ) {
1893
+    if (empty($invoice)) {
1894 1894
         return NULL;
1895 1895
     }
1896 1896
 
1897 1897
     $billing_details = $invoice->get_user_info();
1898
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1898
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1899 1899
 
1900 1900
     ob_start();
1901 1901
     ?>
1902 1902
     <table class="table table-bordered table-sm wpi-billing-details">
1903 1903
         <tbody>
1904 1904
             <tr class="wpi-receipt-name">
1905
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1906
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1905
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1906
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1907 1907
             </tr>
1908 1908
             <tr class="wpi-receipt-email">
1909
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1910
-                <td><?php echo $billing_details['email'] ;?></td>
1909
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1910
+                <td><?php echo $billing_details['email']; ?></td>
1911 1911
             </tr>
1912 1912
             <tr class="wpi-receipt-address">
1913
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1914
-                <td><?php echo $address_row ;?></td>
1913
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1914
+                <td><?php echo $address_row; ?></td>
1915 1915
             </tr>
1916
-            <?php if ( $billing_details['phone'] ) { ?>
1916
+            <?php if ($billing_details['phone']) { ?>
1917 1917
             <tr class="wpi-receipt-phone">
1918
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1919
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1918
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1919
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1920 1920
             </tr>
1921 1921
             <?php } ?>
1922 1922
         </tbody>
@@ -1924,74 +1924,74 @@  discard block
 block discarded – undo
1924 1924
     <?php
1925 1925
     $output = ob_get_clean();
1926 1926
     
1927
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1927
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1928 1928
 
1929 1929
     echo $output;
1930 1930
 }
1931 1931
 
1932
-function wpinv_filter_success_page_content( $content ) {
1933
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1934
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1935
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1932
+function wpinv_filter_success_page_content($content) {
1933
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1934
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1935
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1936 1936
         }
1937 1937
     }
1938 1938
 
1939 1939
     return $content;
1940 1940
 }
1941
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1941
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1942 1942
 
1943
-function wpinv_receipt_actions( $invoice ) {
1944
-    if ( !empty( $invoice ) ) {
1943
+function wpinv_receipt_actions($invoice) {
1944
+    if (!empty($invoice)) {
1945 1945
         $actions = array();
1946 1946
 
1947
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1948
-            $actions['print']   = array(
1949
-                'url'  => $invoice->get_view_url( true ),
1950
-                'name' => __( 'Print Invoice', 'invoicing' ),
1947
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1948
+            $actions['print'] = array(
1949
+                'url'  => $invoice->get_view_url(true),
1950
+                'name' => __('Print Invoice', 'invoicing'),
1951 1951
                 'class' => 'btn-primary',
1952 1952
             );
1953 1953
         }
1954 1954
 
1955
-        if ( is_user_logged_in() ) {
1955
+        if (is_user_logged_in()) {
1956 1956
             $actions['history'] = array(
1957 1957
                 'url'  => wpinv_get_history_page_uri(),
1958
-                'name' => __( 'Invoice History', 'invoicing' ),
1958
+                'name' => __('Invoice History', 'invoicing'),
1959 1959
                 'class' => 'btn-warning',
1960 1960
             );
1961 1961
         }
1962 1962
 
1963
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1963
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1964 1964
 
1965
-        if ( !empty( $actions ) ) {
1965
+        if (!empty($actions)) {
1966 1966
         ?>
1967 1967
         <div class="wpinv-receipt-actions text-right">
1968
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1969
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1968
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1969
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1970 1970
             <?php } ?>
1971 1971
         </div>
1972 1972
         <?php
1973 1973
         }
1974 1974
     }
1975 1975
 }
1976
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1976
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1977 1977
 
1978
-function wpinv_invoice_link( $invoice_id ) {
1979
-    $invoice = wpinv_get_invoice( $invoice_id );
1978
+function wpinv_invoice_link($invoice_id) {
1979
+    $invoice = wpinv_get_invoice($invoice_id);
1980 1980
 
1981
-    if ( empty( $invoice ) ) {
1981
+    if (empty($invoice)) {
1982 1982
         return NULL;
1983 1983
     }
1984 1984
 
1985
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1985
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1986 1986
 
1987
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1987
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1988 1988
 }
1989 1989
 
1990
-function wpinv_invoice_subscription_details( $invoice ) {
1991
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1992
-        $subscription = wpinv_get_subscription( $invoice, true );
1990
+function wpinv_invoice_subscription_details($invoice) {
1991
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1992
+        $subscription = wpinv_get_subscription($invoice, true);
1993 1993
 
1994
-        if ( empty( $subscription ) ) {
1994
+        if (empty($subscription)) {
1995 1995
             return;
1996 1996
         }
1997 1997
 
@@ -2002,15 +2002,15 @@  discard block
 block discarded – undo
2002 2002
         $payments = $subscription->get_child_payments();
2003 2003
         ?>
2004 2004
         <div class="wpinv-subscriptions-details">
2005
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
2005
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
2006 2006
             <table class="table">
2007 2007
                 <thead>
2008 2008
                     <tr>
2009
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
2010
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
2011
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
2012
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
2013
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
2009
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
2010
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
2011
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
2012
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
2013
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
@@ -2024,29 +2024,29 @@  discard block
 block discarded – undo
2024 2024
                 </tbody>
2025 2025
             </table>
2026 2026
         </div>
2027
-        <?php if ( !empty( $payments ) ) { ?>
2027
+        <?php if (!empty($payments)) { ?>
2028 2028
         <div class="wpinv-renewal-payments">
2029
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2029
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2030 2030
             <table class="table">
2031 2031
                 <thead>
2032 2032
                     <tr>
2033 2033
                         <th>#</th>
2034
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2035
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2036
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2034
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2035
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2036
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2037 2037
                     </tr>
2038 2038
                 </thead>
2039 2039
                 <tbody>
2040 2040
                     <?php
2041 2041
                         $i = 1;
2042
-                        foreach ( $payments as $payment ) {
2042
+                        foreach ($payments as $payment) {
2043 2043
                             $invoice_id = $payment->ID;
2044 2044
                     ?>
2045 2045
                     <tr>
2046
-                        <th scope="row"><?php echo $i;?></th>
2047
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2048
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2049
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2046
+                        <th scope="row"><?php echo $i; ?></th>
2047
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2048
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2049
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2050 2050
                     </tr>
2051 2051
                     <?php $i++; } ?>
2052 2052
                 </tbody>
@@ -2057,52 +2057,52 @@  discard block
 block discarded – undo
2057 2057
     }
2058 2058
 }
2059 2059
 
2060
-function wpinv_cart_total_label( $label, $invoice ) {
2061
-    if ( empty( $invoice ) ) {
2060
+function wpinv_cart_total_label($label, $invoice) {
2061
+    if (empty($invoice)) {
2062 2062
         return $label;
2063 2063
     }
2064 2064
 
2065 2065
     $prefix_label = '';
2066
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
2067
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2068
-    } else if ( $invoice->is_renewal() ) {
2069
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2066
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
2067
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2068
+    } else if ($invoice->is_renewal()) {
2069
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2070 2070
     }
2071 2071
 
2072
-    if ( $prefix_label != '' ) {
2073
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2072
+    if ($prefix_label != '') {
2073
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2074 2074
     }
2075 2075
 
2076 2076
     return $label;
2077 2077
 }
2078
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2079
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2080
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2078
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2079
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2080
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2081 2081
 
2082
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2082
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2083 2083
 
2084
-function wpinv_invoice_print_description( $invoice ) {
2085
-    if ( empty( $invoice ) ) {
2084
+function wpinv_invoice_print_description($invoice) {
2085
+    if (empty($invoice)) {
2086 2086
         return NULL;
2087 2087
     }
2088
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2088
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2089 2089
         ?>
2090 2090
         <div class="row wpinv-lower">
2091 2091
             <div class="col-sm-12 wpinv-description">
2092
-                <?php echo wpautop( $description ); ?>
2092
+                <?php echo wpautop($description); ?>
2093 2093
             </div>
2094 2094
         </div>
2095 2095
         <?php
2096 2096
     }
2097 2097
 }
2098
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2098
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2099 2099
 
2100
-function wpinv_invoice_print_payment_info( $invoice ) {
2101
-    if ( empty( $invoice ) ) {
2100
+function wpinv_invoice_print_payment_info($invoice) {
2101
+    if (empty($invoice)) {
2102 2102
         return NULL;
2103 2103
     }
2104 2104
 
2105
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2105
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2106 2106
         ?>
2107 2107
         <div class="row wpinv-payments">
2108 2108
             <div class="col-sm-12">
@@ -2114,43 +2114,43 @@  discard block
 block discarded – undo
2114 2114
 }
2115 2115
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2116 2116
 
2117
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2118
-    if ( empty( $note ) ) {
2117
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2118
+    if (empty($note)) {
2119 2119
         return NULL;
2120 2120
     }
2121 2121
 
2122
-    if ( is_int( $note ) ) {
2123
-        $note = get_comment( $note );
2122
+    if (is_int($note)) {
2123
+        $note = get_comment($note);
2124 2124
     }
2125 2125
 
2126
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2126
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2127 2127
         return NULL;
2128 2128
     }
2129 2129
 
2130
-    $note_classes   = array( 'note' );
2131
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2130
+    $note_classes   = array('note');
2131
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2132 2132
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2133
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2134
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2133
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2134
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2135 2135
 
2136 2136
     ob_start();
2137 2137
     ?>
2138
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2138
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2139 2139
         <div class="note_content">
2140
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2140
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2141 2141
         </div>
2142 2142
         <p class="meta">
2143
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2144
-            <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?>
2145
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2143
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2144
+            <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?>
2145
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2146 2146
             <?php } ?>
2147 2147
         </p>
2148 2148
     </li>
2149 2149
     <?php
2150 2150
     $note_content = ob_get_clean();
2151
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2151
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2152 2152
 
2153
-    if ( $echo ) {
2153
+    if ($echo) {
2154 2154
         echo $note_content;
2155 2155
     } else {
2156 2156
         return $note_content;
@@ -2160,43 +2160,43 @@  discard block
 block discarded – undo
2160 2160
 function wpinv_invalid_invoice_content() {
2161 2161
     global $post;
2162 2162
 
2163
-    $invoice = wpinv_get_invoice( $post->ID );
2163
+    $invoice = wpinv_get_invoice($post->ID);
2164 2164
 
2165
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
2166
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2167
-        if ( is_user_logged_in() ) {
2168
-            if ( wpinv_require_login_to_checkout() ) {
2169
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2170
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2165
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
2166
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2167
+        if (is_user_logged_in()) {
2168
+            if (wpinv_require_login_to_checkout()) {
2169
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2170
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2171 2171
                 }
2172 2172
             }
2173 2173
         } else {
2174
-            if ( wpinv_require_login_to_checkout() ) {
2175
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2176
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2174
+            if (wpinv_require_login_to_checkout()) {
2175
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2176
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2177 2177
                 }
2178 2178
             }
2179 2179
         }
2180 2180
     } else {
2181
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2181
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2182 2182
     }
2183 2183
     ?>
2184 2184
     <div class="row wpinv-row-invalid">
2185 2185
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2186
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2186
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2187 2187
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2188 2188
         </div>
2189 2189
     </div>
2190 2190
     <?php
2191 2191
 }
2192
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2192
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2193 2193
 
2194
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
-function wpinv_force_company_name_field(){
2194
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
+function wpinv_force_company_name_field() {
2196 2196
     $invoice = wpinv_get_invoice_cart();
2197
-    $user_id = wpinv_get_user_id( $invoice->ID );
2198
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2199
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2197
+    $user_id = wpinv_get_user_id($invoice->ID);
2198
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2199
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2200 2200
         ?>
2201 2201
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2202 2202
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2222,21 +2222,21 @@  discard block
 block discarded – undo
2222 2222
  * @return string
2223 2223
  */
2224 2224
 function wpinv_get_policy_text() {
2225
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2225
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2226 2226
 
2227
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
2227
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
2228 2228
 
2229
-    if(!$privacy_page_id){
2230
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2229
+    if (!$privacy_page_id) {
2230
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2231 2231
     }
2232 2232
 
2233
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
2233
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
2234 2234
 
2235 2235
     $find_replace = array(
2236 2236
         '[wpinv_privacy_policy]' => $privacy_link,
2237 2237
     );
2238 2238
 
2239
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2239
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2240 2240
 
2241 2241
     return wp_kses_post(wpautop($privacy_text));
2242 2242
 }
@@ -2245,25 +2245,25 @@  discard block
 block discarded – undo
2245 2245
 /**
2246 2246
  * Allows the user to set their own price for an invoice item
2247 2247
  */
2248
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
2248
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
2249 2249
     
2250 2250
     //Ensure we have an item id
2251
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
2251
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
2252 2252
         return;
2253 2253
     }
2254 2254
 
2255 2255
     //Fetch the item
2256 2256
     $item_id = $cart_item['id'];
2257
-    $item    = new WPInv_Item( $item_id );
2257
+    $item    = new WPInv_Item($item_id);
2258 2258
     
2259
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
2259
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
2260 2260
         return;
2261 2261
     }
2262 2262
 
2263 2263
     //Fetch the dynamic pricing "strings"
2264
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
2265
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
2266
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
2264
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
2265
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
2266
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
2267 2267
 
2268 2268
     //Display a "name_your_price" button
2269 2269
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -2272,7 +2272,7 @@  discard block
 block discarded – undo
2272 2272
     echo '<div class="name-your-price-miniform">';
2273 2273
     
2274 2274
     //Maybe display the recommended price
2275
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
2275
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
2276 2276
         $suggested_price = $item->get_the_price();
2277 2277
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
2278 2278
     }
@@ -2280,50 +2280,50 @@  discard block
 block discarded – undo
2280 2280
     //Display the update price form
2281 2281
     $symbol         = wpinv_currency_symbol();
2282 2282
     $position       = wpinv_currency_position();
2283
-    $minimum        = esc_attr( $item->get_minimum_price() );
2284
-    $price          = esc_attr( $cart_item['item_price'] );
2285
-    $update         = esc_attr__( "Update", 'invoicing' );
2283
+    $minimum        = esc_attr($item->get_minimum_price());
2284
+    $price          = esc_attr($cart_item['item_price']);
2285
+    $update         = esc_attr__("Update", 'invoicing');
2286 2286
 
2287 2287
     //Ensure it supports dynamic prici
2288
-    if( $price < $minimum ) {
2288
+    if ($price < $minimum) {
2289 2289
         $price = $minimum;
2290 2290
     }
2291 2291
 
2292 2292
     echo '<label>';
2293 2293
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
2294 2294
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
2295
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
2295
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
2296 2296
     echo "</label>";
2297 2297
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
2298 2298
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
2299 2299
 
2300 2300
     //Maybe display the minimum price
2301
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
2302
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
2301
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
2302
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
2303 2303
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
2304 2304
     }
2305 2305
 
2306 2306
     echo "</div>";
2307 2307
 
2308 2308
 }
2309
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
2309
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
2310 2310
 
2311 2311
 function wpinv_oxygen_fix_conflict() {
2312 2312
     global $ct_ignore_post_types;
2313 2313
 
2314
-    if ( ! is_array( $ct_ignore_post_types ) ) {
2314
+    if (!is_array($ct_ignore_post_types)) {
2315 2315
         $ct_ignore_post_types = array();
2316 2316
     }
2317 2317
 
2318
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
2318
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
2319 2319
 
2320
-    foreach ( $post_types as $post_type ) {
2320
+    foreach ($post_types as $post_type) {
2321 2321
         $ct_ignore_post_types[] = $post_type;
2322 2322
 
2323 2323
         // Ignore post type
2324
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
2324
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
2325 2325
     }
2326 2326
 
2327
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
2328
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
2327
+    remove_filter('template_include', 'wpinv_template', 10, 1);
2328
+    add_filter('template_include', 'wpinv_template', 999, 1);
2329 2329
 }
2330 2330
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  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
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -78,39 +78,39 @@  discard block
 block discarded – undo
78 78
             'buy_items' => true,
79 79
         );
80 80
 
81
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
82
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
81
+        foreach ($ajax_events as $ajax_event => $nopriv) {
82
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
83 83
             
84
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
85
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
84
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
85
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
86 86
             }
87 87
 
88
-            if ( $nopriv ) {
89
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
88
+            if ($nopriv) {
89
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
90 90
 
91
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
91
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
92 92
             }
93 93
         }
94 94
     }
95 95
     
96 96
     public static function add_note() {
97
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
97
+        check_ajax_referer('add-invoice-note', '_nonce');
98 98
 
99
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
99
+        if (!wpinv_current_user_can_manage_invoicing()) {
100 100
             die(-1);
101 101
         }
102 102
 
103
-        $post_id   = absint( $_POST['post_id'] );
104
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
105
-        $note_type = sanitize_text_field( $_POST['note_type'] );
103
+        $post_id   = absint($_POST['post_id']);
104
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
105
+        $note_type = sanitize_text_field($_POST['note_type']);
106 106
 
107 107
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
108 108
 
109
-        if ( $post_id > 0 ) {
110
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
109
+        if ($post_id > 0) {
110
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
111 111
 
112
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
113
-                wpinv_get_invoice_note_line_item( $note_id );
112
+            if ($note_id > 0 && !is_wp_error($note_id)) {
113
+                wpinv_get_invoice_note_line_item($note_id);
114 114
             }
115 115
         }
116 116
 
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
     }
119 119
 
120 120
     public static function delete_note() {
121
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
121
+        check_ajax_referer('delete-invoice-note', '_nonce');
122 122
 
123
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
123
+        if (!wpinv_current_user_can_manage_invoicing()) {
124 124
             die(-1);
125 125
         }
126 126
 
127
-        $note_id = (int)$_POST['note_id'];
127
+        $note_id = (int) $_POST['note_id'];
128 128
 
129
-        if ( $note_id > 0 ) {
130
-            wp_delete_comment( $note_id, true );
129
+        if ($note_id > 0) {
130
+            wp_delete_comment($note_id, true);
131 131
         }
132 132
 
133 133
         die();
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
     }
141 141
     
142 142
     public static function checkout() {
143
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
144
-            define( 'WPINV_CHECKOUT', true );
143
+        if (!defined('WPINV_CHECKOUT')) {
144
+            define('WPINV_CHECKOUT', true);
145 145
         }
146 146
 
147 147
         wpinv_process_checkout();
@@ -150,53 +150,53 @@  discard block
 block discarded – undo
150 150
     
151 151
     public static function add_invoice_item() {
152 152
         global $wpi_userID, $wpinv_ip_address_country;
153
-        check_ajax_referer( 'invoice-item', '_nonce' );
154
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
153
+        check_ajax_referer('invoice-item', '_nonce');
154
+        if (!wpinv_current_user_can_manage_invoicing()) {
155 155
             die(-1);
156 156
         }
157 157
         
158
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
159
-        $invoice_id = absint( $_POST['invoice_id'] );
158
+        $item_id    = sanitize_text_field($_POST['item_id']);
159
+        $invoice_id = absint($_POST['invoice_id']);
160 160
         
161
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
161
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
162 162
             die();
163 163
         }
164 164
         
165
-        $invoice    = wpinv_get_invoice( $invoice_id );
166
-        if ( empty( $invoice ) ) {
165
+        $invoice = wpinv_get_invoice($invoice_id);
166
+        if (empty($invoice)) {
167 167
             die();
168 168
         }
169 169
         
170
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
170
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
171 171
             die(); // Don't allow modify items for paid invoice.
172 172
         }
173 173
         
174
-        if ( !empty( $_POST['user_id'] ) ) {
175
-            $wpi_userID = absint( $_POST['user_id'] ); 
174
+        if (!empty($_POST['user_id'])) {
175
+            $wpi_userID = absint($_POST['user_id']); 
176 176
         }
177 177
 
178
-        $item = new WPInv_Item( $item_id );
179
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
178
+        $item = new WPInv_Item($item_id);
179
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
180 180
             die();
181 181
         }
182 182
         
183 183
         // Validate item before adding to invoice because recurring item must be paid individually.
184
-        if ( !empty( $invoice->cart_details ) ) {
184
+        if (!empty($invoice->cart_details)) {
185 185
             $valid = true;
186 186
             
187
-            if ( $recurring_item = $invoice->get_recurring() ) {
188
-                if ( $recurring_item != $item_id ) {
187
+            if ($recurring_item = $invoice->get_recurring()) {
188
+                if ($recurring_item != $item_id) {
189 189
                     $valid = false;
190 190
                 }
191
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
191
+            } else if (wpinv_is_recurring_item($item_id)) {
192 192
                 $valid = false;
193 193
             }
194 194
             
195
-            if ( !$valid ) {
195
+            if (!$valid) {
196 196
                 $response               = array();
197 197
                 $response['success']    = false;
198
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
199
-                wp_send_json( $response );
198
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
199
+                wp_send_json($response);
200 200
             }
201 201
         }
202 202
         
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
         
205 205
         $data                   = array();
206 206
         $data['invoice_id']     = $invoice_id;
207
-        $data['cart_discounts'] = $invoice->get_discounts( true );
207
+        $data['cart_discounts'] = $invoice->get_discounts(true);
208 208
         
209
-        wpinv_set_checkout_session( $data );
209
+        wpinv_set_checkout_session($data);
210 210
         
211
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
211
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
212 212
 
213 213
         $args = array(
214 214
             'id'            => $item_id,
@@ -221,21 +221,21 @@  discard block
 block discarded – undo
221 221
             'fees'          => array()
222 222
         );
223 223
 
224
-        $invoice->add_item( $item_id, $args );
224
+        $invoice->add_item($item_id, $args);
225 225
         $invoice->save();
226 226
         
227
-        if ( empty( $_POST['country'] ) ) {
227
+        if (empty($_POST['country'])) {
228 228
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
229 229
         }
230
-        if ( empty( $_POST['state'] ) ) {
230
+        if (empty($_POST['state'])) {
231 231
             $_POST['state'] = $invoice->state;
232 232
         }
233 233
          
234
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
235
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
234
+        $invoice->country   = sanitize_text_field($_POST['country']);
235
+        $invoice->state     = sanitize_text_field($_POST['state']);
236 236
         
237
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
238
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
237
+        $invoice->set('country', sanitize_text_field($_POST['country']));
238
+        $invoice->set('state', sanitize_text_field($_POST['state']));
239 239
         
240 240
         $wpinv_ip_address_country = $invoice->country;
241 241
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         
244 244
         $response                       = array();
245 245
         $response['success']            = true;
246
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
246
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
247 247
         $response['data']['subtotal']   = $invoice->get_subtotal();
248 248
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
249 249
         $response['data']['tax']        = $invoice->get_tax();
@@ -255,41 +255,41 @@  discard block
 block discarded – undo
255 255
         
256 256
         wpinv_set_checkout_session($checkout_session);
257 257
         
258
-        wp_send_json( $response );
258
+        wp_send_json($response);
259 259
     }
260 260
 
261 261
 
262 262
     public static function remove_invoice_item() {
263 263
         global $wpi_userID, $wpinv_ip_address_country;
264 264
         
265
-        check_ajax_referer( 'invoice-item', '_nonce' );
266
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
265
+        check_ajax_referer('invoice-item', '_nonce');
266
+        if (!wpinv_current_user_can_manage_invoicing()) {
267 267
             die(-1);
268 268
         }
269 269
         
270
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
271
-        $invoice_id = absint( $_POST['invoice_id'] );
272
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
270
+        $item_id    = sanitize_text_field($_POST['item_id']);
271
+        $invoice_id = absint($_POST['invoice_id']);
272
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
273 273
         
274
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
274
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
275 275
             die();
276 276
         }
277 277
 
278
-        $invoice    = wpinv_get_invoice( $invoice_id );
279
-        if ( empty( $invoice ) ) {
278
+        $invoice = wpinv_get_invoice($invoice_id);
279
+        if (empty($invoice)) {
280 280
             die();
281 281
         }
282 282
         
283
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
283
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
284 284
             die(); // Don't allow modify items for paid invoice.
285 285
         }
286 286
         
287
-        if ( !empty( $_POST['user_id'] ) ) {
288
-            $wpi_userID = absint( $_POST['user_id'] ); 
287
+        if (!empty($_POST['user_id'])) {
288
+            $wpi_userID = absint($_POST['user_id']); 
289 289
         }
290 290
 
291
-        $item       = new WPInv_Item( $item_id );
292
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
291
+        $item = new WPInv_Item($item_id);
292
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
293 293
             die();
294 294
         }
295 295
         
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
         
298 298
         $data                   = array();
299 299
         $data['invoice_id']     = $invoice_id;
300
-        $data['cart_discounts'] = $invoice->get_discounts( true );
300
+        $data['cart_discounts'] = $invoice->get_discounts(true);
301 301
         
302
-        wpinv_set_checkout_session( $data );
302
+        wpinv_set_checkout_session($data);
303 303
 
304 304
         $args = array(
305 305
             'id'         => $item_id,
@@ -307,21 +307,21 @@  discard block
 block discarded – undo
307 307
             'cart_index' => $cart_index
308 308
         );
309 309
 
310
-        $invoice->remove_item( $item_id, $args );
310
+        $invoice->remove_item($item_id, $args);
311 311
         $invoice->save();
312 312
         
313
-        if ( empty( $_POST['country'] ) ) {
313
+        if (empty($_POST['country'])) {
314 314
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
315 315
         }
316
-        if ( empty( $_POST['state'] ) ) {
316
+        if (empty($_POST['state'])) {
317 317
             $_POST['state'] = $invoice->state;
318 318
         }
319 319
          
320
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
321
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
320
+        $invoice->country   = sanitize_text_field($_POST['country']);
321
+        $invoice->state     = sanitize_text_field($_POST['state']);
322 322
         
323
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
324
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
323
+        $invoice->set('country', sanitize_text_field($_POST['country']));
324
+        $invoice->set('state', sanitize_text_field($_POST['state']));
325 325
         
326 326
         $wpinv_ip_address_country = $invoice->country;
327 327
         
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         
330 330
         $response                       = array();
331 331
         $response['success']            = true;
332
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
332
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
333 333
         $response['data']['subtotal']   = $invoice->get_subtotal();
334 334
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
335 335
         $response['data']['tax']        = $invoice->get_tax();
@@ -341,55 +341,55 @@  discard block
 block discarded – undo
341 341
         
342 342
         wpinv_set_checkout_session($checkout_session);
343 343
         
344
-        wp_send_json( $response );
344
+        wp_send_json($response);
345 345
     }
346 346
     
347 347
     public static function create_invoice_item() {
348
-        check_ajax_referer( 'invoice-item', '_nonce' );
349
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
348
+        check_ajax_referer('invoice-item', '_nonce');
349
+        if (!wpinv_current_user_can_manage_invoicing()) {
350 350
             die(-1);
351 351
         }
352 352
         
353
-        $invoice_id = absint( $_POST['invoice_id'] );
353
+        $invoice_id = absint($_POST['invoice_id']);
354 354
 
355 355
         // Find the item
356
-        if ( !is_numeric( $invoice_id ) ) {
356
+        if (!is_numeric($invoice_id)) {
357 357
             die();
358 358
         }        
359 359
         
360
-        $invoice     = wpinv_get_invoice( $invoice_id );
361
-        if ( empty( $invoice ) ) {
360
+        $invoice = wpinv_get_invoice($invoice_id);
361
+        if (empty($invoice)) {
362 362
             die();
363 363
         }
364 364
         
365 365
         // Validate item before adding to invoice because recurring item must be paid individually.
366
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
366
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
367 367
             $response               = array();
368 368
             $response['success']    = false;
369
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
370
-            wp_send_json( $response );
369
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
370
+            wp_send_json($response);
371 371
         }        
372 372
         
373
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
373
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
374 374
         
375 375
         $meta               = array();
376 376
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
377
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
377
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
378 378
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
379 379
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
380 380
         
381 381
         $data                   = array();
382 382
         $data['post_title']     = sanitize_text_field($save_item['name']);
383 383
         $data['post_status']    = 'publish';
384
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
384
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
385 385
         $data['meta']           = $meta;
386 386
         
387 387
         $item = new WPInv_Item();
388
-        $item->create( $data );
388
+        $item->create($data);
389 389
         
390
-        if ( !empty( $item ) ) {
390
+        if (!empty($item)) {
391 391
             $_POST['item_id']   = $item->ID;
392
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
392
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
393 393
             
394 394
             self::add_invoice_item();
395 395
         }
@@ -397,15 +397,15 @@  discard block
 block discarded – undo
397 397
     }
398 398
     
399 399
     public static function get_billing_details() {
400
-        check_ajax_referer( 'get-billing-details', '_nonce' );
400
+        check_ajax_referer('get-billing-details', '_nonce');
401 401
         
402
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
402
+        if (!wpinv_current_user_can_manage_invoicing()) {
403 403
             die(-1);
404 404
         }
405 405
 
406
-        $user_id            = (int)$_POST['user_id'];
406
+        $user_id            = (int) $_POST['user_id'];
407 407
         $billing_details    = wpinv_get_user_address($user_id);
408
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
408
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
409 409
         
410 410
         if (isset($billing_details['user_id'])) {
411 411
             unset($billing_details['user_id']);
@@ -419,20 +419,20 @@  discard block
 block discarded – undo
419 419
         $response['success']                    = true;
420 420
         $response['data']['billing_details']    = $billing_details;
421 421
         
422
-        wp_send_json( $response );
422
+        wp_send_json($response);
423 423
     }
424 424
     
425 425
     public static function admin_recalculate_totals() {
426 426
         global $wpi_userID, $wpinv_ip_address_country;
427 427
         
428
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
429
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
428
+        check_ajax_referer('wpinv-nonce', '_nonce');
429
+        if (!wpinv_current_user_can_manage_invoicing()) {
430 430
             die(-1);
431 431
         }
432 432
         
433
-        $invoice_id = absint( $_POST['invoice_id'] );        
434
-        $invoice    = wpinv_get_invoice( $invoice_id );
435
-        if ( empty( $invoice ) ) {
433
+        $invoice_id = absint($_POST['invoice_id']);        
434
+        $invoice    = wpinv_get_invoice($invoice_id);
435
+        if (empty($invoice)) {
436 436
             die();
437 437
         }
438 438
 
@@ -440,29 +440,29 @@  discard block
 block discarded – undo
440 440
 
441 441
         $data                   = array();
442 442
         $data['invoice_id']     = $invoice_id;
443
-        $data['cart_discounts'] = $invoice->get_discounts( true );
443
+        $data['cart_discounts'] = $invoice->get_discounts(true);
444 444
 
445
-        wpinv_set_checkout_session( $data );
445
+        wpinv_set_checkout_session($data);
446 446
         
447
-        if ( !empty( $_POST['user_id'] ) ) {
448
-            $wpi_userID = absint( $_POST['user_id'] ); 
447
+        if (!empty($_POST['user_id'])) {
448
+            $wpi_userID = absint($_POST['user_id']); 
449 449
         }
450 450
         
451
-        if ( empty( $_POST['country'] ) ) {
451
+        if (empty($_POST['country'])) {
452 452
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
453 453
         }
454 454
 
455 455
         $disable_taxes = 0;
456
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
456
+        if (!empty($_POST['disable_taxes'])) {
457 457
             $disable_taxes = 1;
458 458
         }
459
-        $invoice->set( 'disable_taxes', $disable_taxes );
459
+        $invoice->set('disable_taxes', $disable_taxes);
460 460
 
461
-        $invoice->country = sanitize_text_field( $_POST['country'] );
462
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
463
-        if ( isset( $_POST['state'] ) ) {
464
-            $invoice->state = sanitize_text_field( $_POST['state'] );
465
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
461
+        $invoice->country = sanitize_text_field($_POST['country']);
462
+        $invoice->set('country', sanitize_text_field($_POST['country']));
463
+        if (isset($_POST['state'])) {
464
+            $invoice->state = sanitize_text_field($_POST['state']);
465
+            $invoice->set('state', sanitize_text_field($_POST['state']));
466 466
         }
467 467
         
468 468
         $wpinv_ip_address_country = $invoice->country;
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         
472 472
         $response                       = array();
473 473
         $response['success']            = true;
474
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
474
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
475 475
         $response['data']['subtotal']   = $invoice->get_subtotal();
476 476
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
477 477
         $response['data']['tax']        = $invoice->get_tax();
@@ -483,25 +483,25 @@  discard block
 block discarded – undo
483 483
         
484 484
         wpinv_set_checkout_session($checkout_session);
485 485
 
486
-        wp_send_json( $response );
486
+        wp_send_json($response);
487 487
     }
488 488
     
489 489
     public static function admin_apply_discount() {
490 490
         global $wpi_userID;
491 491
         
492
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
493
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
492
+        check_ajax_referer('wpinv-nonce', '_nonce');
493
+        if (!wpinv_current_user_can_manage_invoicing()) {
494 494
             die(-1);
495 495
         }
496 496
         
497
-        $invoice_id = absint( $_POST['invoice_id'] );
498
-        $discount_code = sanitize_text_field( $_POST['code'] );
499
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
497
+        $invoice_id = absint($_POST['invoice_id']);
498
+        $discount_code = sanitize_text_field($_POST['code']);
499
+        if (empty($invoice_id) || empty($discount_code)) {
500 500
             die();
501 501
         }
502 502
         
503
-        $invoice = wpinv_get_invoice( $invoice_id );
504
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
503
+        $invoice = wpinv_get_invoice($invoice_id);
504
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
505 505
             die();
506 506
         }
507 507
         
@@ -509,49 +509,49 @@  discard block
 block discarded – undo
509 509
         
510 510
         $data                   = array();
511 511
         $data['invoice_id']     = $invoice_id;
512
-        $data['cart_discounts'] = $invoice->get_discounts( true );
512
+        $data['cart_discounts'] = $invoice->get_discounts(true);
513 513
         
514
-        wpinv_set_checkout_session( $data );
514
+        wpinv_set_checkout_session($data);
515 515
         
516 516
         $response               = array();
517 517
         $response['success']    = false;
518
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
518
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
519 519
         $response['data']['code'] = $discount_code;
520 520
         
521
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
522
-            $discounts = wpinv_set_cart_discount( $discount_code );
521
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
522
+            $discounts = wpinv_set_cart_discount($discount_code);
523 523
             
524 524
             $response['success'] = true;
525
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
526
-        }  else {
525
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
526
+        } else {
527 527
             $errors = wpinv_get_errors();
528
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
528
+            if (!empty($errors['wpinv-discount-error'])) {
529 529
                 $response['msg'] = $errors['wpinv-discount-error'];
530 530
             }
531
-            wpinv_unset_error( 'wpinv-discount-error' );
531
+            wpinv_unset_error('wpinv-discount-error');
532 532
         }
533 533
         
534 534
         wpinv_set_checkout_session($checkout_session);
535 535
         
536
-        wp_send_json( $response );
536
+        wp_send_json($response);
537 537
     }
538 538
     
539 539
     public static function admin_remove_discount() {
540 540
         global $wpi_userID;
541 541
         
542
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
543
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
542
+        check_ajax_referer('wpinv-nonce', '_nonce');
543
+        if (!wpinv_current_user_can_manage_invoicing()) {
544 544
             die(-1);
545 545
         }
546 546
         
547
-        $invoice_id = absint( $_POST['invoice_id'] );
548
-        $discount_code = sanitize_text_field( $_POST['code'] );
549
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
547
+        $invoice_id = absint($_POST['invoice_id']);
548
+        $discount_code = sanitize_text_field($_POST['code']);
549
+        if (empty($invoice_id) || empty($discount_code)) {
550 550
             die();
551 551
         }
552 552
         
553
-        $invoice = wpinv_get_invoice( $invoice_id );
554
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
553
+        $invoice = wpinv_get_invoice($invoice_id);
554
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
555 555
             die();
556 556
         }
557 557
         
@@ -559,38 +559,38 @@  discard block
 block discarded – undo
559 559
         
560 560
         $data                   = array();
561 561
         $data['invoice_id']     = $invoice_id;
562
-        $data['cart_discounts'] = $invoice->get_discounts( true );
562
+        $data['cart_discounts'] = $invoice->get_discounts(true);
563 563
         
564
-        wpinv_set_checkout_session( $data );
564
+        wpinv_set_checkout_session($data);
565 565
         
566 566
         $response               = array();
567 567
         $response['success']    = false;
568 568
         $response['msg']        = NULL;
569 569
         
570
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
570
+        $discounts = wpinv_unset_cart_discount($discount_code);
571 571
         $response['success'] = true;
572
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
572
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
573 573
         
574 574
         wpinv_set_checkout_session($checkout_session);
575 575
         
576
-        wp_send_json( $response );
576
+        wp_send_json($response);
577 577
     }
578 578
     
579 579
     public static function check_email() {
580
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
581
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
580
+        check_ajax_referer('wpinv-nonce', '_nonce');
581
+        if (!wpinv_current_user_can_manage_invoicing()) {
582 582
             die(-1);
583 583
         }
584 584
         
585
-        $email = sanitize_text_field( $_POST['email'] );
585
+        $email = sanitize_text_field($_POST['email']);
586 586
         
587 587
         $response = array();
588
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
588
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
589 589
             $user_id            = $user_data->ID;
590 590
             $user_login         = $user_data->user_login;
591 591
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
592 592
             $billing_details    = wpinv_get_user_address($user_id);
593
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
593
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
594 594
             
595 595
             if (isset($billing_details['user_id'])) {
596 596
                 unset($billing_details['user_id']);
@@ -606,54 +606,54 @@  discard block
 block discarded – undo
606 606
             $response['data']['billing_details']    = $billing_details;
607 607
         }
608 608
         
609
-        wp_send_json( $response );
609
+        wp_send_json($response);
610 610
     }
611 611
     
612 612
     public static function run_tool() {
613
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
614
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
613
+        check_ajax_referer('wpinv-nonce', '_nonce');
614
+        if (!wpinv_current_user_can_manage_invoicing()) {
615 615
             die(-1);
616 616
         }
617 617
         
618
-        $tool = sanitize_text_field( $_POST['tool'] );
618
+        $tool = sanitize_text_field($_POST['tool']);
619 619
         
620
-        do_action( 'wpinv_run_tool' );
620
+        do_action('wpinv_run_tool');
621 621
         
622
-        if ( !empty( $tool ) ) {
623
-            do_action( 'wpinv_tool_' . $tool );
622
+        if (!empty($tool)) {
623
+            do_action('wpinv_tool_' . $tool);
624 624
         }
625 625
     }
626 626
     
627 627
     public static function apply_discount() {
628 628
         global $wpi_userID;
629 629
         
630
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
630
+        check_ajax_referer('wpinv-nonce', '_nonce');
631 631
         
632 632
         $response = array();
633 633
         
634
-        if ( isset( $_POST['code'] ) ) {
635
-            $discount_code = sanitize_text_field( $_POST['code'] );
634
+        if (isset($_POST['code'])) {
635
+            $discount_code = sanitize_text_field($_POST['code']);
636 636
 
637 637
             $response['success']        = false;
638 638
             $response['msg']            = '';
639 639
             $response['data']['code']   = $discount_code;
640 640
             
641 641
             $invoice = wpinv_get_invoice_cart();
642
-            if ( empty( $invoice->ID ) ) {
643
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
644
-                wp_send_json( $response );
642
+            if (empty($invoice->ID)) {
643
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
644
+                wp_send_json($response);
645 645
             }
646 646
 
647 647
             $wpi_userID = $invoice->get_user_id();
648 648
 
649
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
650
-                $discount       = wpinv_get_discount_by_code( $discount_code );
651
-                $discounts      = wpinv_set_cart_discount( $discount_code );
652
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
653
-                $total          = wpinv_get_cart_total( null, $discounts );
654
-                $cart_totals    = wpinv_recalculate_tax( true );
649
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
650
+                $discount       = wpinv_get_discount_by_code($discount_code);
651
+                $discounts      = wpinv_set_cart_discount($discount_code);
652
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
653
+                $total          = wpinv_get_cart_total(null, $discounts);
654
+                $cart_totals    = wpinv_recalculate_tax(true);
655 655
             
656
-                if ( !empty( $cart_totals ) ) {
656
+                if (!empty($cart_totals)) {
657 657
                     $response['success']        = true;
658 658
                     $response['data']           = $cart_totals;
659 659
                     $response['data']['code']   = $discount_code;
@@ -662,29 +662,29 @@  discard block
 block discarded – undo
662 662
                 }
663 663
             } else {
664 664
                 $errors = wpinv_get_errors();
665
-                $response['msg']  = $errors['wpinv-discount-error'];
666
-                wpinv_unset_error( 'wpinv-discount-error' );
665
+                $response['msg'] = $errors['wpinv-discount-error'];
666
+                wpinv_unset_error('wpinv-discount-error');
667 667
             }
668 668
 
669 669
             // Allow for custom discount code handling
670
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
670
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
671 671
         }
672 672
         
673
-        wp_send_json( $response );
673
+        wp_send_json($response);
674 674
     }
675 675
     
676 676
     public static function remove_discount() {
677
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
677
+        check_ajax_referer('wpinv-nonce', '_nonce');
678 678
         
679 679
         $response = array();
680 680
         
681
-        if ( isset( $_POST['code'] ) ) {
682
-            $discount_code  = sanitize_text_field( $_POST['code'] );
683
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
684
-            $total          = wpinv_get_cart_total( null, $discounts );
685
-            $cart_totals    = wpinv_recalculate_tax( true );
681
+        if (isset($_POST['code'])) {
682
+            $discount_code  = sanitize_text_field($_POST['code']);
683
+            $discounts      = wpinv_unset_cart_discount($discount_code);
684
+            $total          = wpinv_get_cart_total(null, $discounts);
685
+            $cart_totals    = wpinv_recalculate_tax(true);
686 686
             
687
-            if ( !empty( $cart_totals ) ) {
687
+            if (!empty($cart_totals)) {
688 688
                 $response['success']        = true;
689 689
                 $response['data']           = $cart_totals;
690 690
                 $response['data']['code']   = $discount_code;
@@ -693,10 +693,10 @@  discard block
 block discarded – undo
693 693
             }
694 694
             
695 695
             // Allow for custom discount code handling
696
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
696
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
697 697
         }
698 698
         
699
-        wp_send_json( $response );
699
+        wp_send_json($response);
700 700
     }
701 701
 
702 702
     /**
@@ -708,74 +708,74 @@  discard block
 block discarded – undo
708 708
         global $invoicing, $wpi_checkout_id, $cart_total;
709 709
 
710 710
         // Check nonce.
711
-        if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) {
712
-            wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) );
711
+        if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) {
712
+            wp_send_json_error(__('Security checks failed.', 'invoicing'));
713 713
         }
714 714
 
715 715
         // Prepare submitted data...
716
-        $data = wp_unslash( $_POST );
716
+        $data = wp_unslash($_POST);
717 717
 
718 718
         // ... form fields...
719
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
720
-            wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) );
719
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
720
+            wp_send_json_error(__('This payment form is no longer active.', 'invoicing'));
721 721
         }
722 722
 
723
-        if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) {
724
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
723
+        if (empty($data['billing_email']) || !is_email($data['billing_email'])) {
724
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
725 725
         }
726 726
 
727 727
         $prepared = array(
728
-            'billing_email'                    => sanitize_email( $data['billing_email'] ),
729
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ),
730
-            __( 'Form Id', 'invoicing' )       => absint( $data['form_id'] ),
728
+            'billing_email'                    => sanitize_email($data['billing_email']),
729
+            __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']),
730
+            __('Form Id', 'invoicing')       => absint($data['form_id']),
731 731
         );
732 732
 
733
-        $prepared['billing_email'] = sanitize_email( $data['billing_email'] );
733
+        $prepared['billing_email'] = sanitize_email($data['billing_email']);
734 734
 
735
-        $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] );
735
+        $fields = $invoicing->form_elements->get_form_elements($data['form_id']);
736 736
 
737 737
         // ... and form items.
738
-        $items          = $invoicing->form_elements->get_form_items( $data['form_id'] );
738
+        $items          = $invoicing->form_elements->get_form_items($data['form_id']);
739 739
         $prepared_items = array();
740 740
 
741
-        if ( ! empty( $data['wpinv-items'] ) ) {
741
+        if (!empty($data['wpinv-items'])) {
742 742
 
743
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
743
+            $selected_items = wpinv_clean($data['wpinv-items']);
744 744
 
745
-            foreach ( $items as $item ) {
745
+            foreach ($items as $item) {
746 746
 
747
-                if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) {
748
-                    wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) );
747
+                if (!empty($item['required']) && !isset($selected_items[$item['id']])) {
748
+                    wp_send_json_error(__('A required item is missing.', 'invoicing'));
749 749
                 }
750 750
 
751
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
751
+                if (!isset($selected_items[$item['id']])) {
752 752
                     continue;
753 753
                 }
754 754
 
755 755
                 $quantity = 1;
756 756
 
757
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
757
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
758 758
 
759
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
759
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
760 760
 
761
-                    if ( empty( $quantity ) ) {
761
+                    if (empty($quantity)) {
762 762
                         $quantity = 1;
763 763
                     }
764 764
                 }
765 765
 
766 766
                 // Custom pricing.
767
-                if ( ! empty( $item['custom_price'] ) ) {
767
+                if (!empty($item['custom_price'])) {
768 768
 
769
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
770
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
769
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
770
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
771 771
 
772
-                    if ( $set_price < $minimum_price ) {
773
-                        wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) );
772
+                    if ($set_price < $minimum_price) {
773
+                        wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing'));
774 774
                     }
775 775
 
776 776
                     $prepared_items[] = array(
777 777
                         'id'           =>$item['id'],
778
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
778
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
779 779
                         'custom_price' => $set_price,
780 780
                         'name'         => $item['title'],
781 781
                         'quantity'     => $quantity,
@@ -785,8 +785,8 @@  discard block
 block discarded – undo
785 785
 
786 786
                     $prepared_items[] = array(
787 787
                         'id'           => $item['id'],
788
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
789
-                        'custom_price' => wpinv_sanitize_amount( $item['price'] ),
788
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
789
+                        'custom_price' => wpinv_sanitize_amount($item['price']),
790 790
                         'name'         => $item['title'],
791 791
                         'quantity'     => $quantity,
792 792
                     );
@@ -797,45 +797,45 @@  discard block
 block discarded – undo
797 797
 
798 798
         } else {
799 799
 
800
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
800
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
801 801
 
802 802
         }
803 803
 
804 804
         // Are all required fields provided?
805
-        foreach ( $fields as $field ) {
805
+        foreach ($fields as $field) {
806 806
 
807
-            if ( ! empty( $field['premade'] ) ) {
807
+            if (!empty($field['premade'])) {
808 808
                 continue;
809 809
             }
810 810
 
811
-            if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) {
812
-                wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
811
+            if (!empty($field['required']) && empty($data[$field['id']])) {
812
+                wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
813 813
             }
814 814
 
815
-            if ( isset( $data[ $field['id'] ] ) ) {
815
+            if (isset($data[$field['id']])) {
816 816
                 $label = $field['id'];
817 817
 
818
-                if ( isset( $field['label'] ) ) {
818
+                if (isset($field['label'])) {
819 819
                     $label = $field['label'];
820 820
                 }
821 821
 
822
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
822
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
823 823
             }
824 824
 
825 825
         }
826 826
         
827
-        $user = get_user_by( 'email', $prepared['billing_email'] );
827
+        $user = get_user_by('email', $prepared['billing_email']);
828 828
 
829
-        if ( empty( $user ) ) {
830
-            $user = wpinv_create_user( $prepared['billing_email'] );
829
+        if (empty($user)) {
830
+            $user = wpinv_create_user($prepared['billing_email']);
831 831
         }
832 832
 
833
-        if ( is_wp_error( $user ) ) {
834
-            wp_send_json_error( $user->get_error_message() );
833
+        if (is_wp_error($user)) {
834
+            wp_send_json_error($user->get_error_message());
835 835
         }
836 836
 
837
-        if ( is_numeric( $user ) ) {
838
-            $user = get_user_by( 'id', $user );
837
+        if (is_numeric($user)) {
838
+            $user = get_user_by('id', $user);
839 839
         }
840 840
 
841 841
         // Create the invoice.
@@ -849,36 +849,36 @@  discard block
 block discarded – undo
849 849
             true
850 850
         );
851 851
 
852
-        if ( is_wp_error( $created ) ) {
853
-            wp_send_json_error( $created->get_error_message() );
852
+        if (is_wp_error($created)) {
853
+            wp_send_json_error($created->get_error_message());
854 854
         }
855 855
 
856
-        if ( empty( $created ) ) {
857
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
856
+        if (empty($created)) {
857
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
858 858
         }
859 859
 
860
-        unset( $prepared['billing_email'] );
861
-        update_post_meta( $created->ID, 'payment_form_data', $prepared );
860
+        unset($prepared['billing_email']);
861
+        update_post_meta($created->ID, 'payment_form_data', $prepared);
862 862
 
863 863
         $wpi_checkout_id = $created->ID;
864 864
         $cart_total = wpinv_price(
865 865
             wpinv_format_amount(
866
-                wpinv_get_cart_total( $created->get_cart_details(), NULL, $created ) ),
866
+                wpinv_get_cart_total($created->get_cart_details(), NULL, $created) ),
867 867
                 $created->get_currency()
868 868
         );
869 869
         ob_start();
870
-            $form_action  = esc_url( wpinv_get_checkout_uri() );
870
+            $form_action = esc_url(wpinv_get_checkout_uri());
871 871
             echo '<form id="wpinv_checkout_form" action="' . $form_action . '" method="POST" class="wpi-form wpi-payment-form-checkout-form mt-4">';
872 872
             
873
-                echo wpinv_display_line_items( $created->ID );
873
+                echo wpinv_display_line_items($created->ID);
874 874
 
875 875
                 echo "<div class='mt-4'>";
876
-                    do_action( 'wpinv_payment_mode_select' );
877
-                    do_action( 'wpinv_checkout_form_bottom' );
876
+                    do_action('wpinv_payment_mode_select');
877
+                    do_action('wpinv_checkout_form_bottom');
878 878
                 echo "</div>";
879 879
 
880 880
             echo "</form>";
881
-        wp_send_json_success( ob_get_clean() );
881
+        wp_send_json_success(ob_get_clean());
882 882
 
883 883
     }
884 884
 
@@ -890,53 +890,53 @@  discard block
 block discarded – undo
890 890
     public static function buy_items() {
891 891
         $user_id = get_current_user_id();
892 892
 
893
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
894
-            wp_send_json( array(
895
-                'success' => wp_login_url( wp_get_referer() )
896
-            ) );
893
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
894
+            wp_send_json(array(
895
+                'success' => wp_login_url(wp_get_referer())
896
+            ));
897 897
         } else {
898 898
             // Only check nonce if logged in as it could be cached when logged out.
899
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
900
-                wp_send_json( array(
901
-                    'error' => __( 'Security checks failed.', 'invoicing' )
902
-                ) );
899
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
900
+                wp_send_json(array(
901
+                    'error' => __('Security checks failed.', 'invoicing')
902
+                ));
903 903
                 wp_die();
904 904
             }
905 905
 
906 906
             // allow to set a custom price through post_id
907 907
             $items = $_POST['items'];
908
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
909
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
908
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
909
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
910 910
 
911 911
             $cart_items = array();
912
-            if ( $items ) {
913
-                $items = explode( ',', $items );
912
+            if ($items) {
913
+                $items = explode(',', $items);
914 914
 
915
-                foreach( $items as $item ) {
915
+                foreach ($items as $item) {
916 916
                     $item_id = $item;
917 917
                     $quantity = 1;
918 918
 
919
-                    if ( strpos( $item, '|' ) !== false ) {
920
-                        $item_parts = explode( '|', $item );
919
+                    if (strpos($item, '|') !== false) {
920
+                        $item_parts = explode('|', $item);
921 921
                         $item_id = $item_parts[0];
922 922
                         $quantity = $item_parts[1];
923 923
                     }
924 924
 
925
-                    if ( $item_id && $quantity ) {
925
+                    if ($item_id && $quantity) {
926 926
                         $cart_items_arr = array(
927
-                            'id'            => (int)$item_id,
928
-                            'quantity'      => (int)$quantity
927
+                            'id'            => (int) $item_id,
928
+                            'quantity'      => (int) $quantity
929 929
                         );
930 930
 
931 931
                         // If there is a related post id then add it to meta
932
-                        if ( $related_post_id ) {
932
+                        if ($related_post_id) {
933 933
                             $cart_items_arr['meta'] = array(
934 934
                                 'post_id'   => $related_post_id
935 935
                             );
936 936
                         }
937 937
 
938 938
                         // If there is a custom price then set it.
939
-                        if ( $custom_item_price ) {
939
+                        if ($custom_item_price) {
940 940
                             $cart_items_arr['custom_price'] = $custom_item_price;
941 941
                         }
942 942
 
@@ -952,37 +952,37 @@  discard block
 block discarded – undo
952 952
              * @param int $related_post_id The related post id if any.
953 953
              * @since 1.0.0
954 954
              */
955
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
955
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
956 956
 
957 957
             // Make sure its not in the cart already, if it is then redirect to checkout.
958 958
             $cart_invoice = wpinv_get_invoice_cart();
959 959
 
960
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
961
-                wp_send_json( array(
960
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
961
+                wp_send_json(array(
962 962
                     'success' =>  $cart_invoice->get_checkout_payment_url()
963
-                ) );
963
+                ));
964 964
                 wp_die();
965 965
             }
966 966
 
967 967
             // Check if user has invoice with same items waiting to be paid.
968
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
969
-            if ( !empty( $user_invoices ) ) {
970
-                foreach( $user_invoices as $user_invoice ) {
968
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
969
+            if (!empty($user_invoices)) {
970
+                foreach ($user_invoices as $user_invoice) {
971 971
                     $user_cart_details = array();
972
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
972
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
973 973
                     $cart_details = $invoice->get_cart_details();
974 974
 
975
-                    if ( !empty( $cart_details ) ) {
976
-                        foreach ( $cart_details as $invoice_item ) {
975
+                    if (!empty($cart_details)) {
976
+                        foreach ($cart_details as $invoice_item) {
977 977
                             $ii_arr = array();
978
-                            $ii_arr['id'] = (int)$invoice_item['id'];
979
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
978
+                            $ii_arr['id'] = (int) $invoice_item['id'];
979
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
980 980
 
981
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
981
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
982 982
                                 $ii_arr['meta'] = $invoice_item['meta'];
983 983
                             }
984 984
 
985
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
985
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
986 986
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
987 987
                             }
988 988
 
@@ -990,17 +990,17 @@  discard block
 block discarded – undo
990 990
                         }
991 991
                     }
992 992
 
993
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
994
-                        wp_send_json( array(
993
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
994
+                        wp_send_json(array(
995 995
                             'success' =>  $invoice->get_checkout_payment_url()
996
-                        ) );
996
+                        ));
997 997
                         wp_die();
998 998
                     }
999 999
                 }
1000 1000
             }
1001 1001
 
1002 1002
             // Create invoice and send user to checkout
1003
-            if ( !empty( $cart_items ) ) {
1003
+            if (!empty($cart_items)) {
1004 1004
                 $invoice_data = array(
1005 1005
                     'status'        =>  'wpi-pending',
1006 1006
                     'created_via'   =>  'wpi',
@@ -1008,21 +1008,21 @@  discard block
 block discarded – undo
1008 1008
                     'cart_details'  =>  $cart_items,
1009 1009
                 );
1010 1010
 
1011
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1011
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1012 1012
 
1013
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1014
-                    wp_send_json( array(
1013
+                if (!empty($invoice) && isset($invoice->ID)) {
1014
+                    wp_send_json(array(
1015 1015
                         'success' =>  $invoice->get_checkout_payment_url()
1016
-                    ) );
1016
+                    ));
1017 1017
                 } else {
1018
-                    wp_send_json( array(
1019
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1020
-                    ) );
1018
+                    wp_send_json(array(
1019
+                        'error' => __('Invoice failed to create', 'invoicing')
1020
+                    ));
1021 1021
                 }
1022 1022
             } else {
1023
-                wp_send_json( array(
1024
-                    'error' => __( 'Items not valid.', 'invoicing' )
1025
-                ) );
1023
+                wp_send_json(array(
1024
+                    'error' => __('Items not valid.', 'invoicing')
1025
+                ));
1026 1026
             }
1027 1027
         }
1028 1028
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-details.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@  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 7
 class WPInv_Meta_Box_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat;
10 10
 
11 11
         $currency_symbol    = wpinv_currency_symbol();
12
-        $statuses           = wpinv_get_invoice_statuses( true );
12
+        $statuses           = wpinv_get_invoice_statuses(true);
13 13
 
14
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
15
-        $invoice            = new WPInv_Invoice( $post_id );
16
-        $status             = $invoice->get_status( false ); // Current status    
14
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
15
+        $invoice            = new WPInv_Invoice($post_id);
16
+        $status             = $invoice->get_status(false); // Current status    
17 17
         $discount           = $invoice->get_discount();
18 18
         $discount_code      = $discount > 0 ? $invoice->get_discount_code() : '';
19 19
         $invoice_number     = $invoice->get_number();
20 20
         $taxable            = $invoice->is_taxable();
21 21
 
22 22
         $date_created       = $invoice->get_created_date();
23
-        $datetime_created   = strtotime( $date_created );
24
-        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : '';
23
+        $datetime_created   = strtotime($date_created);
24
+        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : '';
25 25
         $date_completed     = $invoice->get_completed_date();
26
-        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a';
27
-        $title['status'] = __( 'Invoice Status:', 'invoicing' );
28
-        $title['number'] = __( 'Invoice Number:', 'invoicing' );
29
-        $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing' );
26
+        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a';
27
+        $title['status'] = __('Invoice Status:', 'invoicing');
28
+        $title['number'] = __('Invoice Number:', 'invoicing');
29
+        $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing');
30 30
 
31 31
         $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice);
32 32
         $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice);
@@ -36,36 +36,36 @@  discard block
 block discarded – undo
36 36
 <div class="gdmbx2-wrap form-table">
37 37
     <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details">
38 38
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created">
39
-            <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div>
40
-            <div class="gdmbx-td"><?php echo $date_created;?></div>
39
+            <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div>
40
+            <div class="gdmbx-td"><?php echo $date_created; ?></div>
41 41
         </div>
42
-        <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?>
42
+        <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft', 'draft')))) { ?>
43 43
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue">
44
-            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div>
44
+            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div>
45 45
             <div class="gdmbx-td">
46
-                <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd">
47
-                <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p>
46
+                <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd">
47
+                <p class="wpi-meta-row wpi-meta-desc"><?php _e('Leave blank to disable sending auto reminder for this invoice.', 'invoicing'); ?></p>
48 48
             </div>
49 49
         </div>
50 50
         <?php } ?>
51
-        <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?>
52
-        <?php if ( $date_completed && $date_completed != 'n/a' ) { ?>
51
+        <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?>
52
+        <?php if ($date_completed && $date_completed != 'n/a') { ?>
53 53
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed">
54
-            <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div>
55
-            <div class="gdmbx-td"><?php echo $date_completed;?></div>
54
+            <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div>
55
+            <div class="gdmbx-td"><?php echo $date_completed; ?></div>
56 56
         </div>
57 57
         <?php } ?>
58
-        <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?>
58
+        <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?>
59 59
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed">
60
-            <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div>
61
-            <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div>
60
+            <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div>
61
+            <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div>
62 62
         </div>
63 63
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status">
64 64
             <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div>
65 65
             <div class="gdmbx-td">
66 66
                 <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2">
67
-                    <?php foreach ( $statuses as $value => $label ) { ?>
68
-                    <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option>
67
+                    <?php foreach ($statuses as $value => $label) { ?>
68
+                    <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option>
69 69
                     <?php } ?>
70 70
                 </select>
71 71
             </div>
@@ -74,129 +74,129 @@  discard block
 block discarded – undo
74 74
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout">
75 75
             <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div>
76 76
             <div class="gdmbx-td">
77
-                <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
77
+                <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
78 78
             </div>
79 79
         </div>
80
-        <?php do_action( 'wpinv_meta_box_details_inner', $post_id );
80
+        <?php do_action('wpinv_meta_box_details_inner', $post_id);
81 81
         $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id);
82 82
         ?>
83 83
 
84
-        <?php if ( $wpinv_euvat->allow_vat_rules() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
84
+        <?php if ($wpinv_euvat->allow_vat_rules() && !($invoice->is_paid() || $invoice->is_refunded())) { ?>
85 85
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-taxable">
86 86
             <div class="gdmbx-th">
87 87
                 <label for="wpinv_taxable">
88
-                    <input type="checkbox" name="disable_taxes" value="1" <?php checked( $taxable, false ); ?> id="wpinv_taxable">
89
-                    <?php _e( 'Disable taxes', 'invoicing' ); ?>
88
+                    <input type="checkbox" name="disable_taxes" value="1" <?php checked($taxable, false); ?> id="wpinv_taxable">
89
+                    <?php _e('Disable taxes', 'invoicing'); ?>
90 90
                 </label>
91 91
             </div>
92 92
         </div>
93 93
         <?php } ?>
94 94
 
95
-        <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?>
95
+        <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?>
96 96
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout">
97
-            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div>
97
+            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div>
98 98
             <div class="gdmbx-td">
99
-                <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
99
+                <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid && !$disable_discount) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
100 100
             </div>
101 101
         </div>
102 102
         <?php } ?>
103 103
     </div>
104 104
 </div>
105 105
 <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout">
106
-    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label>
106
+    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label>
107 107
         <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2">
108
-            <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option>
109
-            <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option>
108
+            <option value="1"><?php _e('Yes', 'invoicing'); ?></option>
109
+            <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option>
110 110
         </select>
111 111
     </p>
112 112
     <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p>
113 113
 </div>
114
-<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?>
114
+<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?>
115 115
         <?php
116 116
     }
117 117
     
118
-    public static function resend_invoice( $post ) {
118
+    public static function resend_invoice($post) {
119 119
         global $wpi_mb_invoice;
120 120
         
121
-        if ( empty( $wpi_mb_invoice ) ) {
121
+        if (empty($wpi_mb_invoice)) {
122 122
             return;
123 123
         }
124 124
         
125 125
         $text = array(
126
-            'message'       => esc_attr__( 'This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing' ),
127
-            'button_text'   =>  __( 'Resend Invoice', 'invoicing' ),
126
+            'message'       => esc_attr__('This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing'),
127
+            'button_text'   =>  __('Resend Invoice', 'invoicing'),
128 128
         );
129 129
             
130 130
         $text = apply_filters('wpinv_resend_invoice_metabox_text', $text);
131
-        do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice );
131
+        do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice);
132 132
         
133
-        if ( $email = $wpi_mb_invoice->get_email() ) {
133
+        if ($email = $wpi_mb_invoice->get_email()) {
134 134
             $email_actions = array();
135
-            $email_actions['email_url']      = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) );
136
-            $email_actions['reminder_url']   = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) );
135
+            $email_actions['email_url']      = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)));
136
+            $email_actions['reminder_url']   = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID));
137 137
             
138
-            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions );
138
+            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions);
139 139
         ?>
140 140
         <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p>
141
-        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
142
-        <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?>
143
-        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
141
+        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
142
+        <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?>
143
+        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
144 144
         <?php } ?>
145 145
         <?php
146 146
         }
147 147
         
148
-        do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice );
148
+        do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice);
149 149
     }
150 150
     
151
-    public static function subscriptions( $post ) {
152
-        $invoice = wpinv_get_invoice( $post->ID );
151
+    public static function subscriptions($post) {
152
+        $invoice = wpinv_get_invoice($post->ID);
153 153
 
154
-        if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) {
155
-            $subscription = wpinv_get_subscription( $invoice );
154
+        if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) {
155
+            $subscription = wpinv_get_subscription($invoice);
156 156
 
157
-            if ( empty( $subscription ) ) {
157
+            if (empty($subscription)) {
158 158
                 ?>
159
-                <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p>
159
+                <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p>
160 160
                 <?php
161 161
                 return;
162 162
             }
163
-            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency );
164
-            $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency;
165
-            $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) );
163
+            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
164
+            $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency;
165
+            $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id));
166 166
             $payments = $subscription->get_child_payments();
167 167
             ?>
168 168
             <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p>
169
-            <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?>
169
+            <?php if (!empty($subscription) && !empty($subscription->id)) { ?>
170 170
                 <p class="wpi-meta-row wpi-sub-id">
171
-                    <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
171
+                    <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
172 172
             <?php } ?>
173 173
             <p class="wpi-meta-row wpi-bill-cycle">
174
-                <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?>
174
+                <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?>
175 175
             </p>
176 176
             <p class="wpi-meta-row wpi-billed-times">
177
-                <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?>
177
+                <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?>
178 178
             </p>
179 179
             <p class="wpi-meta-row wpi-start-date">
180
-                <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?>
180
+                <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?>
181 181
             </p>
182 182
             <p class="wpi-meta-row wpi-end-date">
183
-                <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?>
183
+                <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?>
184 184
             </p>
185
-            <?php if ( $subscription->status ) { ?>
185
+            <?php if ($subscription->status) { ?>
186 186
                 <p class="wpi-meta-row wpi-sub-status">
187
-                    <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
187
+                    <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
188 188
                 </p>
189 189
             <?php } ?>
190
-            <?php if ( !empty( $payments ) ) { ?>
191
-                <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p>
190
+            <?php if (!empty($payments)) { ?>
191
+                <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p>
192 192
                 <ul id="wpi-sub-payments">
193
-                <?php foreach ( $payments as $payment ) {
193
+                <?php foreach ($payments as $payment) {
194 194
                     $invoice_id = $payment->ID;
195 195
                     ?>
196 196
                     <li>
197
-                        <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a>&nbsp;&ndash;&nbsp;
198
-                        <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?>&nbsp;&ndash;&nbsp;</span>
199
-                        <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span>
197
+                        <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a>&nbsp;&ndash;&nbsp;
198
+                        <span><?php echo wpinv_get_invoice_date($invoice_id); ?>&nbsp;&ndash;&nbsp;</span>
199
+                        <span><?php echo wpinv_payment_total($invoice_id, true); ?></span>
200 200
                     </li>
201 201
                 <?php } ?>
202 202
                 </ul>
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
         }
205 205
     }
206 206
     
207
-    public static function renewals( $post ) {
208
-        $invoice = wpinv_get_invoice( $post->ID );
207
+    public static function renewals($post) {
208
+        $invoice = wpinv_get_invoice($post->ID);
209 209
         
210
-        if ( wpinv_is_subscription_payment( $invoice ) ) {
211
-            $parent_url = get_edit_post_link( $invoice->parent_invoice );
212
-            $parent_id  = wpinv_get_invoice_number( $invoice->parent_invoice );
213
-            $subscription = wpinv_get_subscription( $invoice );
210
+        if (wpinv_is_subscription_payment($invoice)) {
211
+            $parent_url = get_edit_post_link($invoice->parent_invoice);
212
+            $parent_id  = wpinv_get_invoice_number($invoice->parent_invoice);
213
+            $subscription = wpinv_get_subscription($invoice);
214 214
         ?>
215
-        <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
216
-        <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p>
215
+        <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
216
+        <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p>
217 217
         <?php
218 218
         }
219 219
     }
@@ -221,47 +221,47 @@  discard block
 block discarded – undo
221 221
     /**
222 222
      * Renders a metabox to edit a payment form.
223 223
      */
224
-    public static function payment_form( $post ) {
225
-        WPInv_Meta_Box_Form_Items::output_options( $post );
224
+    public static function payment_form($post) {
225
+        WPInv_Meta_Box_Form_Items::output_options($post);
226 226
     }
227 227
 
228 228
     /**
229 229
      * Renders a metabox to select items.
230 230
      */
231
-    public static function payment_form_items( $post ) {
232
-        WPInv_Meta_Box_Form_Items::output( $post );
231
+    public static function payment_form_items($post) {
232
+        WPInv_Meta_Box_Form_Items::output($post);
233 233
     }
234 234
     
235
-    public static function payment_meta( $post ) {
235
+    public static function payment_meta($post) {
236 236
         global $wpi_mb_invoice;
237 237
 
238
-        $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false;
239
-        if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) {
238
+        $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false;
239
+        if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) {
240 240
             $set_dateway = true;
241 241
         }
242 242
         
243 243
         ?>
244 244
         <p class="wpi-meta-row">
245
-        <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?>
246
-            <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label>
245
+        <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?>
246
+            <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label>
247 247
             <select required="required" id="wpinv_gateway" class="wpi_select2" name="wpinv_gateway">
248
-                <?php foreach ( $gateways as $name => $gateway ) {
249
-                    if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) {
248
+                <?php foreach ($gateways as $name => $gateway) {
249
+                    if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) {
250 250
                         continue;
251 251
                     }
252 252
                     ?>
253
-                <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
253
+                <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
254 254
                 <?php } ?>
255 255
             </select>
256 256
         <?php } else { 
257
-            echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) );
257
+            echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway));
258 258
         } ?>
259 259
         </p>
260
-        <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?>
261
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p>
260
+        <?php if ($key = $wpi_mb_invoice->get_key()) { ?>
261
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p>
262 262
         <?php } ?>
263
-        <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?>
264
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p>
263
+        <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?>
264
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p>
265 265
         <?php } ?>
266 266
         <?php
267 267
     }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  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 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
 
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
22
+        if (!$use_taxes && (float) $invoice->get_tax() > 0) {
23 23
             $use_taxes = true;
24 24
         }
25
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
25
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
26 26
         $is_recurring       = $invoice->is_recurring();
27 27
         $post_type_object   = get_post_type_object($invoice->post_type);
28 28
         $type_title         = $post_type_object->labels->singular_name;
29 29
 
30 30
         $cols = 5;
31
-        if ( $item_quantities ) {
31
+        if ($item_quantities) {
32 32
             $cols++;
33 33
         }
34
-        if ( $use_taxes ) {
34
+        if ($use_taxes) {
35 35
             $cols++;
36 36
         }
37 37
         $class = '';
38
-        if ( $invoice->is_paid() ) {
38
+        if ($invoice->is_paid()) {
39 39
             $class .= ' wpinv-paid';
40 40
         }
41
-        if ( $invoice->is_refunded() ) {
41
+        if ($invoice->is_refunded()) {
42 42
             $class .= ' wpinv-refunded';
43 43
         }
44
-        if ( $is_recurring ) {
44
+        if ($is_recurring) {
45 45
             $class .= ' wpi-recurring';
46 46
         }
47 47
         ?>
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
50 50
                 <thead>
51 51
                     <tr>
52
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
53
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
54
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
55
-                        <?php if ( $item_quantities ) { ?>
56
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
52
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
53
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
54
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
55
+                        <?php if ($item_quantities) { ?>
56
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
59
-                        <?php if ( $use_taxes ) { ?>
60
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
58
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
59
+                        <?php if ($use_taxes) { ?>
60
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
61 61
                         <?php } ?>
62 62
                         <th class="action"></th>
63 63
                     </tr>
64 64
                 </thead>
65 65
                 <tbody class="wpinv-line-items">
66
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
66
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
67 67
                 </tbody>
68 68
                 <tfoot class="wpinv-totals">
69 69
                     <tr>
@@ -74,45 +74,45 @@  discard block
 block discarded – undo
74 74
                                         <td class="id">
75 75
                                         </td>
76 76
                                         <td class="title">
77
-                                            <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]">
78
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
77
+                                            <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]">
78
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
79 79
                                             <div class="wp-clearfix">
80 80
                                                 <label class="wpi-vat-rule">
81
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
81
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
82 82
                                                     <span class="input-text-wrap">
83
-                                                        <?php echo wpinv_html_select( array(
83
+                                                        <?php echo wpinv_html_select(array(
84 84
                                                             'options'          => $wpinv_euvat->get_rules(),
85 85
                                                             'name'             => '_wpinv_quick[vat_rule]',
86 86
                                                             'id'               => '_wpinv_quick_vat_rule',
87 87
                                                             'show_option_all'  => false,
88 88
                                                             'show_option_none' => false,
89 89
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2',
90
-                                                        ) ); ?>
90
+                                                        )); ?>
91 91
                                                     </span>
92 92
                                                 </label>
93 93
                                             </div>
94
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
94
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-class">
97
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_all_classes(),
101 101
                                                             'name'             => '_wpinv_quick[vat_class]',
102 102
                                                             'id'               => '_wpinv_quick_vat_class',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110 110
                                             <?php } ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-item-type">
113
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $item_types,
117 117
                                                             'name'             => '_wpinv_quick[type]',
118 118
                                                             'id'               => '_wpinv_quick_type',
@@ -120,37 +120,37 @@  discard block
 block discarded – undo
120 120
                                                             'show_option_all'  => false,
121 121
                                                             'show_option_none' => false,
122 122
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type wpi_select2',
123
-                                                        ) ); ?>
123
+                                                        )); ?>
124 124
                                                     </span>
125 125
                                                 </label>
126 126
                                             </div>
127 127
 
128 128
                                             <div class="wp-clearfix">
129 129
                                                 <?php 
130
-                                                    echo wpinv_html_textarea( array(
130
+                                                    echo wpinv_html_textarea(array(
131 131
                                                         'name'  => '_wpinv_quick[excerpt]',
132 132
                                                         'id'    => '_wpinv_quick_excerpt',
133 133
                                                         'value' => '',
134 134
                                                         'class' => 'large-text',
135
-                                                        'label' => __( 'Item description', 'invoicing' ),
136
-                                                    ) ); 
135
+                                                        'label' => __('Item description', 'invoicing'),
136
+                                                    )); 
137 137
                                                 ?>
138 138
                                             </div>
139 139
 
140 140
                                             <div class="wp-clearfix">
141 141
                                                 <label class="wpi-item-actions">
142 142
                                                     <span class="input-text-wrap">
143
-                                                        <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">
143
+                                                        <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">
144 144
                                                     </span>
145 145
                                                 </label>
146 146
                                             </div>
147 147
                                         </td>
148 148
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
149
-                                        <?php if ( $item_quantities ) { ?>
149
+                                        <?php if ($item_quantities) { ?>
150 150
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
151 151
                                         <?php } ?>
152 152
                                         <td class="total"></td>
153
-                                        <?php if ( $use_taxes ) { ?>
153
+                                        <?php if ($use_taxes) { ?>
154 154
                                         <td class="tax"></td>
155 155
                                         <?php } ?>
156 156
                                         <td class="action"></td>
@@ -163,29 +163,29 @@  discard block
 block discarded – undo
163 163
                         <td colspan="<?php echo $cols; ?>"></td>
164 164
                     </tr>
165 165
                     <tr class="totals">
166
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
166
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
167 167
                         <td colspan="4">
168 168
                             <table cellspacing="0" cellpadding="0">
169 169
                                 <tr class="subtotal">
170
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
171
-                                    <td class="total"><?php echo $subtotal;?></td>
170
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
171
+                                    <td class="total"><?php echo $subtotal; ?></td>
172 172
                                     <td class="action"></td>
173 173
                                 </tr>
174 174
                                 <tr class="discount">
175
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
176
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
175
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
176
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
177 177
                                     <td class="action"></td>
178 178
                                 </tr>
179
-                                <?php if ( $use_taxes ) { ?>
179
+                                <?php if ($use_taxes) { ?>
180 180
                                 <tr class="tax">
181
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
182
-                                    <td class="total"><?php echo $tax;?></td>
181
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
182
+                                    <td class="total"><?php echo $tax; ?></td>
183 183
                                     <td class="action"></td>
184 184
                                 </tr>
185 185
                                 <?php } ?>
186 186
                                 <tr class="total">
187
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
188
-                                    <td class="total"><?php echo $total;?></td>
187
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
188
+                                    <td class="total"><?php echo $total; ?></td>
189 189
                                     <td class="action"></td>
190 190
                                 </tr>
191 191
                             </table>
@@ -196,90 +196,90 @@  discard block
 block discarded – undo
196 196
             <div class="wpinv-actions">
197 197
                 <?php ob_start(); ?>
198 198
                 <?php
199
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
200
-                        if ( !$invoice->is_recurring() ) {
201
-                            echo wpinv_item_dropdown( array(
199
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
200
+                        if (!$invoice->is_recurring()) {
201
+                            echo wpinv_item_dropdown(array(
202 202
                                 'name'             => 'wpinv_invoice_item',
203 203
                                 'id'               => 'wpinv_invoice_item',
204 204
                                 'show_recurring'   => true,
205 205
                                 'class'            => 'wpi_select2',
206
-                            ) );
206
+                            ));
207 207
                     ?>
208
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
208
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
209 209
                     <?php } ?>
210
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
211
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
210
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
211
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
212 212
             </div>
213 213
         </div>
214 214
         <?php
215 215
     }
216 216
 
217
-    public static function prices( $post ) {        
217
+    public static function prices($post) {        
218 218
         $symbol         = wpinv_currency_symbol();
219 219
         $position       = wpinv_currency_position();
220
-        $item           = new WPInv_Item( $post->ID );
220
+        $item           = new WPInv_Item($post->ID);
221 221
 
222 222
         $price                = $item->get_price();
223 223
         $is_dynamic_pricing   = $item->get_is_dynamic_pricing();
224 224
         $minimum_price        = $item->get_minimum_price();
225 225
         $is_recurring         = $item->is_recurring();
226 226
         $period               = $item->get_recurring_period();
227
-        $interval             = absint( $item->get_recurring_interval() );
228
-        $times                = absint( $item->get_recurring_limit() );
227
+        $interval             = absint($item->get_recurring_interval());
228
+        $times                = absint($item->get_recurring_limit());
229 229
         $free_trial           = $item->has_free_trial();
230 230
         $trial_interval       = $item->get_trial_interval();
231 231
         $trial_period         = $item->get_trial_period();
232 232
 
233 233
         $intervals            = array();
234
-        for ( $i = 1; $i <= 90; $i++ ) {
234
+        for ($i = 1; $i <= 90; $i++) {
235 235
             $intervals[$i] = $i;
236 236
         }
237 237
 
238
-        $interval       = $interval > 0 ? $interval : 1;
238
+        $interval = $interval > 0 ? $interval : 1;
239 239
 
240 240
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
241 241
 
242 242
         $minimum_price_style = 'margin-left: 24px;';
243
-        if(! $is_dynamic_pricing ) {
243
+        if (!$is_dynamic_pricing) {
244 244
             $minimum_price_style .= 'display: none;';
245 245
         }
246 246
 
247 247
         ?>
248
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
249
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
248
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
249
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
250 250
         </p>
251 251
 
252
-    <?php if( $item->supports_dynamic_pricing() ) { ?>
252
+    <?php if ($item->supports_dynamic_pricing()) { ?>
253 253
 
254 254
         <p class="wpinv-row-name-your-price">
255 255
             <label>
256
-                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> />
257
-                <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?>
256
+                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> />
257
+                <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?>
258 258
             </label>
259
-            <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?>
259
+            <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?>
260 260
         </p>
261 261
 
262 262
         <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>">
263 263
             <label>
264
-                <?php _e( 'Minimum Price', 'invoicing' ); ?>
265
-                <?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?>
264
+                <?php _e('Minimum Price', 'invoicing'); ?>
265
+                <?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?>
266 266
             </label>
267 267
 
268
-            <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?>
268
+            <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?>
269 269
         </p>
270 270
 
271 271
     <?php } ?>
272 272
 
273 273
         <p class="wpinv-row-is-recurring">
274 274
             <label for="wpinv_is_recurring">
275
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
276
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
275
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
276
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
277 277
             </label>
278
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
278
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
279 279
         </p>
280
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
281
-            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
282
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
280
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
281
+            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
282
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
283 283
                 'options'          => $intervals,
284 284
                 'name'             => 'wpinv_recurring_interval',
285 285
                 'id'               => 'wpinv_recurring_interval',
@@ -287,30 +287,30 @@  discard block
 block discarded – undo
287 287
                 'show_option_all'  => false,
288 288
                 'show_option_none' => false,
289 289
                 'class'            => 'wpi_select2',
290
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
291
-            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
290
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
291
+            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
292 292
             <span class="clear wpi-trial-clr"></span>
293 293
             <label class="wpinv-free-trial" for="wpinv_free_trial">
294
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
295
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
294
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> 
295
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
296 296
             </label>
297 297
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
298
-                <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
298
+                <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
299 299
             </label>
300
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
300
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
301 301
         </p>
302
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
303
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
302
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
303
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
304 304
         <?php
305 305
     }
306 306
 
307
-    public static function vat_rules( $post ) {
307
+    public static function vat_rules($post) {
308 308
         global $wpinv_euvat;
309 309
 
310
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
310
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
311 311
         ?>
312
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
313
-        <?php echo wpinv_html_select( array(
312
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
313
+        <?php echo wpinv_html_select(array(
314 314
                     'options'          => $wpinv_euvat->get_rules(),
315 315
                     'name'             => 'wpinv_vat_rules',
316 316
                     'id'               => 'wpinv_vat_rules',
@@ -318,20 +318,20 @@  discard block
 block discarded – undo
318 318
                     'show_option_all'  => false,
319 319
                     'show_option_none' => false,
320 320
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2',
321
-                ) ); ?>
321
+                )); ?>
322 322
         </p>
323
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
324
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
325
-        <p class="wpi-m0"><?php _e( 'Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing' ); ?></p>
323
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
324
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
325
+        <p class="wpi-m0"><?php _e('Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing'); ?></p>
326 326
         <?php
327 327
     }
328 328
 
329
-    public static function vat_classes( $post ) {
329
+    public static function vat_classes($post) {
330 330
         global $wpinv_euvat;
331 331
         
332
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
332
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
333 333
         ?>
334
-        <p><?php echo wpinv_html_select( array(
334
+        <p><?php echo wpinv_html_select(array(
335 335
                     'options'          => $wpinv_euvat->get_all_classes(),
336 336
                     'name'             => 'wpinv_vat_class',
337 337
                     'id'               => 'wpinv_vat_class',
@@ -339,18 +339,18 @@  discard block
 block discarded – undo
339 339
                     'show_option_all'  => false,
340 340
                     'show_option_none' => false,
341 341
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class wpi_select2',
342
-                ) ); ?>
342
+                )); ?>
343 343
         </p>
344
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
344
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
345 345
         <?php
346 346
     }
347 347
 
348
-    public static function item_info( $post ) {
349
-        $item_type = wpinv_get_item_type( $post->ID );
350
-        do_action( 'wpinv_item_info_metabox_before', $post );
348
+    public static function item_info($post) {
349
+        $item_type = wpinv_get_item_type($post->ID);
350
+        do_action('wpinv_item_info_metabox_before', $post);
351 351
         ?>
352
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
353
-        <?php echo wpinv_html_select( array(
352
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
353
+        <?php echo wpinv_html_select(array(
354 354
                     'options'          => wpinv_get_item_types(),
355 355
                     'name'             => 'wpinv_item_type',
356 356
                     'id'               => 'wpinv_item_type',
@@ -358,135 +358,135 @@  discard block
 block discarded – undo
358 358
                     'show_option_all'  => false,
359 359
                     'show_option_none' => false,
360 360
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
361
-                ) ); ?>
361
+                )); ?>
362 362
         </p>
363
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
363
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
364 364
         <?php
365
-        do_action( 'wpinv_item_info_metabox_after', $post );
365
+        do_action('wpinv_item_info_metabox_after', $post);
366 366
     }
367 367
 
368
-    public static function meta_values( $post ) {
369
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
368
+    public static function meta_values($post) {
369
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
370 370
             'type',
371 371
             'custom_id'
372
-        ) );
372
+        ));
373 373
 
374
-        if ( empty( $meta_keys ) ) {
374
+        if (empty($meta_keys)) {
375 375
             return;
376 376
         }
377 377
 
378
-        do_action( 'wpinv_meta_values_metabox_before', $post );
378
+        do_action('wpinv_meta_values_metabox_before', $post);
379 379
 
380
-        foreach ( $meta_keys as $meta_key ) {
380
+        foreach ($meta_keys as $meta_key) {
381 381
             ?>
382
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
382
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
383 383
             <?php 
384 384
         }
385 385
 
386
-        do_action( 'wpinv_meta_values_metabox_after', $post );
386
+        do_action('wpinv_meta_values_metabox_after', $post);
387 387
     }
388 388
 
389
-    public static function save( $post_id, $data, $post ) {
390
-        $invoice        = new WPInv_Invoice( $post_id );
389
+    public static function save($post_id, $data, $post) {
390
+        $invoice        = new WPInv_Invoice($post_id);
391 391
 
392 392
         // Billing
393
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
394
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
395
-        $company        = sanitize_text_field( $data['wpinv_company'] );
396
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
397
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
398
-        $address        = sanitize_text_field( $data['wpinv_address'] );
399
-        $city           = sanitize_text_field( $data['wpinv_city'] );
400
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
401
-        $country        = sanitize_text_field( $data['wpinv_country'] );
402
-        $state          = sanitize_text_field( $data['wpinv_state'] );
393
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
394
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
395
+        $company        = sanitize_text_field($data['wpinv_company']);
396
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
397
+        $phone          = sanitize_text_field($data['wpinv_phone']);
398
+        $address        = sanitize_text_field($data['wpinv_address']);
399
+        $city           = sanitize_text_field($data['wpinv_city']);
400
+        $zip            = sanitize_text_field($data['wpinv_zip']);
401
+        $country        = sanitize_text_field($data['wpinv_country']);
402
+        $state          = sanitize_text_field($data['wpinv_state']);
403 403
 
404 404
         // Details
405
-        $status         = sanitize_text_field( $data['wpinv_status'] );
406
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
407
-        $number         = sanitize_text_field( $data['wpinv_number'] );
408
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
405
+        $status         = sanitize_text_field($data['wpinv_status']);
406
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
407
+        $number         = sanitize_text_field($data['wpinv_number']);
408
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
409 409
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
410 410
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
411 411
 
412 412
         $disable_taxes = 0;
413 413
 
414
-        if ( ! empty( $data['disable_taxes'] ) ) {
414
+        if (!empty($data['disable_taxes'])) {
415 415
             $disable_taxes = 1;
416 416
         }
417 417
 
418
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
419
-
420
-        $invoice->set( 'due_date', $due_date );
421
-        $invoice->set( 'first_name', $first_name );
422
-        $invoice->set( 'last_name', $last_name );
423
-        $invoice->set( 'company', $company );
424
-        $invoice->set( 'vat_number', $vat_number );
425
-        $invoice->set( 'phone', $phone );
426
-        $invoice->set( 'address', $address );
427
-        $invoice->set( 'city', $city );
428
-        $invoice->set( 'zip', $zip );
429
-        $invoice->set( 'country', $country );
430
-        $invoice->set( 'state', $state );
431
-        $invoice->set( 'status', $status );
432
-        $invoice->set( 'set', $status );
418
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
419
+
420
+        $invoice->set('due_date', $due_date);
421
+        $invoice->set('first_name', $first_name);
422
+        $invoice->set('last_name', $last_name);
423
+        $invoice->set('company', $company);
424
+        $invoice->set('vat_number', $vat_number);
425
+        $invoice->set('phone', $phone);
426
+        $invoice->set('address', $address);
427
+        $invoice->set('city', $city);
428
+        $invoice->set('zip', $zip);
429
+        $invoice->set('country', $country);
430
+        $invoice->set('state', $state);
431
+        $invoice->set('status', $status);
432
+        $invoice->set('set', $status);
433 433
         //$invoice->set( 'number', $number );
434 434
         //$invoice->set( 'discounts', $discounts );
435 435
         //$invoice->set( 'discount', $discount );
436
-        $invoice->set( 'disable_taxes', $disable_taxes );
437
-        $invoice->set( 'ip', $ip );
436
+        $invoice->set('disable_taxes', $disable_taxes);
437
+        $invoice->set('ip', $ip);
438 438
         $invoice->old_status = $_POST['original_post_status'];
439 439
         
440 440
         $currency = $invoice->get_currency();
441
-        if ( ! empty( sanitize_text_field( $data['wpinv_currency'] ) ) ) {
442
-            $currency = sanitize_text_field( $data['wpinv_currency'] );
441
+        if (!empty(sanitize_text_field($data['wpinv_currency']))) {
442
+            $currency = sanitize_text_field($data['wpinv_currency']);
443 443
         }
444 444
 
445
-        if ( empty( $currency ) ) {
445
+        if (empty($currency)) {
446 446
             $currency = wpinv_get_currency();
447 447
         }
448 448
 
449
-        if ( ! $invoice->is_paid() ) {
449
+        if (!$invoice->is_paid()) {
450 450
             $invoice->currency = $currency;
451 451
         }
452 452
 
453
-        if ( !empty( $data['wpinv_gateway'] ) ) {
454
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
453
+        if (!empty($data['wpinv_gateway'])) {
454
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
455 455
         }
456 456
         $saved = $invoice->save();
457 457
 
458 458
         // Check for payment notes
459
-        if ( !empty( $data['invoice_note'] ) ) {
460
-            $note               = wp_kses( $data['invoice_note'], array() );
461
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
459
+        if (!empty($data['invoice_note'])) {
460
+            $note               = wp_kses($data['invoice_note'], array());
461
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
462 462
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
463 463
 
464
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
464
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
465 465
         }
466 466
 
467 467
         // Update user address if empty.
468
-        if ( $saved && !empty( $invoice ) ) {
469
-            if ( $user_id = $invoice->get_user_id() ) {
470
-                $user_address = wpinv_get_user_address( $user_id, false );
468
+        if ($saved && !empty($invoice)) {
469
+            if ($user_id = $invoice->get_user_id()) {
470
+                $user_address = wpinv_get_user_address($user_id, false);
471 471
 
472 472
                 if (empty($user_address['first_name'])) {
473
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
474
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
473
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
474
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
475 475
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
476
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
476
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
477 477
                 }
478 478
 
479 479
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
480
-                    update_user_meta( $user_id, '_wpinv_address', $address );
481
-                    update_user_meta( $user_id, '_wpinv_city', $city );
482
-                    update_user_meta( $user_id, '_wpinv_state', $state );
483
-                    update_user_meta( $user_id, '_wpinv_country', $country );
484
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
485
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
480
+                    update_user_meta($user_id, '_wpinv_address', $address);
481
+                    update_user_meta($user_id, '_wpinv_city', $city);
482
+                    update_user_meta($user_id, '_wpinv_state', $state);
483
+                    update_user_meta($user_id, '_wpinv_country', $country);
484
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
485
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
486 486
                 }
487 487
             }
488 488
 
489
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
489
+            do_action('wpinv_invoice_metabox_saved', $invoice);
490 490
         }
491 491
 
492 492
         return $saved;
Please login to merge, or discard this patch.