@@ -7,440 +7,440 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
21 | 21 | return NULL; |
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
25 | - if ( $cart && empty( $invoice_id ) ) { |
|
24 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
25 | + if ($cart && empty($invoice_id)) { |
|
26 | 26 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
27 | 27 | } |
28 | 28 | |
29 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
29 | + $invoice = new WPInv_Invoice($invoice_id); |
|
30 | 30 | return $invoice; |
31 | 31 | } |
32 | 32 | |
33 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
34 | - return wpinv_get_invoice( $invoice_id, true ); |
|
33 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
34 | + return wpinv_get_invoice($invoice_id, true); |
|
35 | 35 | } |
36 | 36 | |
37 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
38 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
37 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
38 | + $invoice = new WPInv_Invoice($invoice_id); |
|
39 | 39 | return $invoice->get_description(); |
40 | 40 | } |
41 | 41 | |
42 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
43 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
42 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
43 | + $invoice = new WPInv_Invoice($invoice_id); |
|
44 | 44 | return $invoice->get_currency(); |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
48 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
47 | +function wpinv_get_payment_user_email($invoice_id) { |
|
48 | + $invoice = new WPInv_Invoice($invoice_id); |
|
49 | 49 | return $invoice->get_email(); |
50 | 50 | } |
51 | 51 | |
52 | -function wpinv_get_user_id( $invoice_id ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
52 | +function wpinv_get_user_id($invoice_id) { |
|
53 | + $invoice = new WPInv_Invoice($invoice_id); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
58 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
57 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
58 | + $invoice = new WPInv_Invoice($invoice_id); |
|
59 | 59 | |
60 | - return $invoice->get_status( $return_label ); |
|
60 | + return $invoice->get_status($return_label); |
|
61 | 61 | } |
62 | 62 | |
63 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
64 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
63 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
64 | + $invoice = new WPInv_Invoice($invoice_id); |
|
65 | 65 | |
66 | - return $invoice->get_gateway( $return_label ); |
|
66 | + return $invoice->get_gateway($return_label); |
|
67 | 67 | } |
68 | 68 | |
69 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
70 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
69 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
70 | + $invoice = new WPInv_Invoice($invoice_id); |
|
71 | 71 | |
72 | 72 | return $invoice->get_gateway_title(); |
73 | 73 | } |
74 | 74 | |
75 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
76 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
75 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
76 | + $invoice = new WPInv_Invoice($invoice_id); |
|
77 | 77 | |
78 | 78 | return $invoice->get_transaction_id(); |
79 | 79 | } |
80 | 80 | |
81 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
81 | +function wpinv_get_id_by_transaction_id($key) { |
|
82 | 82 | global $wpdb; |
83 | 83 | |
84 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
84 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
85 | 85 | |
86 | - if ( $invoice_id != NULL ) |
|
86 | + if ($invoice_id != NULL) |
|
87 | 87 | return $invoice_id; |
88 | 88 | |
89 | 89 | return 0; |
90 | 90 | } |
91 | 91 | |
92 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
93 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
92 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
93 | + $invoice = new WPInv_Invoice($invoice_id); |
|
94 | 94 | |
95 | - return $invoice->get_meta( $meta_key, $single ); |
|
95 | + return $invoice->get_meta($meta_key, $single); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
99 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
98 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
99 | + $invoice = new WPInv_Invoice($invoice_id); |
|
100 | 100 | |
101 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
101 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
102 | 102 | } |
103 | 103 | |
104 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
105 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
104 | +function wpinv_get_items($invoice_id = 0) { |
|
105 | + $invoice = wpinv_get_invoice($invoice_id); |
|
106 | 106 | |
107 | 107 | $items = $invoice->get_items(); |
108 | 108 | $invoice_currency = $invoice->get_currency(); |
109 | 109 | |
110 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
111 | - foreach ( $items as $key => $item ) { |
|
110 | + if (!empty($items) && is_array($items)) { |
|
111 | + foreach ($items as $key => $item) { |
|
112 | 112 | $items[$key]['currency'] = $invoice_currency; |
113 | 113 | |
114 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
114 | + if (!isset($cart_item['subtotal'])) { |
|
115 | 115 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
120 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
121 | 121 | } |
122 | 122 | |
123 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
124 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
123 | +function wpinv_get_fees($invoice_id = 0) { |
|
124 | + $invoice = wpinv_get_invoice($invoice_id); |
|
125 | 125 | $fees = $invoice->get_fees(); |
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
127 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
131 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
130 | +function wpinv_get_invoice_ip($invoice_id) { |
|
131 | + $invoice = new WPInv_Invoice($invoice_id); |
|
132 | 132 | return $invoice->get_ip(); |
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
136 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
135 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
136 | + $invoice = new WPInv_Invoice($invoice_id); |
|
137 | 137 | return $invoice->get_user_info(); |
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
141 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
140 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
141 | + $invoice = new WPInv_Invoice($invoice_id); |
|
142 | 142 | |
143 | - return $invoice->get_subtotal( $currency ); |
|
143 | + return $invoice->get_subtotal($currency); |
|
144 | 144 | } |
145 | 145 | |
146 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
147 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
146 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
147 | + $invoice = new WPInv_Invoice($invoice_id); |
|
148 | 148 | |
149 | - return $invoice->get_tax( $currency ); |
|
149 | + return $invoice->get_tax($currency); |
|
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
153 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
152 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
153 | + $invoice = wpinv_get_invoice($invoice_id); |
|
154 | 154 | |
155 | - return $invoice->get_discount( $currency, $dash ); |
|
155 | + return $invoice->get_discount($currency, $dash); |
|
156 | 156 | } |
157 | 157 | |
158 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
159 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
158 | +function wpinv_discount_code($invoice_id = 0) { |
|
159 | + $invoice = new WPInv_Invoice($invoice_id); |
|
160 | 160 | |
161 | 161 | return $invoice->get_discount_code(); |
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
165 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
164 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
165 | + $invoice = new WPInv_Invoice($invoice_id); |
|
166 | 166 | |
167 | - return $invoice->get_total( $currency ); |
|
167 | + return $invoice->get_total($currency); |
|
168 | 168 | } |
169 | 169 | |
170 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
171 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
170 | +function wpinv_get_date_created($invoice_id = 0) { |
|
171 | + $invoice = new WPInv_Invoice($invoice_id); |
|
172 | 172 | |
173 | 173 | $date_created = $invoice->get_created_date(); |
174 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
174 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
175 | 175 | |
176 | 176 | return $date_created; |
177 | 177 | } |
178 | 178 | |
179 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
180 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
179 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
180 | + $invoice = new WPInv_Invoice($invoice_id); |
|
181 | 181 | |
182 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
182 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
183 | 183 | $date_completed = $invoice->get_completed_date(); |
184 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
185 | - if ( $invoice_date == '' ) { |
|
184 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
185 | + if ($invoice_date == '') { |
|
186 | 186 | $date_created = $invoice->get_created_date(); |
187 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
187 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return $invoice_date; |
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
194 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
193 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
194 | + $invoice = new WPInv_Invoice($invoice_id); |
|
195 | 195 | |
196 | 196 | return $invoice->vat_number; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
199 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice_id); |
|
201 | 201 | |
202 | - return $invoice->add_note( $note, $user_type, $added_by_user ); |
|
202 | + return $invoice->add_note($note, $user_type, $added_by_user); |
|
203 | 203 | } |
204 | 204 | |
205 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
205 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
206 | 206 | global $invoicing; |
207 | 207 | |
208 | - if ( empty( $invoice_id ) ) { |
|
208 | + if (empty($invoice_id)) { |
|
209 | 209 | return NULL; |
210 | 210 | } |
211 | 211 | |
212 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
212 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
213 | 213 | |
214 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
214 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
215 | 215 | } |
216 | 216 | |
217 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
218 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
217 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
218 | + $invoice = new WPInv_Invoice($invoice_id); |
|
219 | 219 | return $invoice->get_key(); |
220 | 220 | } |
221 | 221 | |
222 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
223 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
222 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
223 | + $invoice = new WPInv_Invoice($invoice_id); |
|
224 | 224 | return $invoice->get_number(); |
225 | 225 | } |
226 | 226 | |
227 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
227 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
228 | 228 | $cart_items = wpinv_get_cart_content_details(); |
229 | 229 | $items = array(); |
230 | 230 | |
231 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
231 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
232 | 232 | |
233 | - if( $cart_items ) { |
|
233 | + if ($cart_items) { |
|
234 | 234 | |
235 | - foreach( $cart_items as $item ) { |
|
235 | + foreach ($cart_items as $item) { |
|
236 | 236 | |
237 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
238 | - $items[] = $item; |
|
237 | + if (!in_array($item['id'], $excluded_items)) { |
|
238 | + $items[] = $item; |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
243 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
244 | 244 | |
245 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
245 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
248 | +function wpinv_get_cart_items_subtotal($items) { |
|
249 | 249 | $subtotal = 0.00; |
250 | 250 | |
251 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
252 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
251 | + if (is_array($items) && !empty($items)) { |
|
252 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
253 | 253 | |
254 | - if( is_array( $prices ) ) { |
|
255 | - $subtotal = array_sum( $prices ); |
|
254 | + if (is_array($prices)) { |
|
255 | + $subtotal = array_sum($prices); |
|
256 | 256 | } else { |
257 | 257 | $subtotal = 0.00; |
258 | 258 | } |
259 | 259 | |
260 | - if( $subtotal < 0 ) { |
|
260 | + if ($subtotal < 0) { |
|
261 | 261 | $subtotal = 0.00; |
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
265 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
269 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
270 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
268 | +function wpinv_get_cart_subtotal($items = array()) { |
|
269 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
270 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
271 | 271 | |
272 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
272 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
273 | 273 | } |
274 | 274 | |
275 | -function wpinv_cart_subtotal( $items = array() ) { |
|
276 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
275 | +function wpinv_cart_subtotal($items = array()) { |
|
276 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
277 | 277 | |
278 | 278 | // Todo - Show tax labels here (if needed) |
279 | 279 | |
280 | 280 | return $price; |
281 | 281 | } |
282 | 282 | |
283 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
284 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
285 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
286 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
283 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
284 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
285 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
286 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
287 | 287 | $fees = (float)wpinv_get_cart_fee_total(); |
288 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
288 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
289 | 289 | $total = 0; |
290 | 290 | } else { |
291 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
291 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
292 | 292 | } |
293 | 293 | |
294 | - if ( $total < 0 ) { |
|
294 | + if ($total < 0) { |
|
295 | 295 | $total = 0.00; |
296 | 296 | } |
297 | 297 | |
298 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
298 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
299 | 299 | |
300 | - return wpinv_sanitize_amount( $total ); |
|
300 | + return wpinv_sanitize_amount($total); |
|
301 | 301 | } |
302 | 302 | |
303 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
303 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
304 | 304 | global $cart_total; |
305 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
306 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
305 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
306 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
307 | 307 | |
308 | 308 | // Todo - Show tax labels here (if needed) |
309 | 309 | |
310 | 310 | $cart_total = $total; |
311 | 311 | |
312 | - if ( !$echo ) { |
|
312 | + if (!$echo) { |
|
313 | 313 | return $total; |
314 | 314 | } |
315 | 315 | |
316 | 316 | echo $total; |
317 | 317 | } |
318 | 318 | |
319 | -function wpinv_get_cart_tax( $items = array() ) { |
|
319 | +function wpinv_get_cart_tax($items = array()) { |
|
320 | 320 | $cart_tax = 0; |
321 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
321 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
322 | 322 | |
323 | - if ( $items ) { |
|
324 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
323 | + if ($items) { |
|
324 | + $taxes = wp_list_pluck($items, 'tax'); |
|
325 | 325 | |
326 | - if( is_array( $taxes ) ) { |
|
327 | - $cart_tax = array_sum( $taxes ); |
|
326 | + if (is_array($taxes)) { |
|
327 | + $cart_tax = array_sum($taxes); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | 331 | $cart_tax += wpinv_get_cart_fee_tax(); |
332 | 332 | |
333 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
333 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
334 | 334 | } |
335 | 335 | |
336 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
337 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
338 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
336 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
337 | + $cart_tax = wpinv_get_cart_tax($items); |
|
338 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
339 | 339 | |
340 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
340 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
341 | 341 | |
342 | - if ( !$echo ) { |
|
342 | + if (!$echo) { |
|
343 | 343 | return $tax; |
344 | 344 | } |
345 | 345 | |
346 | 346 | echo $tax; |
347 | 347 | } |
348 | 348 | |
349 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
349 | +function wpinv_get_cart_discount_code($items = array()) { |
|
350 | 350 | $invoice = wpinv_get_invoice_cart(); |
351 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
351 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
352 | 352 | |
353 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
353 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
357 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
356 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
357 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
358 | 358 | |
359 | - if ( $cart_discount_code != '' ) { |
|
359 | + if ($cart_discount_code != '') { |
|
360 | 360 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
361 | 361 | } |
362 | 362 | |
363 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
363 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
364 | 364 | |
365 | - if ( !$echo ) { |
|
365 | + if (!$echo) { |
|
366 | 366 | return $discount_code; |
367 | 367 | } |
368 | 368 | |
369 | 369 | echo $discount_code; |
370 | 370 | } |
371 | 371 | |
372 | -function wpinv_get_cart_discount( $items = array() ) { |
|
372 | +function wpinv_get_cart_discount($items = array()) { |
|
373 | 373 | $invoice = wpinv_get_invoice_cart(); |
374 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
374 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
375 | 375 | |
376 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
376 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
380 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
381 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
379 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
380 | + $cart_discount = wpinv_get_cart_discount($items); |
|
381 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
382 | 382 | |
383 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
383 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
384 | 384 | |
385 | - if ( !$echo ) { |
|
385 | + if (!$echo) { |
|
386 | 386 | return $discount; |
387 | 387 | } |
388 | 388 | |
389 | 389 | echo $discount; |
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
393 | - $item = new WPInv_Item( $item_id ); |
|
392 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
393 | + $item = new WPInv_Item($item_id); |
|
394 | 394 | |
395 | - return $item->get_fees( $type, $item_id ); |
|
395 | + return $item->get_fees($type, $item_id); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | function wpinv_get_cart_fee_total() { |
399 | - $total = 0; |
|
399 | + $total = 0; |
|
400 | 400 | $fees = wpinv_get_cart_fees(); |
401 | 401 | |
402 | - if ( $fees ) { |
|
403 | - foreach ( $fees as $fee_id => $fee ) { |
|
402 | + if ($fees) { |
|
403 | + foreach ($fees as $fee_id => $fee) { |
|
404 | 404 | $total += $fee['amount']; |
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
408 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | function wpinv_get_cart_fee_tax() { |
412 | 412 | $tax = 0; |
413 | 413 | $fees = wpinv_get_cart_fees(); |
414 | 414 | |
415 | - if ( $fees ) { |
|
416 | - foreach ( $fees as $fee_id => $fee ) { |
|
417 | - if( ! empty( $fee['no_tax'] ) ) { |
|
415 | + if ($fees) { |
|
416 | + foreach ($fees as $fee_id => $fee) { |
|
417 | + if (!empty($fee['no_tax'])) { |
|
418 | 418 | continue; |
419 | 419 | } |
420 | 420 | |
421 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
421 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
425 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | function wpinv_cart_has_recurring_item() { |
429 | 429 | $cart_items = wpinv_get_cart_contents(); |
430 | 430 | |
431 | - if ( empty( $cart_items ) ) { |
|
431 | + if (empty($cart_items)) { |
|
432 | 432 | return false; |
433 | 433 | } |
434 | 434 | |
435 | 435 | $has_subscription = false; |
436 | - foreach( $cart_items as $cart_item ) { |
|
437 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
436 | + foreach ($cart_items as $cart_item) { |
|
437 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
438 | 438 | $has_subscription = true; |
439 | 439 | break; |
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
443 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | function wpinv_cart_has_free_trial() { |
@@ -448,85 +448,85 @@ discard block |
||
448 | 448 | |
449 | 449 | $free_trial = false; |
450 | 450 | |
451 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
451 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
452 | 452 | $free_trial = true; |
453 | 453 | } |
454 | 454 | |
455 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
455 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | function wpinv_get_cart_contents() { |
459 | 459 | $cart_details = wpinv_get_cart_details(); |
460 | 460 | |
461 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
461 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | function wpinv_get_cart_content_details() { |
465 | 465 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
466 | 466 | $cart_items = wpinv_get_cart_contents(); |
467 | 467 | |
468 | - if ( empty( $cart_items ) ) { |
|
468 | + if (empty($cart_items)) { |
|
469 | 469 | return false; |
470 | 470 | } |
471 | 471 | $invoice = wpinv_get_invoice_cart(); |
472 | 472 | |
473 | 473 | $details = array(); |
474 | - $length = count( $cart_items ) - 1; |
|
474 | + $length = count($cart_items) - 1; |
|
475 | 475 | |
476 | - if ( empty( $_POST['country'] ) ) { |
|
476 | + if (empty($_POST['country'])) { |
|
477 | 477 | $_POST['country'] = $invoice->country; |
478 | 478 | } |
479 | - if ( !isset( $_POST['state'] ) ) { |
|
479 | + if (!isset($_POST['state'])) { |
|
480 | 480 | $_POST['state'] = $invoice->state; |
481 | 481 | } |
482 | 482 | |
483 | - foreach( $cart_items as $key => $item ) { |
|
484 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
485 | - if ( empty( $item_id ) ) { |
|
483 | + foreach ($cart_items as $key => $item) { |
|
484 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
485 | + if (empty($item_id)) { |
|
486 | 486 | continue; |
487 | 487 | } |
488 | 488 | |
489 | 489 | $wpi_current_id = $invoice->ID; |
490 | 490 | $wpi_item_id = $item_id; |
491 | 491 | |
492 | - $item_price = wpinv_get_item_price( $item_id ); |
|
493 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
494 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
495 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
496 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
492 | + $item_price = wpinv_get_item_price($item_id); |
|
493 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
494 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
495 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
496 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
497 | 497 | |
498 | 498 | $subtotal = $item_price * $quantity; |
499 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
500 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
501 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
499 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
500 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
501 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
502 | 502 | |
503 | - if ( wpinv_prices_include_tax() ) { |
|
504 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
503 | + if (wpinv_prices_include_tax()) { |
|
504 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
505 | 505 | } |
506 | 506 | |
507 | - $total = $subtotal - $discount + $tax; |
|
507 | + $total = $subtotal - $discount + $tax; |
|
508 | 508 | |
509 | 509 | // Do not allow totals to go negatve |
510 | - if( $total < 0 ) { |
|
510 | + if ($total < 0) { |
|
511 | 511 | $total = 0; |
512 | 512 | } |
513 | 513 | |
514 | - $details[ $key ] = array( |
|
514 | + $details[$key] = array( |
|
515 | 515 | 'id' => $item_id, |
516 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
517 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
516 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
517 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
518 | 518 | 'quantity' => $quantity, |
519 | - 'discount' => wpinv_format_amount( $discount, NULL, true ), |
|
520 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
521 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
522 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
519 | + 'discount' => wpinv_format_amount($discount, NULL, true), |
|
520 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
521 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
522 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
523 | 523 | 'vat_rates_class' => $tax_class, |
524 | - 'vat_rate' => wpinv_format_amount( $tax_rate, NULL, true ), |
|
525 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
524 | + 'vat_rate' => wpinv_format_amount($tax_rate, NULL, true), |
|
525 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
526 | 526 | 'fees' => $fees, |
527 | 527 | ); |
528 | 528 | |
529 | - if ( $wpinv_is_last_cart_item ) { |
|
529 | + if ($wpinv_is_last_cart_item) { |
|
530 | 530 | $wpinv_is_last_cart_item = false; |
531 | 531 | $wpinv_flat_discount_total = 0.00; |
532 | 532 | } |
@@ -535,56 +535,56 @@ discard block |
||
535 | 535 | return $details; |
536 | 536 | } |
537 | 537 | |
538 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
538 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
539 | 539 | global $ajax_cart_details; |
540 | 540 | |
541 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
542 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
541 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
542 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
543 | 543 | |
544 | 544 | $invoice_currency = $invoice->currency; |
545 | 545 | |
546 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
547 | - foreach ( $cart_details as $key => $cart_item ) { |
|
548 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
546 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
547 | + foreach ($cart_details as $key => $cart_item) { |
|
548 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
549 | 549 | |
550 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
551 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
550 | + if (!isset($cart_item['subtotal'])) { |
|
551 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | } |
555 | 555 | |
556 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
556 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
557 | 557 | } |
558 | 558 | |
559 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
560 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
559 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
560 | + $invoice = wpinv_get_invoice($invoice_id); |
|
561 | 561 | |
562 | - $old_status = wpinv_status_nicename( $old_status ); |
|
563 | - $new_status = wpinv_status_nicename( $new_status ); |
|
562 | + $old_status = wpinv_status_nicename($old_status); |
|
563 | + $new_status = wpinv_status_nicename($new_status); |
|
564 | 564 | |
565 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
565 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
566 | 566 | |
567 | 567 | // Add note |
568 | - return $invoice->add_note( $status_change, 0 ); |
|
568 | + return $invoice->add_note($status_change, 0); |
|
569 | 569 | } |
570 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
570 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
571 | 571 | |
572 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
572 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
573 | 573 | global $wpi_has_free_trial; |
574 | 574 | |
575 | 575 | $wpi_has_free_trial = false; |
576 | 576 | |
577 | - if ( $old_status == 'publish' ) { |
|
577 | + if ($old_status == 'publish') { |
|
578 | 578 | return; // Make sure that payments are only paid once |
579 | 579 | } |
580 | 580 | |
581 | 581 | // Make sure the payment completion is only processed when new status is paid |
582 | - if ( $new_status != 'publish' ) { |
|
582 | + if ($new_status != 'publish') { |
|
583 | 583 | return; |
584 | 584 | } |
585 | 585 | |
586 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
587 | - if ( empty( $invoice ) ) { |
|
586 | + $invoice = new WPInv_Invoice($invoice_id); |
|
587 | + if (empty($invoice)) { |
|
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
@@ -592,58 +592,58 @@ discard block |
||
592 | 592 | $completed_date = $invoice->completed_date; |
593 | 593 | $cart_details = $invoice->cart_details; |
594 | 594 | |
595 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
595 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
596 | 596 | |
597 | - if ( is_array( $cart_details ) ) { |
|
597 | + if (is_array($cart_details)) { |
|
598 | 598 | // Increase purchase count and earnings |
599 | - foreach ( $cart_details as $cart_index => $item ) { |
|
599 | + foreach ($cart_details as $cart_index => $item) { |
|
600 | 600 | // Ensure these actions only run once, ever |
601 | - if ( empty( $completed_date ) ) { |
|
602 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
601 | + if (empty($completed_date)) { |
|
602 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | 607 | // Check for discount codes and increment their use counts |
608 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
609 | - if( ! empty( $discounts ) ) { |
|
610 | - foreach( $discounts as $code ) { |
|
611 | - wpinv_increase_discount_usage( $code ); |
|
608 | + if ($discounts = $invoice->get_discounts(true)) { |
|
609 | + if (!empty($discounts)) { |
|
610 | + foreach ($discounts as $code) { |
|
611 | + wpinv_increase_discount_usage($code); |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Ensure this action only runs once ever |
617 | - if( empty( $completed_date ) ) { |
|
617 | + if (empty($completed_date)) { |
|
618 | 618 | // Save the completed date |
619 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
619 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
620 | 620 | $invoice->save(); |
621 | 621 | |
622 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
622 | + do_action('wpinv_complete_payment', $invoice_id); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // Empty the shopping cart |
626 | 626 | wpinv_empty_cart(); |
627 | 627 | } |
628 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
628 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
629 | 629 | |
630 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
631 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
630 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
631 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
632 | 632 | |
633 | - if ( empty( $invoice ) ) { |
|
633 | + if (empty($invoice)) { |
|
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | |
637 | - return $invoice->update_status( $new_status ); |
|
637 | + return $invoice->update_status($new_status); |
|
638 | 638 | } |
639 | 639 | |
640 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
640 | +function wpinv_cart_has_fees($type = 'all') { |
|
641 | 641 | return false; |
642 | 642 | } |
643 | 643 | |
644 | 644 | function wpinv_validate_checkout_fields() { |
645 | 645 | // Check if there is $_POST |
646 | - if ( empty( $_POST ) ) { |
|
646 | + if (empty($_POST)) { |
|
647 | 647 | return false; |
648 | 648 | } |
649 | 649 | |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | ); |
656 | 656 | |
657 | 657 | // Validate agree to terms |
658 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
658 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
659 | 659 | wpinv_checkout_validate_agree_to_terms(); |
660 | 660 | } |
661 | 661 | |
662 | - $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
662 | + $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
663 | 663 | |
664 | 664 | // Return collected data |
665 | 665 | return $valid_data; |
@@ -671,20 +671,20 @@ discard block |
||
671 | 671 | $has_subscription = wpinv_cart_has_recurring_item(); |
672 | 672 | |
673 | 673 | // Check if a gateway value is present |
674 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
675 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
674 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
675 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
676 | 676 | |
677 | - if ( '0.00' == wpinv_get_cart_total() ) { |
|
677 | + if ('0.00' == wpinv_get_cart_total()) { |
|
678 | 678 | $gateway = 'manual'; |
679 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
680 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
681 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
682 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
679 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
680 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
681 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
682 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | |
686 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
687 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
686 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
687 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | return $gateway; |
@@ -696,10 +696,10 @@ discard block |
||
696 | 696 | |
697 | 697 | $error = false; |
698 | 698 | // If we have discounts, loop through them |
699 | - if ( ! empty( $discounts ) ) { |
|
700 | - foreach ( $discounts as $discount ) { |
|
699 | + if (!empty($discounts)) { |
|
700 | + foreach ($discounts as $discount) { |
|
701 | 701 | // Check if valid |
702 | - if ( !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) { |
|
702 | + if (!wpinv_is_discount_valid($discount, get_current_user_id())) { |
|
703 | 703 | // Discount is not valid |
704 | 704 | $error = true; |
705 | 705 | } |
@@ -709,20 +709,20 @@ discard block |
||
709 | 709 | return NULL; |
710 | 710 | } |
711 | 711 | |
712 | - if ( $error && !wpinv_get_errors() ) { |
|
713 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
712 | + if ($error && !wpinv_get_errors()) { |
|
713 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
714 | 714 | } |
715 | 715 | |
716 | - return implode( ',', $discounts ); |
|
716 | + return implode(',', $discounts); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | function wpinv_checkout_validate_cc() { |
720 | 720 | $card_data = wpinv_checkout_get_cc_info(); |
721 | 721 | |
722 | 722 | // Validate the card zip |
723 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
724 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
725 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
723 | + if (!empty($card_data['wpinv_zip'])) { |
|
724 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
725 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | |
@@ -732,28 +732,28 @@ discard block |
||
732 | 732 | |
733 | 733 | function wpinv_checkout_get_cc_info() { |
734 | 734 | $cc_info = array(); |
735 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
736 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
737 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
738 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
739 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
740 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
741 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
742 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
743 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
744 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
735 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
736 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
737 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
738 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
739 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
740 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
741 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
742 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
743 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
744 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
745 | 745 | |
746 | 746 | // Return cc info |
747 | 747 | return $cc_info; |
748 | 748 | } |
749 | 749 | |
750 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
750 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
751 | 751 | $ret = false; |
752 | 752 | |
753 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
753 | + if (empty($zip) || empty($country_code)) |
|
754 | 754 | return $ret; |
755 | 755 | |
756 | - $country_code = strtoupper( $country_code ); |
|
756 | + $country_code = strtoupper($country_code); |
|
757 | 757 | |
758 | 758 | $zip_regex = array( |
759 | 759 | "AD" => "AD\d{3}", |
@@ -913,17 +913,17 @@ discard block |
||
913 | 913 | "ZM" => "\d{5}" |
914 | 914 | ); |
915 | 915 | |
916 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
916 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
917 | 917 | $ret = true; |
918 | 918 | |
919 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
919 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | function wpinv_checkout_validate_agree_to_terms() { |
923 | 923 | // Validate agree to terms |
924 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
924 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
925 | 925 | // User did not agree |
926 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
926 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
@@ -936,36 +936,36 @@ discard block |
||
936 | 936 | ); |
937 | 937 | |
938 | 938 | // Verify there is a user_ID |
939 | - if ( $user_ID > 0 ) { |
|
939 | + if ($user_ID > 0) { |
|
940 | 940 | // Get the logged in user data |
941 | - $user_data = get_userdata( $user_ID ); |
|
942 | - $required_fields = wpinv_checkout_required_fields(); |
|
941 | + $user_data = get_userdata($user_ID); |
|
942 | + $required_fields = wpinv_checkout_required_fields(); |
|
943 | 943 | |
944 | 944 | // Loop through required fields and show error messages |
945 | - if ( !empty( $required_fields ) ) { |
|
946 | - foreach ( $required_fields as $field_name => $value ) { |
|
947 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
948 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
945 | + if (!empty($required_fields)) { |
|
946 | + foreach ($required_fields as $field_name => $value) { |
|
947 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
948 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
949 | 949 | } |
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
953 | 953 | // Verify data |
954 | - if ( $user_data ) { |
|
954 | + if ($user_data) { |
|
955 | 955 | // Collected logged in user data |
956 | 956 | $valid_user_data = array( |
957 | 957 | 'user_id' => $user_ID, |
958 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
959 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
960 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
958 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
959 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
960 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
961 | 961 | ); |
962 | 962 | |
963 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
964 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
963 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
964 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
965 | 965 | } |
966 | 966 | } else { |
967 | 967 | // Set invalid user error |
968 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
968 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | |
@@ -973,21 +973,21 @@ discard block |
||
973 | 973 | return $valid_user_data; |
974 | 974 | } |
975 | 975 | |
976 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
976 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
977 | 977 | // Initialize user |
978 | 978 | $user = false; |
979 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
979 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
980 | 980 | |
981 | 981 | /*if ( $is_ajax ) { |
982 | 982 | // Do not create or login the user during the ajax submission (check for errors only) |
983 | 983 | return true; |
984 | - } else */if ( is_user_logged_in() ) { |
|
984 | + } else */if (is_user_logged_in()) { |
|
985 | 985 | // Set the valid user as the logged in collected data |
986 | 986 | $user = $valid_data['logged_in_user']; |
987 | 987 | } |
988 | 988 | |
989 | 989 | // Verify we have an user |
990 | - if ( false === $user || empty( $user ) ) { |
|
990 | + if (false === $user || empty($user)) { |
|
991 | 991 | // Return false |
992 | 992 | return false; |
993 | 993 | } |
@@ -1006,11 +1006,11 @@ discard block |
||
1006 | 1006 | 'zip', |
1007 | 1007 | ); |
1008 | 1008 | |
1009 | - foreach ( $address_fields as $field ) { |
|
1010 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1009 | + foreach ($address_fields as $field) { |
|
1010 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1011 | 1011 | |
1012 | - if ( !empty( $user['user_id'] ) ) { |
|
1013 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1012 | + if (!empty($user['user_id'])) { |
|
1013 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | |
@@ -1018,28 +1018,28 @@ discard block |
||
1018 | 1018 | return $user; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1021 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1022 | 1022 | global $wpi_session; |
1023 | 1023 | |
1024 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1024 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | function wpinv_get_checkout_session() { |
1028 | 1028 | global $wpi_session; |
1029 | 1029 | |
1030 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1030 | + return $wpi_session->get('wpinv_checkout'); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | function wpinv_empty_cart() { |
1034 | 1034 | global $wpi_session; |
1035 | 1035 | |
1036 | 1036 | // Remove cart contents |
1037 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1037 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1038 | 1038 | |
1039 | 1039 | // Remove all cart fees |
1040 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1040 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1041 | 1041 | |
1042 | - do_action( 'wpinv_empty_cart' ); |
|
1042 | + do_action('wpinv_empty_cart'); |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | function wpinv_process_checkout() { |
@@ -1051,42 +1051,42 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | $wpi_checkout_id = $invoice->ID; |
1053 | 1053 | |
1054 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1054 | + do_action('wpinv_pre_process_checkout'); |
|
1055 | 1055 | |
1056 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1056 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1057 | 1057 | $valid_data = false; |
1058 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1058 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1059 | 1059 | } else { |
1060 | 1060 | // Validate the form $_POST data |
1061 | 1061 | $valid_data = wpinv_validate_checkout_fields(); |
1062 | 1062 | |
1063 | 1063 | // Allow themes and plugins to hook to errors |
1064 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1064 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1067 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1068 | 1068 | |
1069 | 1069 | // Validate the user |
1070 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1070 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1071 | 1071 | |
1072 | 1072 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1073 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1073 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1074 | 1074 | |
1075 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1076 | - if ( $is_ajax ) { |
|
1077 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1075 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1076 | + if ($is_ajax) { |
|
1077 | + do_action('wpinv_ajax_checkout_errors'); |
|
1078 | 1078 | die(); |
1079 | 1079 | } else { |
1080 | 1080 | return false; |
1081 | 1081 | } |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - if ( $is_ajax ) { |
|
1084 | + if ($is_ajax) { |
|
1085 | 1085 | // Save address fields. |
1086 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1087 | - foreach ( $address_fields as $field ) { |
|
1088 | - if ( isset( $user[$field] ) ) { |
|
1089 | - $invoice->set( $field, $user[$field] ); |
|
1086 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1087 | + foreach ($address_fields as $field) { |
|
1088 | + if (isset($user[$field])) { |
|
1089 | + $invoice->set($field, $user[$field]); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | $invoice->save(); |
@@ -1094,15 +1094,15 @@ discard block |
||
1094 | 1094 | |
1095 | 1095 | $response['success'] = true; |
1096 | 1096 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1097 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1097 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1098 | 1098 | $response['data']['discount'] = $invoice->get_discount(); |
1099 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1099 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1100 | 1100 | $response['data']['tax'] = $invoice->get_tax(); |
1101 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1101 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1102 | 1102 | $response['data']['total'] = $invoice->get_total(); |
1103 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1103 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1104 | 1104 | |
1105 | - wp_send_json( $response ); |
|
1105 | + wp_send_json($response); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $user_info = array( |
@@ -1124,42 +1124,42 @@ discard block |
||
1124 | 1124 | |
1125 | 1125 | // Setup invoice information |
1126 | 1126 | $invoice_data = array( |
1127 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1127 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1128 | 1128 | 'items' => $cart_items, |
1129 | 1129 | 'cart_discounts' => $discounts, |
1130 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1131 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1132 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1133 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1134 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1130 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1131 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1132 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1133 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1134 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1135 | 1135 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1136 | 1136 | 'user_email' => $user['email'], |
1137 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1138 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1137 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1138 | + 'user_info' => stripslashes_deep($user_info), |
|
1139 | 1139 | 'post_data' => $_POST, |
1140 | 1140 | 'cart_details' => $cart_items, |
1141 | 1141 | 'gateway' => $valid_data['gateway'], |
1142 | 1142 | 'card_info' => $valid_data['cc_info'] |
1143 | 1143 | ); |
1144 | 1144 | |
1145 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1146 | - if ( is_array( $vat_info ) ) { |
|
1145 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1146 | + if (is_array($vat_info)) { |
|
1147 | 1147 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1148 | 1148 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1149 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1149 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1150 | 1150 | |
1151 | 1151 | // Add the VAT rate to each item in the cart |
1152 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1152 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1153 | 1153 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1154 | - $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 ); |
|
1154 | + $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3); |
|
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | // Save vat fields. |
1159 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1160 | - foreach ( $address_fields as $field ) { |
|
1161 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1162 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1159 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1160 | + foreach ($address_fields as $field) { |
|
1161 | + if (isset($invoice_data['user_info'][$field])) { |
|
1162 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | $invoice->save(); |
@@ -1169,49 +1169,49 @@ discard block |
||
1169 | 1169 | $valid_data['user'] = $user; |
1170 | 1170 | |
1171 | 1171 | // Allow themes and plugins to hook before the gateway |
1172 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1172 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1173 | 1173 | |
1174 | 1174 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1175 | - if ( !$invoice_data['price'] ) { |
|
1175 | + if (!$invoice_data['price']) { |
|
1176 | 1176 | // Revert to manual |
1177 | 1177 | $invoice_data['gateway'] = 'manual'; |
1178 | 1178 | $_POST['wpi-gateway'] = 'manual'; |
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | // Allow the invoice data to be modified before it is sent to the gateway |
1182 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1182 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1183 | 1183 | |
1184 | 1184 | // Setup the data we're storing in the purchase session |
1185 | 1185 | $session_data = $invoice_data; |
1186 | 1186 | // Make sure credit card numbers are never stored in sessions |
1187 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1188 | - unset( $session_data['card_info']['card_number'] ); |
|
1187 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1188 | + unset($session_data['card_info']['card_number']); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1192 | - wpinv_set_checkout_session( $invoice_data ); |
|
1192 | + wpinv_set_checkout_session($invoice_data); |
|
1193 | 1193 | |
1194 | 1194 | // Set gateway |
1195 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1196 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
1197 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
1195 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1196 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
1197 | + $invoice->update_meta('_wpinv_checkout', true); |
|
1198 | 1198 | |
1199 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1199 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1200 | 1200 | |
1201 | 1201 | // Send info to the gateway for payment processing |
1202 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1202 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1203 | 1203 | die(); |
1204 | 1204 | } |
1205 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1205 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1206 | 1206 | |
1207 | -function wpinv_get_invoices( $args ) { |
|
1208 | - $args = wp_parse_args( $args, array( |
|
1209 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1207 | +function wpinv_get_invoices($args) { |
|
1208 | + $args = wp_parse_args($args, array( |
|
1209 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1210 | 1210 | 'type' => 'wpi_invoice', |
1211 | 1211 | 'parent' => null, |
1212 | 1212 | 'user' => null, |
1213 | 1213 | 'email' => '', |
1214 | - 'limit' => get_option( 'posts_per_page' ), |
|
1214 | + 'limit' => get_option('posts_per_page'), |
|
1215 | 1215 | 'offset' => null, |
1216 | 1216 | 'page' => 1, |
1217 | 1217 | 'exclude' => array(), |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | 'order' => 'DESC', |
1220 | 1220 | 'return' => 'objects', |
1221 | 1221 | 'paginate' => false, |
1222 | - ) ); |
|
1222 | + )); |
|
1223 | 1223 | |
1224 | 1224 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1225 | 1225 | $map_legacy = array( |
@@ -1232,18 +1232,18 @@ discard block |
||
1232 | 1232 | 'paged' => 'page', |
1233 | 1233 | ); |
1234 | 1234 | |
1235 | - foreach ( $map_legacy as $from => $to ) { |
|
1236 | - if ( isset( $args[ $from ] ) ) { |
|
1237 | - $args[ $to ] = $args[ $from ]; |
|
1235 | + foreach ($map_legacy as $from => $to) { |
|
1236 | + if (isset($args[$from])) { |
|
1237 | + $args[$to] = $args[$from]; |
|
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - if ( get_query_var( 'paged' ) ) |
|
1241 | + if (get_query_var('paged')) |
|
1242 | 1242 | $args['page'] = get_query_var('paged'); |
1243 | - else if ( get_query_var( 'page' ) ) |
|
1244 | - $args['page'] = get_query_var( 'page' ); |
|
1245 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1246 | - $args['page'] = $args[ 'page' ]; |
|
1243 | + else if (get_query_var('page')) |
|
1244 | + $args['page'] = get_query_var('page'); |
|
1245 | + else if (!empty($args['page'])) |
|
1246 | + $args['page'] = $args['page']; |
|
1247 | 1247 | else |
1248 | 1248 | $args['page'] = 1; |
1249 | 1249 | |
@@ -1256,47 +1256,47 @@ discard block |
||
1256 | 1256 | 'post_status' => $args['status'], |
1257 | 1257 | 'posts_per_page' => $args['limit'], |
1258 | 1258 | 'meta_query' => array(), |
1259 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1259 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1260 | 1260 | 'fields' => 'ids', |
1261 | 1261 | 'orderby' => $args['orderby'], |
1262 | 1262 | 'order' => $args['order'], |
1263 | 1263 | ); |
1264 | 1264 | |
1265 | - if ( !empty( $args['user'] ) ) { |
|
1266 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1265 | + if (!empty($args['user'])) { |
|
1266 | + $wp_query_args['author'] = absint($args['user']); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | - if ( ! is_null( $args['parent'] ) ) { |
|
1270 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1269 | + if (!is_null($args['parent'])) { |
|
1270 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1271 | 1271 | } |
1272 | 1272 | |
1273 | - if ( ! is_null( $args['offset'] ) ) { |
|
1274 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1273 | + if (!is_null($args['offset'])) { |
|
1274 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1275 | 1275 | } else { |
1276 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1276 | + $wp_query_args['paged'] = absint($args['page']); |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | - if ( ! empty( $args['exclude'] ) ) { |
|
1280 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1279 | + if (!empty($args['exclude'])) { |
|
1280 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | - if ( ! $args['paginate' ] ) { |
|
1283 | + if (!$args['paginate']) { |
|
1284 | 1284 | $wp_query_args['no_found_rows'] = true; |
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | // Get results. |
1288 | - $invoices = new WP_Query( $wp_query_args ); |
|
1288 | + $invoices = new WP_Query($wp_query_args); |
|
1289 | 1289 | |
1290 | - if ( 'objects' === $args['return'] ) { |
|
1291 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1292 | - } elseif ( 'self' === $args['return'] ) { |
|
1290 | + if ('objects' === $args['return']) { |
|
1291 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1292 | + } elseif ('self' === $args['return']) { |
|
1293 | 1293 | return $invoices; |
1294 | 1294 | } else { |
1295 | 1295 | $return = $invoices->posts; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - if ( $args['paginate' ] ) { |
|
1299 | - return (object) array( |
|
1298 | + if ($args['paginate']) { |
|
1299 | + return (object)array( |
|
1300 | 1300 | 'invoices' => $return, |
1301 | 1301 | 'total' => $invoices->found_posts, |
1302 | 1302 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1308,21 +1308,21 @@ discard block |
||
1308 | 1308 | |
1309 | 1309 | function wpinv_get_user_invoices_columns() { |
1310 | 1310 | $columns = array( |
1311 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1312 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1313 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1314 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1315 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1311 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1312 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
1313 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1314 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1315 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1316 | 1316 | ); |
1317 | 1317 | |
1318 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1318 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1321 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1322 | 1322 | global $wpinv_receipt_args; |
1323 | 1323 | |
1324 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1325 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1324 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1325 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1326 | 1326 | 'price' => true, |
1327 | 1327 | 'discount' => true, |
1328 | 1328 | 'items' => true, |
@@ -1331,185 +1331,185 @@ discard block |
||
1331 | 1331 | 'invoice_key' => false, |
1332 | 1332 | 'payment_method' => true, |
1333 | 1333 | 'invoice_id' => true |
1334 | - ), $atts, 'wpinv_receipt' ); |
|
1334 | + ), $atts, 'wpinv_receipt'); |
|
1335 | 1335 | |
1336 | 1336 | $session = wpinv_get_checkout_session(); |
1337 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1338 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1339 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1337 | + if (isset($_GET['invoice_key'])) { |
|
1338 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1339 | + } else if ($session && isset($session['invoice_key'])) { |
|
1340 | 1340 | $invoice_key = $session['invoice_key']; |
1341 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1341 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1342 | 1342 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1343 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1344 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1343 | + } else if (isset($_GET['invoice-id'])) { |
|
1344 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
1345 | 1345 | } |
1346 | 1346 | |
1347 | 1347 | // No key found |
1348 | - if ( ! isset( $invoice_key ) ) { |
|
1348 | + if (!isset($invoice_key)) { |
|
1349 | 1349 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1350 | 1350 | } |
1351 | 1351 | |
1352 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1353 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1354 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1352 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1353 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1354 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1355 | 1355 | $invoice_id = (int)$_GET['invoice-id']; |
1356 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1356 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1360 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1360 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1361 | 1361 | // login redirect |
1362 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1362 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1365 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1366 | 1366 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1367 | 1367 | } |
1368 | 1368 | |
1369 | 1369 | ob_start(); |
1370 | 1370 | |
1371 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1371 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1372 | 1372 | |
1373 | 1373 | $display = ob_get_clean(); |
1374 | 1374 | |
1375 | 1375 | return $display; |
1376 | 1376 | } |
1377 | 1377 | |
1378 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1378 | +function wpinv_get_invoice_id_by_key($key) { |
|
1379 | 1379 | global $wpdb; |
1380 | 1380 | |
1381 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1381 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1382 | 1382 | |
1383 | - if ( $invoice_id != NULL ) |
|
1383 | + if ($invoice_id != NULL) |
|
1384 | 1384 | return $invoice_id; |
1385 | 1385 | |
1386 | 1386 | return 0; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1389 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1390 | 1390 | $return = false; |
1391 | 1391 | |
1392 | - if ( empty( $invoice_key ) ) { |
|
1392 | + if (empty($invoice_key)) { |
|
1393 | 1393 | return $return; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | 1396 | global $wpinv_receipt_args; |
1397 | 1397 | |
1398 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1399 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1400 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1398 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1399 | + if (isset($_GET['invoice-id'])) { |
|
1400 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
1404 | - $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
|
1403 | + $user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']); |
|
1404 | + $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']); |
|
1405 | 1405 | |
1406 | - if ( is_user_logged_in() ) { |
|
1407 | - if ( $user_id === (int) get_current_user_id() ) { |
|
1406 | + if (is_user_logged_in()) { |
|
1407 | + if ($user_id === (int)get_current_user_id()) { |
|
1408 | 1408 | $return = true; |
1409 | 1409 | } |
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | $session = wpinv_get_checkout_session(); |
1413 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
1414 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
1413 | + if (!empty($session) && !is_user_logged_in()) { |
|
1414 | + if ($session['invoice_key'] === $invoice_meta['key']) { |
|
1415 | 1415 | $return = true; |
1416 | 1416 | } |
1417 | 1417 | } |
1418 | 1418 | |
1419 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1419 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | function wpinv_pay_for_invoice() { |
1423 | 1423 | global $wpinv_euvat; |
1424 | 1424 | |
1425 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1425 | + if (isset($_GET['invoice_key'])) { |
|
1426 | 1426 | $checkout_uri = wpinv_get_checkout_uri(); |
1427 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1427 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1428 | 1428 | |
1429 | - if ( empty( $invoice_key ) ) { |
|
1430 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1431 | - wp_redirect( $checkout_uri ); |
|
1429 | + if (empty($invoice_key)) { |
|
1430 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1431 | + wp_redirect($checkout_uri); |
|
1432 | 1432 | wpinv_die(); |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1435 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1436 | 1436 | |
1437 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1438 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1439 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1437 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1438 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1439 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1440 | 1440 | $invoice_id = (int)$_GET['invoice-id']; |
1441 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1441 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1445 | - if ( $invoice->needs_payment() ) { |
|
1444 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1445 | + if ($invoice->needs_payment()) { |
|
1446 | 1446 | $data = array(); |
1447 | 1447 | $data['invoice_id'] = $invoice_id; |
1448 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1448 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1449 | 1449 | |
1450 | - wpinv_set_checkout_session( $data ); |
|
1450 | + wpinv_set_checkout_session($data); |
|
1451 | 1451 | |
1452 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1452 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1453 | 1453 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
1454 | 1454 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
1455 | 1455 | |
1456 | - wpinv_recalculate_tax( true ); |
|
1456 | + wpinv_recalculate_tax(true); |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | } else { |
1460 | 1460 | $checkout_uri = $invoice->get_view_url(); |
1461 | 1461 | } |
1462 | 1462 | } else { |
1463 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
1463 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
1464 | 1464 | |
1465 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
1465 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
1466 | 1466 | } |
1467 | 1467 | |
1468 | - wp_redirect( $checkout_uri ); |
|
1468 | + wp_redirect($checkout_uri); |
|
1469 | 1469 | wpinv_die(); |
1470 | 1470 | } |
1471 | 1471 | } |
1472 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
1472 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
1473 | 1473 | |
1474 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
1475 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
1476 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1474 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
1475 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
1476 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
1477 | 1477 | $user_id = $invoice->get_user_id(); |
1478 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
1478 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
1479 | 1479 | |
1480 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
1481 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
1480 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
1481 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
1482 | 1482 | |
1483 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
1483 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
1484 | 1484 | wpinv_die(); |
1485 | 1485 | } |
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
1489 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
1489 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
1490 | 1490 | |
1491 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
1492 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
1491 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
1492 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
1493 | 1493 | |
1494 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
1494 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
1495 | 1495 | return false; |
1496 | 1496 | } |
1497 | 1497 | |
1498 | - if ( empty( $transaction_id ) ) { |
|
1498 | + if (empty($transaction_id)) { |
|
1499 | 1499 | $transaction_id = $invoice_id; |
1500 | 1500 | } |
1501 | 1501 | |
1502 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
1502 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
1503 | 1503 | |
1504 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
1504 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
1505 | 1505 | } |
1506 | 1506 | |
1507 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
1508 | - if ( empty( $status_display ) ) { |
|
1509 | - $status_display = wpinv_status_nicename( $status ); |
|
1507 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
1508 | + if (empty($status_display)) { |
|
1509 | + $status_display = wpinv_status_nicename($status); |
|
1510 | 1510 | } |
1511 | 1511 | |
1512 | - switch ( $status ) { |
|
1512 | + switch ($status) { |
|
1513 | 1513 | case 'publish' : |
1514 | 1514 | case 'wpi-renewal' : |
1515 | 1515 | $class = 'label-success'; |
@@ -1534,28 +1534,28 @@ discard block |
||
1534 | 1534 | |
1535 | 1535 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
1536 | 1536 | |
1537 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
1537 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
1538 | 1538 | } |
1539 | 1539 | |
1540 | -function wpinv_format_invoice_number( $number ) { |
|
1541 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
1540 | +function wpinv_format_invoice_number($number) { |
|
1541 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
1542 | 1542 | |
1543 | 1543 | // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release. |
1544 | - if ( $padd === '' || $padd === false || $padd === NULL ) { |
|
1545 | - return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number ); |
|
1544 | + if ($padd === '' || $padd === false || $padd === NULL) { |
|
1545 | + return wp_sprintf(__('WPINV-%d', 'invoicing'), $number); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
1549 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
1548 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
1549 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
1550 | 1550 | |
1551 | - $padd = absint( $padd ); |
|
1552 | - $formatted_number = absint( $number ); |
|
1551 | + $padd = absint($padd); |
|
1552 | + $formatted_number = absint($number); |
|
1553 | 1553 | |
1554 | - if ( $padd > 0 ) { |
|
1555 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
1554 | + if ($padd > 0) { |
|
1555 | + $formatted_number = zeroise($formatted_number, $padd); |
|
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | $formatted_number = $prefix . $formatted_number . $postfix; |
1559 | 1559 | |
1560 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
1560 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
1561 | 1561 | } |
1562 | 1562 | \ No newline at end of file |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | final class WPInv_Invoice { |
15 | - public $ID = 0; |
|
15 | + public $ID = 0; |
|
16 | 16 | public $title; |
17 | 17 | |
18 | 18 | public $pending; |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | public $full_name = ''; |
65 | 65 | public $parent_invoice = 0; |
66 | 66 | |
67 | - public function __construct( $invoice_id = false ) { |
|
68 | - if( empty( $invoice_id ) ) { |
|
67 | + public function __construct($invoice_id = false) { |
|
68 | + if (empty($invoice_id)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - $this->setup_invoice( $invoice_id ); |
|
72 | + $this->setup_invoice($invoice_id); |
|
73 | 73 | } |
74 | 74 | |
75 | - public function get( $key ) { |
|
76 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
77 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
75 | + public function get($key) { |
|
76 | + if (method_exists($this, 'get_' . $key)) { |
|
77 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
78 | 78 | } else { |
79 | 79 | $value = $this->$key; |
80 | 80 | } |
@@ -82,51 +82,51 @@ discard block |
||
82 | 82 | return $value; |
83 | 83 | } |
84 | 84 | |
85 | - public function set( $key, $value ) { |
|
86 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
85 | + public function set($key, $value) { |
|
86 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
87 | 87 | |
88 | - if ( $key === 'status' ) { |
|
88 | + if ($key === 'status') { |
|
89 | 89 | $this->old_status = $this->status; |
90 | 90 | } |
91 | 91 | |
92 | - if ( ! in_array( $key, $ignore ) ) { |
|
93 | - $this->pending[ $key ] = $value; |
|
92 | + if (!in_array($key, $ignore)) { |
|
93 | + $this->pending[$key] = $value; |
|
94 | 94 | } |
95 | 95 | |
96 | - if( '_ID' !== $key ) { |
|
96 | + if ('_ID' !== $key) { |
|
97 | 97 | $this->$key = $value; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - public function _isset( $name ) { |
|
102 | - if ( property_exists( $this, $name) ) { |
|
103 | - return false === empty( $this->$name ); |
|
101 | + public function _isset($name) { |
|
102 | + if (property_exists($this, $name)) { |
|
103 | + return false === empty($this->$name); |
|
104 | 104 | } else { |
105 | 105 | return null; |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | - private function setup_invoice( $invoice_id ) { |
|
109 | + private function setup_invoice($invoice_id) { |
|
110 | 110 | $this->pending = array(); |
111 | 111 | |
112 | - if ( empty( $invoice_id ) ) { |
|
112 | + if (empty($invoice_id)) { |
|
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | |
116 | - $invoice = get_post( $invoice_id ); |
|
116 | + $invoice = get_post($invoice_id); |
|
117 | 117 | |
118 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
118 | + if (!$invoice || is_wp_error($invoice)) { |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
122 | - if( 'wpi_invoice' !== $invoice->post_type ) { |
|
122 | + if ('wpi_invoice' !== $invoice->post_type) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
126 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
126 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
127 | 127 | |
128 | 128 | // Primary Identifier |
129 | - $this->ID = absint( $invoice_id ); |
|
129 | + $this->ID = absint($invoice_id); |
|
130 | 130 | |
131 | 131 | // We have a payment, get the generic payment_meta item to reduce calls to it |
132 | 132 | $this->payment_meta = $this->get_meta(); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $this->post_status = $this->status; |
138 | 138 | $this->mode = $this->setup_mode(); |
139 | 139 | $this->parent_invoice = $invoice->post_parent; |
140 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
140 | + $this->post_name = $this->setup_post_name($invoice); |
|
141 | 141 | $this->status_nicename = $this->setup_status_nicename(); |
142 | 142 | |
143 | 143 | // Items |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | |
160 | 160 | // User based |
161 | 161 | $this->ip = $this->setup_ip(); |
162 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
163 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
162 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
163 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
164 | 164 | |
165 | 165 | $this->user_info = $this->setup_user_info(); |
166 | 166 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $this->company = $this->user_info['company']; |
170 | 170 | $this->vat_number = $this->user_info['vat_number']; |
171 | 171 | $this->vat_rate = $this->user_info['vat_rate']; |
172 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
172 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
173 | 173 | $this->address = $this->user_info['address']; |
174 | 174 | $this->city = $this->user_info['city']; |
175 | 175 | $this->country = $this->user_info['country']; |
@@ -184,48 +184,48 @@ discard block |
||
184 | 184 | // Other Identifiers |
185 | 185 | $this->key = $this->setup_invoice_key(); |
186 | 186 | $this->number = $this->setup_invoice_number(); |
187 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
187 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
188 | 188 | |
189 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
189 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
190 | 190 | |
191 | 191 | // Allow extensions to add items to this object via hook |
192 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
192 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
193 | 193 | |
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | private function setup_status_nicename() { |
198 | - $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
198 | + $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
199 | 199 | |
200 | - $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status ); |
|
200 | + $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status); |
|
201 | 201 | |
202 | 202 | return $status; |
203 | 203 | } |
204 | 204 | |
205 | - private function setup_post_name( $post = NULL ) { |
|
205 | + private function setup_post_name($post = NULL) { |
|
206 | 206 | $post_name = ''; |
207 | 207 | |
208 | - if ( !empty( $post ) ) { |
|
209 | - if( !empty( $post->post_name ) ) { |
|
208 | + if (!empty($post)) { |
|
209 | + if (!empty($post->post_name)) { |
|
210 | 210 | $post_name = $post->post_name; |
211 | - } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) { |
|
212 | - $post_name = sanitize_title( $post->post_title ); |
|
211 | + } else if (!empty($post->ID) && !empty($post->post_title)) { |
|
212 | + $post_name = sanitize_title($post->post_title); |
|
213 | 213 | |
214 | 214 | global $wpdb; |
215 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
215 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - $this->post_name = $post_name; |
|
219 | + $this->post_name = $post_name; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | private function setup_due_date() { |
223 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
223 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
224 | 224 | |
225 | - if ( empty( $due_date ) ) { |
|
226 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
227 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
228 | - } else if ( $due_date == 'none' ) { |
|
225 | + if (empty($due_date)) { |
|
226 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
227 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
228 | + } else if ($due_date == 'none') { |
|
229 | 229 | $due_date = ''; |
230 | 230 | } |
231 | 231 | |
@@ -233,63 +233,63 @@ discard block |
||
233 | 233 | } |
234 | 234 | |
235 | 235 | private function setup_completed_date() { |
236 | - $invoice = get_post( $this->ID ); |
|
236 | + $invoice = get_post($this->ID); |
|
237 | 237 | |
238 | - if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
238 | + if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
239 | 239 | return false; // This invoice was never paid |
240 | 240 | } |
241 | 241 | |
242 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
242 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
243 | 243 | |
244 | 244 | return $date; |
245 | 245 | } |
246 | 246 | |
247 | 247 | private function setup_cart_details() { |
248 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
248 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
249 | 249 | return $cart_details; |
250 | 250 | } |
251 | 251 | |
252 | 252 | public function array_convert() { |
253 | - return get_object_vars( $this ); |
|
253 | + return get_object_vars($this); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | private function setup_items() { |
257 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
257 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
258 | 258 | return $items; |
259 | 259 | } |
260 | 260 | |
261 | 261 | private function setup_fees() { |
262 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
262 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
263 | 263 | return $payment_fees; |
264 | 264 | } |
265 | 265 | |
266 | 266 | private function setup_currency() { |
267 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
267 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
268 | 268 | return $currency; |
269 | 269 | } |
270 | 270 | |
271 | 271 | private function setup_discount() { |
272 | 272 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
273 | - $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total ); |
|
274 | - if ( $discount < 0 ) { |
|
273 | + $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total); |
|
274 | + if ($discount < 0) { |
|
275 | 275 | $discount = 0; |
276 | 276 | } |
277 | - $discount = wpinv_format_amount( $discount, NULL, true ); |
|
277 | + $discount = wpinv_format_amount($discount, NULL, true); |
|
278 | 278 | |
279 | 279 | return $discount; |
280 | 280 | } |
281 | 281 | |
282 | 282 | private function setup_discount_code() { |
283 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
283 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
284 | 284 | return $discount_code; |
285 | 285 | } |
286 | 286 | |
287 | 287 | private function setup_tax() { |
288 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
288 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
289 | 289 | |
290 | 290 | // We don't have tax as it's own meta and no meta was passed |
291 | - if ( '' === $tax ) { |
|
292 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
291 | + if ('' === $tax) { |
|
292 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | return $tax; |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | $subtotal = 0; |
304 | 304 | $cart_details = $this->cart_details; |
305 | 305 | |
306 | - if ( is_array( $cart_details ) ) { |
|
307 | - foreach ( $cart_details as $item ) { |
|
308 | - if ( isset( $item['subtotal'] ) ) { |
|
306 | + if (is_array($cart_details)) { |
|
307 | + foreach ($cart_details as $item) { |
|
308 | + if (isset($item['subtotal'])) { |
|
309 | 309 | $subtotal += $item['subtotal']; |
310 | 310 | } |
311 | 311 | } |
@@ -319,18 +319,18 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | private function setup_discounts() { |
322 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
322 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
323 | 323 | return $discounts; |
324 | 324 | } |
325 | 325 | |
326 | 326 | private function setup_total() { |
327 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
327 | + $amount = $this->get_meta('_wpinv_total', true); |
|
328 | 328 | |
329 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
330 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
331 | - $meta = maybe_unserialize( $meta ); |
|
329 | + if (empty($amount) && '0.00' != $amount) { |
|
330 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
331 | + $meta = maybe_unserialize($meta); |
|
332 | 332 | |
333 | - if ( isset( $meta['amount'] ) ) { |
|
333 | + if (isset($meta['amount'])) { |
|
334 | 334 | $amount = $meta['amount']; |
335 | 335 | } |
336 | 336 | } |
@@ -339,13 +339,13 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | private function setup_mode() { |
342 | - return $this->get_meta( '_wpinv_mode' ); |
|
342 | + return $this->get_meta('_wpinv_mode'); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | private function setup_gateway() { |
346 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
346 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
347 | 347 | |
348 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
348 | + if (empty($gateway) && 'publish' === $this->status) { |
|
349 | 349 | $gateway = 'manual'; |
350 | 350 | } |
351 | 351 | |
@@ -353,23 +353,23 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | private function setup_gateway_title() { |
356 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
356 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
357 | 357 | return $gateway_title; |
358 | 358 | } |
359 | 359 | |
360 | 360 | private function setup_transaction_id() { |
361 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
361 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
362 | 362 | |
363 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
363 | + if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) { |
|
364 | 364 | $gateway = $this->gateway; |
365 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
365 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | return $transaction_id; |
369 | 369 | } |
370 | 370 | |
371 | 371 | private function setup_ip() { |
372 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
372 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
373 | 373 | return $ip; |
374 | 374 | } |
375 | 375 | |
@@ -379,62 +379,62 @@ discard block |
||
379 | 379 | ///} |
380 | 380 | |
381 | 381 | private function setup_first_name() { |
382 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
382 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
383 | 383 | return $first_name; |
384 | 384 | } |
385 | 385 | |
386 | 386 | private function setup_last_name() { |
387 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
387 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
388 | 388 | return $last_name; |
389 | 389 | } |
390 | 390 | |
391 | 391 | private function setup_company() { |
392 | - $company = $this->get_meta( '_wpinv_company' ); |
|
392 | + $company = $this->get_meta('_wpinv_company'); |
|
393 | 393 | return $company; |
394 | 394 | } |
395 | 395 | |
396 | 396 | private function setup_vat_number() { |
397 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
397 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
398 | 398 | return $vat_number; |
399 | 399 | } |
400 | 400 | |
401 | 401 | private function setup_vat_rate() { |
402 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
402 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
403 | 403 | return $vat_rate; |
404 | 404 | } |
405 | 405 | |
406 | 406 | private function setup_adddress_confirmed() { |
407 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
407 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
408 | 408 | return $adddress_confirmed; |
409 | 409 | } |
410 | 410 | |
411 | 411 | private function setup_phone() { |
412 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
412 | + $phone = $this->get_meta('_wpinv_phone'); |
|
413 | 413 | return $phone; |
414 | 414 | } |
415 | 415 | |
416 | 416 | private function setup_address() { |
417 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
417 | + $address = $this->get_meta('_wpinv_address', true); |
|
418 | 418 | return $address; |
419 | 419 | } |
420 | 420 | |
421 | 421 | private function setup_city() { |
422 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
422 | + $city = $this->get_meta('_wpinv_city', true); |
|
423 | 423 | return $city; |
424 | 424 | } |
425 | 425 | |
426 | 426 | private function setup_country() { |
427 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
427 | + $country = $this->get_meta('_wpinv_country', true); |
|
428 | 428 | return $country; |
429 | 429 | } |
430 | 430 | |
431 | 431 | private function setup_state() { |
432 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
432 | + $state = $this->get_meta('_wpinv_state', true); |
|
433 | 433 | return $state; |
434 | 434 | } |
435 | 435 | |
436 | 436 | private function setup_zip() { |
437 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
437 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
438 | 438 | return $zip; |
439 | 439 | } |
440 | 440 | |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | 'user_id' => $this->user_id, |
444 | 444 | 'first_name' => $this->first_name, |
445 | 445 | 'last_name' => $this->last_name, |
446 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
446 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
447 | 447 | 'phone' => $this->phone, |
448 | 448 | 'address' => $this->address, |
449 | 449 | 'city' => $this->city, |
@@ -458,12 +458,12 @@ discard block |
||
458 | 458 | ); |
459 | 459 | |
460 | 460 | $user_info = array(); |
461 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
462 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
461 | + if (isset($this->payment_meta['user_info'])) { |
|
462 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
463 | 463 | |
464 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
464 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
465 | 465 | $this->user_id = $post->post_author; |
466 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
466 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
467 | 467 | |
468 | 468 | $user_info['user_id'] = $this->user_id; |
469 | 469 | $user_info['email'] = $this->email; |
@@ -472,13 +472,13 @@ discard block |
||
472 | 472 | } |
473 | 473 | } |
474 | 474 | |
475 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
475 | + $user_info = wp_parse_args($user_info, $defaults); |
|
476 | 476 | |
477 | 477 | // Get the user, but only if it's been created |
478 | - $user = get_userdata( $this->user_id ); |
|
478 | + $user = get_userdata($this->user_id); |
|
479 | 479 | |
480 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
481 | - if ( empty( $user_info ) ) { |
|
480 | + if (!empty($user) && $user->ID > 0) { |
|
481 | + if (empty($user_info)) { |
|
482 | 482 | $user_info = array( |
483 | 483 | 'user_id' => $user->ID, |
484 | 484 | 'first_name' => $user->first_name, |
@@ -487,23 +487,23 @@ discard block |
||
487 | 487 | 'discount' => '', |
488 | 488 | ); |
489 | 489 | } else { |
490 | - foreach ( $user_info as $key => $value ) { |
|
491 | - if ( ! empty( $value ) ) { |
|
490 | + foreach ($user_info as $key => $value) { |
|
491 | + if (!empty($value)) { |
|
492 | 492 | continue; |
493 | 493 | } |
494 | 494 | |
495 | - switch( $key ) { |
|
495 | + switch ($key) { |
|
496 | 496 | case 'user_id': |
497 | - $user_info[ $key ] = $user->ID; |
|
497 | + $user_info[$key] = $user->ID; |
|
498 | 498 | break; |
499 | 499 | case 'first_name': |
500 | - $user_info[ $key ] = $user->first_name; |
|
500 | + $user_info[$key] = $user->first_name; |
|
501 | 501 | break; |
502 | 502 | case 'last_name': |
503 | - $user_info[ $key ] = $user->last_name; |
|
503 | + $user_info[$key] = $user->last_name; |
|
504 | 504 | break; |
505 | 505 | case 'email': |
506 | - $user_info[ $key ] = $user->user_email; |
|
506 | + $user_info[$key] = $user->user_email; |
|
507 | 507 | break; |
508 | 508 | } |
509 | 509 | } |
@@ -514,16 +514,16 @@ discard block |
||
514 | 514 | } |
515 | 515 | |
516 | 516 | private function setup_invoice_key() { |
517 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
517 | + $key = $this->get_meta('_wpinv_key', true); |
|
518 | 518 | |
519 | 519 | return $key; |
520 | 520 | } |
521 | 521 | |
522 | 522 | private function setup_invoice_number() { |
523 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
523 | + $number = $this->get_meta('_wpinv_number', true); |
|
524 | 524 | |
525 | - if ( !$number ) { |
|
526 | - $number = wpinv_format_invoice_number( $this->ID ); |
|
525 | + if (!$number) { |
|
526 | + $number = wpinv_format_invoice_number($this->ID); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | return $number; |
@@ -534,18 +534,18 @@ discard block |
||
534 | 534 | |
535 | 535 | if ($number = $this->get_number()) { |
536 | 536 | $invoice_title = $number; |
537 | - } else if ( ! empty( $this->ID ) ) { |
|
538 | - $invoice_title = wpinv_format_invoice_number( $this->ID ); |
|
537 | + } else if (!empty($this->ID)) { |
|
538 | + $invoice_title = wpinv_format_invoice_number($this->ID); |
|
539 | 539 | } else { |
540 | - $invoice_title = wpinv_format_invoice_number( 0 ); |
|
540 | + $invoice_title = wpinv_format_invoice_number(0); |
|
541 | 541 | } |
542 | 542 | |
543 | - if ( empty( $this->key ) ) { |
|
543 | + if (empty($this->key)) { |
|
544 | 544 | $this->key = self::generate_key(); |
545 | 545 | $this->pending['key'] = $this->key; |
546 | 546 | } |
547 | 547 | |
548 | - if ( empty( $this->ip ) ) { |
|
548 | + if (empty($this->ip)) { |
|
549 | 549 | $this->ip = wpinv_get_ip(); |
550 | 550 | $this->pending['ip'] = $this->ip; |
551 | 551 | } |
@@ -577,75 +577,75 @@ discard block |
||
577 | 577 | 'fees' => $this->fees, |
578 | 578 | ); |
579 | 579 | |
580 | - $post_name = sanitize_title( $invoice_title ); |
|
580 | + $post_name = sanitize_title($invoice_title); |
|
581 | 581 | |
582 | 582 | $post_data = array( |
583 | 583 | 'post_title' => $invoice_title, |
584 | 584 | 'post_status' => $this->status, |
585 | 585 | 'post_author' => $this->user_id, |
586 | 586 | 'post_type' => 'wpi_invoice', |
587 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
588 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
587 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
588 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
589 | 589 | 'post_parent' => $this->parent_invoice, |
590 | 590 | ); |
591 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
591 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
592 | 592 | |
593 | 593 | // Create a blank invoice |
594 | - if ( !empty( $this->ID ) ) { |
|
594 | + if (!empty($this->ID)) { |
|
595 | 595 | $args['ID'] = $this->ID; |
596 | 596 | $args['post_name'] = $post_name; |
597 | 597 | |
598 | - $invoice_id = wp_update_post( $args ); |
|
598 | + $invoice_id = wp_update_post($args); |
|
599 | 599 | } else { |
600 | - $invoice_id = wp_insert_post( $args ); |
|
600 | + $invoice_id = wp_insert_post($args); |
|
601 | 601 | |
602 | - $post_title = wpinv_format_invoice_number( $invoice_id ); |
|
602 | + $post_title = wpinv_format_invoice_number($invoice_id); |
|
603 | 603 | global $wpdb; |
604 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) ); |
|
605 | - clean_post_cache( $invoice_id ); |
|
604 | + $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id)); |
|
605 | + clean_post_cache($invoice_id); |
|
606 | 606 | } |
607 | 607 | |
608 | - if ( !empty( $invoice_id ) ) { |
|
608 | + if (!empty($invoice_id)) { |
|
609 | 609 | $this->ID = $invoice_id; |
610 | 610 | $this->_ID = $invoice_id; |
611 | 611 | |
612 | 612 | ///$this->pending['user_id'] = $this->user_id; |
613 | - if ( isset( $this->pending['number'] ) ) { |
|
613 | + if (isset($this->pending['number'])) { |
|
614 | 614 | $this->pending['number'] = $post_name; |
615 | 615 | } |
616 | 616 | |
617 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
618 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
619 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
620 | - foreach( $this->fees as $fee ) { |
|
621 | - $this->increase_fees( $fee['amount'] ); |
|
617 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
618 | + if (!empty($this->payment_meta['fees'])) { |
|
619 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
620 | + foreach ($this->fees as $fee) { |
|
621 | + $this->increase_fees($fee['amount']); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
625 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
625 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
626 | 626 | $this->new = true; |
627 | 627 | } |
628 | 628 | |
629 | 629 | return $this->ID; |
630 | 630 | } |
631 | 631 | |
632 | - public function save( $setup = false ) { |
|
632 | + public function save($setup = false) { |
|
633 | 633 | global $wpi_session; |
634 | 634 | |
635 | 635 | $saved = false; |
636 | - if ( empty( $this->items ) ) { |
|
636 | + if (empty($this->items)) { |
|
637 | 637 | return $saved; // Don't save empty invoice. |
638 | 638 | } |
639 | 639 | |
640 | - if ( empty( $this->key ) ) { |
|
640 | + if (empty($this->key)) { |
|
641 | 641 | $this->key = self::generate_key(); |
642 | 642 | $this->pending['key'] = $this->key; |
643 | 643 | } |
644 | 644 | |
645 | - if ( empty( $this->ID ) ) { |
|
645 | + if (empty($this->ID)) { |
|
646 | 646 | $invoice_id = $this->insert_invoice(); |
647 | 647 | |
648 | - if ( false === $invoice_id ) { |
|
648 | + if (false === $invoice_id) { |
|
649 | 649 | $saved = false; |
650 | 650 | } else { |
651 | 651 | $this->ID = $invoice_id; |
@@ -653,27 +653,27 @@ discard block |
||
653 | 653 | } |
654 | 654 | |
655 | 655 | // If we have something pending, let's save it |
656 | - if ( !empty( $this->pending ) ) { |
|
656 | + if (!empty($this->pending)) { |
|
657 | 657 | $total_increase = 0; |
658 | 658 | $total_decrease = 0; |
659 | 659 | |
660 | - foreach ( $this->pending as $key => $value ) { |
|
661 | - switch( $key ) { |
|
660 | + foreach ($this->pending as $key => $value) { |
|
661 | + switch ($key) { |
|
662 | 662 | case 'items': |
663 | 663 | // Update totals for pending items |
664 | - foreach ( $this->pending[ $key ] as $item ) { |
|
665 | - switch( $item['action'] ) { |
|
664 | + foreach ($this->pending[$key] as $item) { |
|
665 | + switch ($item['action']) { |
|
666 | 666 | case 'add': |
667 | 667 | $price = $item['price']; |
668 | 668 | $taxes = $item['tax']; |
669 | 669 | |
670 | - if ( 'publish' === $this->status ) { |
|
670 | + if ('publish' === $this->status) { |
|
671 | 671 | $total_increase += $price; |
672 | 672 | } |
673 | 673 | break; |
674 | 674 | |
675 | 675 | case 'remove': |
676 | - if ( 'publish' === $this->status ) { |
|
676 | + if ('publish' === $this->status) { |
|
677 | 677 | $total_decrease += $item['price']; |
678 | 678 | } |
679 | 679 | break; |
@@ -681,16 +681,16 @@ discard block |
||
681 | 681 | } |
682 | 682 | break; |
683 | 683 | case 'fees': |
684 | - if ( 'publish' !== $this->status ) { |
|
684 | + if ('publish' !== $this->status) { |
|
685 | 685 | break; |
686 | 686 | } |
687 | 687 | |
688 | - if ( empty( $this->pending[ $key ] ) ) { |
|
688 | + if (empty($this->pending[$key])) { |
|
689 | 689 | break; |
690 | 690 | } |
691 | 691 | |
692 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
693 | - switch( $fee['action'] ) { |
|
692 | + foreach ($this->pending[$key] as $fee) { |
|
693 | + switch ($fee['action']) { |
|
694 | 694 | case 'add': |
695 | 695 | $total_increase += $fee['amount']; |
696 | 696 | break; |
@@ -702,86 +702,86 @@ discard block |
||
702 | 702 | } |
703 | 703 | break; |
704 | 704 | case 'status': |
705 | - $this->update_status( $this->status ); |
|
705 | + $this->update_status($this->status); |
|
706 | 706 | break; |
707 | 707 | case 'gateway': |
708 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
708 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
709 | 709 | break; |
710 | 710 | case 'mode': |
711 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
711 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
712 | 712 | break; |
713 | 713 | case 'transaction_id': |
714 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
714 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
715 | 715 | break; |
716 | 716 | case 'ip': |
717 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
717 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
718 | 718 | break; |
719 | 719 | ///case 'user_id': |
720 | 720 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
721 | 721 | ///$this->user_info['user_id'] = $this->user_id; |
722 | 722 | ///break; |
723 | 723 | case 'first_name': |
724 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
724 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
725 | 725 | $this->user_info['first_name'] = $this->first_name; |
726 | 726 | break; |
727 | 727 | case 'last_name': |
728 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
728 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
729 | 729 | $this->user_info['last_name'] = $this->last_name; |
730 | 730 | break; |
731 | 731 | case 'phone': |
732 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
732 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
733 | 733 | $this->user_info['phone'] = $this->phone; |
734 | 734 | break; |
735 | 735 | case 'address': |
736 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
736 | + $this->update_meta('_wpinv_address', $this->address); |
|
737 | 737 | $this->user_info['address'] = $this->address; |
738 | 738 | break; |
739 | 739 | case 'city': |
740 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
740 | + $this->update_meta('_wpinv_city', $this->city); |
|
741 | 741 | $this->user_info['city'] = $this->city; |
742 | 742 | break; |
743 | 743 | case 'country': |
744 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
744 | + $this->update_meta('_wpinv_country', $this->country); |
|
745 | 745 | $this->user_info['country'] = $this->country; |
746 | 746 | break; |
747 | 747 | case 'state': |
748 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
748 | + $this->update_meta('_wpinv_state', $this->state); |
|
749 | 749 | $this->user_info['state'] = $this->state; |
750 | 750 | break; |
751 | 751 | case 'zip': |
752 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
752 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
753 | 753 | $this->user_info['zip'] = $this->zip; |
754 | 754 | break; |
755 | 755 | case 'company': |
756 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
756 | + $this->update_meta('_wpinv_company', $this->company); |
|
757 | 757 | $this->user_info['company'] = $this->company; |
758 | 758 | break; |
759 | 759 | case 'vat_number': |
760 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
760 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
761 | 761 | $this->user_info['vat_number'] = $this->vat_number; |
762 | 762 | |
763 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
764 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
765 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
766 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
763 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
764 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
765 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
766 | + $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed); |
|
767 | 767 | $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
768 | 768 | } |
769 | 769 | |
770 | 770 | break; |
771 | 771 | case 'vat_rate': |
772 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
772 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
773 | 773 | $this->user_info['vat_rate'] = $this->vat_rate; |
774 | 774 | break; |
775 | 775 | case 'adddress_confirmed': |
776 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
776 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
777 | 777 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
778 | 778 | break; |
779 | 779 | |
780 | 780 | case 'key': |
781 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
781 | + $this->update_meta('_wpinv_key', $this->key); |
|
782 | 782 | break; |
783 | 783 | case 'number': |
784 | - $this->update_meta( '_wpinv_number', $this->number ); |
|
784 | + $this->update_meta('_wpinv_number', $this->number); |
|
785 | 785 | break; |
786 | 786 | case 'date': |
787 | 787 | $args = array( |
@@ -790,34 +790,34 @@ discard block |
||
790 | 790 | 'edit_date' => true, |
791 | 791 | ); |
792 | 792 | |
793 | - wp_update_post( $args ); |
|
793 | + wp_update_post($args); |
|
794 | 794 | break; |
795 | 795 | case 'due_date': |
796 | - if ( empty( $this->due_date ) ) { |
|
796 | + if (empty($this->due_date)) { |
|
797 | 797 | $this->due_date = 'none'; |
798 | 798 | } |
799 | 799 | |
800 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
800 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
801 | 801 | break; |
802 | 802 | case 'completed_date': |
803 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
803 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
804 | 804 | break; |
805 | 805 | case 'discounts': |
806 | - if ( ! is_array( $this->discounts ) ) { |
|
807 | - $this->discounts = explode( ',', $this->discounts ); |
|
806 | + if (!is_array($this->discounts)) { |
|
807 | + $this->discounts = explode(',', $this->discounts); |
|
808 | 808 | } |
809 | 809 | |
810 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
810 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
811 | 811 | break; |
812 | 812 | |
813 | 813 | //case 'tax': |
814 | 814 | //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
815 | 815 | //break; |
816 | 816 | case 'discount': |
817 | - $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) ); |
|
817 | + $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true)); |
|
818 | 818 | break; |
819 | 819 | case 'discount_code': |
820 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
820 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
821 | 821 | break; |
822 | 822 | //case 'fees': |
823 | 823 | //$this->update_meta( '_wpinv_fees', $this->fees ); |
@@ -827,19 +827,19 @@ discard block |
||
827 | 827 | 'ID' => $this->ID, |
828 | 828 | 'post_parent' => $this->parent_invoice, |
829 | 829 | ); |
830 | - wp_update_post( $args ); |
|
830 | + wp_update_post($args); |
|
831 | 831 | break; |
832 | 832 | default: |
833 | - do_action( 'wpinv_save', $this, $key ); |
|
833 | + do_action('wpinv_save', $this, $key); |
|
834 | 834 | break; |
835 | 835 | } |
836 | 836 | } |
837 | 837 | |
838 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
839 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
840 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
838 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
839 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
840 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
841 | 841 | |
842 | - $this->items = array_values( $this->items ); |
|
842 | + $this->items = array_values($this->items); |
|
843 | 843 | |
844 | 844 | $new_meta = array( |
845 | 845 | 'items' => $this->items, |
@@ -850,12 +850,12 @@ discard block |
||
850 | 850 | ); |
851 | 851 | |
852 | 852 | $meta = $this->get_meta(); |
853 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
853 | + $merged_meta = array_merge($meta, $new_meta); |
|
854 | 854 | |
855 | 855 | // Only save the payment meta if it's changed |
856 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
857 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
858 | - if ( false !== $updated ) { |
|
856 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
857 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
858 | + if (false !== $updated) { |
|
859 | 859 | $saved = true; |
860 | 860 | } |
861 | 861 | } |
@@ -863,15 +863,15 @@ discard block |
||
863 | 863 | $this->pending = array(); |
864 | 864 | $saved = true; |
865 | 865 | } else { |
866 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
867 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
868 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
866 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
867 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
868 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
869 | 869 | } |
870 | 870 | |
871 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
871 | + do_action('wpinv_invoice_save', $this, $saved); |
|
872 | 872 | |
873 | - if ( true === $saved || $setup ) { |
|
874 | - $this->setup_invoice( $this->ID ); |
|
873 | + if (true === $saved || $setup) { |
|
874 | + $this->setup_invoice($this->ID); |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | $this->refresh_item_ids(); |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | return $saved; |
880 | 880 | } |
881 | 881 | |
882 | - public function add_fee( $args, $global = true ) { |
|
882 | + public function add_fee($args, $global = true) { |
|
883 | 883 | $default_args = array( |
884 | 884 | 'label' => '', |
885 | 885 | 'amount' => 0, |
@@ -889,75 +889,75 @@ discard block |
||
889 | 889 | 'item_id' => 0, |
890 | 890 | ); |
891 | 891 | |
892 | - $fee = wp_parse_args( $args, $default_args ); |
|
892 | + $fee = wp_parse_args($args, $default_args); |
|
893 | 893 | |
894 | - if ( !empty( $fee['label'] ) ) { |
|
894 | + if (!empty($fee['label'])) { |
|
895 | 895 | return false; |
896 | 896 | } |
897 | 897 | |
898 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
898 | + $fee['id'] = sanitize_title($fee['label']); |
|
899 | 899 | |
900 | - $this->fees[] = $fee; |
|
900 | + $this->fees[] = $fee; |
|
901 | 901 | |
902 | 902 | $added_fee = $fee; |
903 | 903 | $added_fee['action'] = 'add'; |
904 | 904 | $this->pending['fees'][] = $added_fee; |
905 | - reset( $this->fees ); |
|
905 | + reset($this->fees); |
|
906 | 906 | |
907 | - $this->increase_fees( $fee['amount'] ); |
|
907 | + $this->increase_fees($fee['amount']); |
|
908 | 908 | return true; |
909 | 909 | } |
910 | 910 | |
911 | - public function remove_fee( $key ) { |
|
911 | + public function remove_fee($key) { |
|
912 | 912 | $removed = false; |
913 | 913 | |
914 | - if ( is_numeric( $key ) ) { |
|
915 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
914 | + if (is_numeric($key)) { |
|
915 | + $removed = $this->remove_fee_by('index', $key); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | return $removed; |
919 | 919 | } |
920 | 920 | |
921 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
922 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
921 | + public function remove_fee_by($key, $value, $global = false) { |
|
922 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
923 | 923 | 'index', 'label', 'amount', 'type', |
924 | - ) ); |
|
924 | + )); |
|
925 | 925 | |
926 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
926 | + if (!in_array($key, $allowed_fee_keys)) { |
|
927 | 927 | return false; |
928 | 928 | } |
929 | 929 | |
930 | 930 | $removed = false; |
931 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
932 | - $removed_fee = $this->fees[ $value ]; |
|
931 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
932 | + $removed_fee = $this->fees[$value]; |
|
933 | 933 | $removed_fee['action'] = 'remove'; |
934 | 934 | $this->pending['fees'][] = $removed_fee; |
935 | 935 | |
936 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
936 | + $this->decrease_fees($removed_fee['amount']); |
|
937 | 937 | |
938 | - unset( $this->fees[ $value ] ); |
|
938 | + unset($this->fees[$value]); |
|
939 | 939 | $removed = true; |
940 | - } else if ( 'index' !== $key ) { |
|
941 | - foreach ( $this->fees as $index => $fee ) { |
|
942 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
940 | + } else if ('index' !== $key) { |
|
941 | + foreach ($this->fees as $index => $fee) { |
|
942 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
943 | 943 | $removed_fee = $fee; |
944 | 944 | $removed_fee['action'] = 'remove'; |
945 | 945 | $this->pending['fees'][] = $removed_fee; |
946 | 946 | |
947 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
947 | + $this->decrease_fees($removed_fee['amount']); |
|
948 | 948 | |
949 | - unset( $this->fees[ $index ] ); |
|
949 | + unset($this->fees[$index]); |
|
950 | 950 | $removed = true; |
951 | 951 | |
952 | - if ( false === $global ) { |
|
952 | + if (false === $global) { |
|
953 | 953 | break; |
954 | 954 | } |
955 | 955 | } |
956 | 956 | } |
957 | 957 | } |
958 | 958 | |
959 | - if ( true === $removed ) { |
|
960 | - $this->fees = array_values( $this->fees ); |
|
959 | + if (true === $removed) { |
|
960 | + $this->fees = array_values($this->fees); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | return $removed; |
@@ -965,35 +965,35 @@ discard block |
||
965 | 965 | |
966 | 966 | |
967 | 967 | |
968 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
968 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
969 | 969 | // Bail if no note specified |
970 | - if( !$note ) { |
|
970 | + if (!$note) { |
|
971 | 971 | return false; |
972 | 972 | } |
973 | 973 | |
974 | - if ( empty( $this->ID ) ) |
|
974 | + if (empty($this->ID)) |
|
975 | 975 | return false; |
976 | 976 | |
977 | - if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) { |
|
978 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
977 | + if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) { |
|
978 | + $user = get_user_by('id', get_current_user_id()); |
|
979 | 979 | $comment_author = $user->display_name; |
980 | 980 | $comment_author_email = $user->user_email; |
981 | 981 | } else { |
982 | - $comment_author = __( 'System', 'invoicing' ); |
|
983 | - $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@'; |
|
984 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
985 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
982 | + $comment_author = __('System', 'invoicing'); |
|
983 | + $comment_author_email = strtolower(__('System', 'invoicing')) . '@'; |
|
984 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
985 | + $comment_author_email = sanitize_email($comment_author_email); |
|
986 | 986 | } |
987 | 987 | |
988 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
988 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
989 | 989 | |
990 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
990 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
991 | 991 | 'comment_post_ID' => $this->ID, |
992 | 992 | 'comment_content' => $note, |
993 | 993 | 'comment_agent' => 'GeoDirectory', |
994 | 994 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
995 | - 'comment_date' => current_time( 'mysql' ), |
|
996 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
995 | + 'comment_date' => current_time('mysql'), |
|
996 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
997 | 997 | 'comment_approved' => 1, |
998 | 998 | 'comment_parent' => 0, |
999 | 999 | 'comment_author' => $comment_author, |
@@ -1001,53 +1001,53 @@ discard block |
||
1001 | 1001 | 'comment_author_url' => '', |
1002 | 1002 | 'comment_author_email' => $comment_author_email, |
1003 | 1003 | 'comment_type' => 'wpinv_note' |
1004 | - ) ) ); |
|
1004 | + ))); |
|
1005 | 1005 | |
1006 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
1006 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
1007 | 1007 | |
1008 | - if ( $customer_type ) { |
|
1009 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
1008 | + if ($customer_type) { |
|
1009 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
1010 | 1010 | |
1011 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
1011 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | return $note_id; |
1015 | 1015 | } |
1016 | 1016 | |
1017 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1018 | - $amount = (float) $amount; |
|
1017 | + private function increase_subtotal($amount = 0.00) { |
|
1018 | + $amount = (float)$amount; |
|
1019 | 1019 | $this->subtotal += $amount; |
1020 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1020 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
1021 | 1021 | |
1022 | 1022 | $this->recalculate_total(); |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1026 | - $amount = (float) $amount; |
|
1025 | + private function decrease_subtotal($amount = 0.00) { |
|
1026 | + $amount = (float)$amount; |
|
1027 | 1027 | $this->subtotal -= $amount; |
1028 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1028 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
1029 | 1029 | |
1030 | - if ( $this->subtotal < 0 ) { |
|
1030 | + if ($this->subtotal < 0) { |
|
1031 | 1031 | $this->subtotal = 0; |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | $this->recalculate_total(); |
1035 | 1035 | } |
1036 | 1036 | |
1037 | - private function increase_fees( $amount = 0.00 ) { |
|
1037 | + private function increase_fees($amount = 0.00) { |
|
1038 | 1038 | $amount = (float)$amount; |
1039 | 1039 | $this->fees_total += $amount; |
1040 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
1040 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
1041 | 1041 | |
1042 | 1042 | $this->recalculate_total(); |
1043 | 1043 | } |
1044 | 1044 | |
1045 | - private function decrease_fees( $amount = 0.00 ) { |
|
1046 | - $amount = (float) $amount; |
|
1045 | + private function decrease_fees($amount = 0.00) { |
|
1046 | + $amount = (float)$amount; |
|
1047 | 1047 | $this->fees_total -= $amount; |
1048 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
1048 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
1049 | 1049 | |
1050 | - if ( $this->fees_total < 0 ) { |
|
1050 | + if ($this->fees_total < 0) { |
|
1051 | 1051 | $this->fees_total = 0; |
1052 | 1052 | } |
1053 | 1053 | |
@@ -1058,54 +1058,54 @@ discard block |
||
1058 | 1058 | global $wpi_nosave; |
1059 | 1059 | |
1060 | 1060 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
1061 | - $this->total = wpinv_format_amount( $this->total, NULL, true ); |
|
1061 | + $this->total = wpinv_format_amount($this->total, NULL, true); |
|
1062 | 1062 | |
1063 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
1063 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | - public function increase_tax( $amount = 0.00 ) { |
|
1067 | - $amount = (float) $amount; |
|
1066 | + public function increase_tax($amount = 0.00) { |
|
1067 | + $amount = (float)$amount; |
|
1068 | 1068 | $this->tax += $amount; |
1069 | 1069 | |
1070 | 1070 | $this->recalculate_total(); |
1071 | 1071 | } |
1072 | 1072 | |
1073 | - public function decrease_tax( $amount = 0.00 ) { |
|
1074 | - $amount = (float) $amount; |
|
1073 | + public function decrease_tax($amount = 0.00) { |
|
1074 | + $amount = (float)$amount; |
|
1075 | 1075 | $this->tax -= $amount; |
1076 | 1076 | |
1077 | - if ( $this->tax < 0 ) { |
|
1077 | + if ($this->tax < 0) { |
|
1078 | 1078 | $this->tax = 0; |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | $this->recalculate_total(); |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
1085 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
1084 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
1085 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
1086 | 1086 | |
1087 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1087 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) { |
|
1088 | 1088 | return false; // Don't permit status changes that aren't changes |
1089 | 1089 | } |
1090 | 1090 | |
1091 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
1091 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
1092 | 1092 | $updated = false; |
1093 | 1093 | |
1094 | - if ( $do_change ) { |
|
1095 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
1094 | + if ($do_change) { |
|
1095 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
1096 | 1096 | |
1097 | 1097 | $update_post_data = array(); |
1098 | 1098 | $update_post_data['ID'] = $this->ID; |
1099 | 1099 | $update_post_data['post_status'] = $new_status; |
1100 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
1101 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
1100 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
1101 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
1102 | 1102 | |
1103 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
1103 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
1104 | 1104 | |
1105 | - $updated = wp_update_post( $update_post_data ); |
|
1105 | + $updated = wp_update_post($update_post_data); |
|
1106 | 1106 | |
1107 | 1107 | // Process any specific status functions |
1108 | - switch( $new_status ) { |
|
1108 | + switch ($new_status) { |
|
1109 | 1109 | case 'wpi-refunded': |
1110 | 1110 | $this->process_refund(); |
1111 | 1111 | break; |
@@ -1118,9 +1118,9 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | // Status was changed. |
1121 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
1122 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
1123 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
1121 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
1122 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
1123 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | return $updated; |
@@ -1134,72 +1134,72 @@ discard block |
||
1134 | 1134 | $this->save(); |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1138 | - if ( empty( $meta_key ) ) { |
|
1137 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1138 | + if (empty($meta_key)) { |
|
1139 | 1139 | return false; |
1140 | 1140 | } |
1141 | 1141 | |
1142 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1142 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1143 | 1143 | $current_meta = $this->get_meta(); |
1144 | - $current_meta[ $meta_key ] = $meta_value; |
|
1144 | + $current_meta[$meta_key] = $meta_value; |
|
1145 | 1145 | |
1146 | 1146 | $meta_key = '_wpinv_payment_meta'; |
1147 | 1147 | $meta_value = $current_meta; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1150 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1151 | 1151 | |
1152 | - if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
|
1152 | + if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) { |
|
1153 | 1153 | $args = array( |
1154 | 1154 | 'ID' => $this->ID, |
1155 | 1155 | 'post_date' => $meta_value, |
1156 | 1156 | 'edit_date' => true, |
1157 | - 'post_date_gmt' => get_gmt_from_date( $meta_value ), |
|
1157 | + 'post_date_gmt' => get_gmt_from_date($meta_value), |
|
1158 | 1158 | 'post_modified' => $meta_value, |
1159 | - 'post_modified_gmt' => get_gmt_from_date( $meta_value ) |
|
1159 | + 'post_modified_gmt' => get_gmt_from_date($meta_value) |
|
1160 | 1160 | ); |
1161 | - wp_update_post( $args ); |
|
1161 | + wp_update_post($args); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1164 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | private function process_refund() { |
1168 | 1168 | $process_refund = true; |
1169 | 1169 | |
1170 | 1170 | // If the payment was not in publish, don't decrement stats as they were never incremented |
1171 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
1171 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
1172 | 1172 | $process_refund = false; |
1173 | 1173 | } |
1174 | 1174 | |
1175 | 1175 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1176 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
1176 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
1177 | 1177 | |
1178 | - if ( false === $process_refund ) { |
|
1178 | + if (false === $process_refund) { |
|
1179 | 1179 | return; |
1180 | 1180 | } |
1181 | 1181 | |
1182 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
1182 | + do_action('wpinv_pre_refund_invoice', $this); |
|
1183 | 1183 | |
1184 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
1185 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
1186 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1184 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
1185 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
1186 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
1187 | 1187 | |
1188 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
1188 | + do_action('wpinv_post_refund_invoice', $this); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | private function process_failure() { |
1192 | 1192 | $discounts = $this->discounts; |
1193 | - if ( empty( $discounts ) ) { |
|
1193 | + if (empty($discounts)) { |
|
1194 | 1194 | return; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( ! is_array( $discounts ) ) { |
|
1198 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
1197 | + if (!is_array($discounts)) { |
|
1198 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | - foreach ( $discounts as $discount ) { |
|
1202 | - wpinv_decrease_discount_usage( $discount ); |
|
1201 | + foreach ($discounts as $discount) { |
|
1202 | + wpinv_decrease_discount_usage($discount); |
|
1203 | 1203 | } |
1204 | 1204 | } |
1205 | 1205 | |
@@ -1207,92 +1207,92 @@ discard block |
||
1207 | 1207 | $process_pending = true; |
1208 | 1208 | |
1209 | 1209 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1210 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) { |
|
1210 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) { |
|
1211 | 1211 | $process_pending = false; |
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1215 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
1215 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
1216 | 1216 | |
1217 | - if ( false === $process_pending ) { |
|
1217 | + if (false === $process_pending) { |
|
1218 | 1218 | return; |
1219 | 1219 | } |
1220 | 1220 | |
1221 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
1222 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
1223 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1221 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
1222 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
1223 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
1224 | 1224 | |
1225 | 1225 | $this->completed_date = ''; |
1226 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
1226 | + $this->update_meta('_wpinv_completed_date', ''); |
|
1227 | 1227 | } |
1228 | 1228 | |
1229 | 1229 | // get data |
1230 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1231 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1230 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1231 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1232 | 1232 | |
1233 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1233 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1234 | 1234 | |
1235 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1235 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1236 | 1236 | |
1237 | - if ( empty( $meta['key'] ) ) { |
|
1237 | + if (empty($meta['key'])) { |
|
1238 | 1238 | $meta['key'] = $this->setup_invoice_key(); |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - if ( empty( $meta['date'] ) ) { |
|
1242 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1241 | + if (empty($meta['date'])) { |
|
1242 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1243 | 1243 | } |
1244 | 1244 | } |
1245 | 1245 | |
1246 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1246 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1247 | 1247 | |
1248 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1248 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | public function get_description() { |
1252 | - $post = get_post( $this->ID ); |
|
1252 | + $post = get_post($this->ID); |
|
1253 | 1253 | |
1254 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1255 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1254 | + $description = !empty($post) ? $post->post_content : ''; |
|
1255 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | - public function get_status( $nicename = false ) { |
|
1259 | - if ( !$nicename ) { |
|
1258 | + public function get_status($nicename = false) { |
|
1259 | + if (!$nicename) { |
|
1260 | 1260 | $status = $this->status; |
1261 | 1261 | } else { |
1262 | 1262 | $status = $this->status_nicename; |
1263 | 1263 | } |
1264 | 1264 | |
1265 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1265 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | public function get_cart_details() { |
1269 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1269 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1270 | 1270 | } |
1271 | 1271 | |
1272 | - public function get_subtotal( $currency = false ) { |
|
1273 | - $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency ); |
|
1272 | + public function get_subtotal($currency = false) { |
|
1273 | + $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency); |
|
1274 | 1274 | |
1275 | - if ( $currency ) { |
|
1276 | - $subtotal = wpinv_price( $subtotal, $this->get_currency() ); |
|
1275 | + if ($currency) { |
|
1276 | + $subtotal = wpinv_price($subtotal, $this->get_currency()); |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1279 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1280 | 1280 | } |
1281 | 1281 | |
1282 | - public function get_total( $currency = false ) { |
|
1283 | - if ( $this->is_free_trial() ) { |
|
1284 | - $total = wpinv_format_amount( 0, NULL, !$currency ); |
|
1282 | + public function get_total($currency = false) { |
|
1283 | + if ($this->is_free_trial()) { |
|
1284 | + $total = wpinv_format_amount(0, NULL, !$currency); |
|
1285 | 1285 | } else { |
1286 | - $total = wpinv_format_amount( $this->total, NULL, !$currency ); |
|
1286 | + $total = wpinv_format_amount($this->total, NULL, !$currency); |
|
1287 | 1287 | } |
1288 | - if ( $currency ) { |
|
1289 | - $total = wpinv_price( $total, $this->get_currency() ); |
|
1288 | + if ($currency) { |
|
1289 | + $total = wpinv_price($total, $this->get_currency()); |
|
1290 | 1290 | } |
1291 | 1291 | |
1292 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1292 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1295 | + public function get_recurring_details($field = '', $currency = false) { |
|
1296 | 1296 | $data = array(); |
1297 | 1297 | $data['cart_details'] = $this->cart_details; |
1298 | 1298 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1300,45 +1300,45 @@ discard block |
||
1300 | 1300 | $data['tax'] = $this->get_tax(); |
1301 | 1301 | $data['total'] = $this->get_total(); |
1302 | 1302 | |
1303 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
1303 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
1304 | 1304 | $is_free_trial = $this->is_free_trial(); |
1305 | - $discounts = $this->get_discounts( true ); |
|
1305 | + $discounts = $this->get_discounts(true); |
|
1306 | 1306 | |
1307 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
1307 | + if ($is_free_trial || !empty($discounts)) { |
|
1308 | 1308 | $first_use_only = false; |
1309 | 1309 | |
1310 | - if ( !empty( $discounts ) ) { |
|
1311 | - foreach ( $discounts as $key => $code ) { |
|
1312 | - if ( wpinv_discount_is_recurring( $code, true ) ) { |
|
1310 | + if (!empty($discounts)) { |
|
1311 | + foreach ($discounts as $key => $code) { |
|
1312 | + if (wpinv_discount_is_recurring($code, true)) { |
|
1313 | 1313 | $first_use_only = true; |
1314 | 1314 | break; |
1315 | 1315 | } |
1316 | 1316 | } |
1317 | 1317 | } |
1318 | 1318 | |
1319 | - if ( !$first_use_only ) { |
|
1320 | - $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1321 | - $data['discount'] = wpinv_format_amount( $this->discount, NULL, true ); |
|
1322 | - $data['tax'] = wpinv_format_amount( $this->tax, NULL, true ); |
|
1323 | - $data['total'] = wpinv_format_amount( $this->total, NULL, true ); |
|
1319 | + if (!$first_use_only) { |
|
1320 | + $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true); |
|
1321 | + $data['discount'] = wpinv_format_amount($this->discount, NULL, true); |
|
1322 | + $data['tax'] = wpinv_format_amount($this->tax, NULL, true); |
|
1323 | + $data['total'] = wpinv_format_amount($this->total, NULL, true); |
|
1324 | 1324 | } else { |
1325 | 1325 | $cart_subtotal = 0; |
1326 | 1326 | $cart_discount = 0; |
1327 | 1327 | $cart_tax = 0; |
1328 | 1328 | |
1329 | - foreach ( $this->cart_details as $key => $item ) { |
|
1330 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1331 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1329 | + foreach ($this->cart_details as $key => $item) { |
|
1330 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1331 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1332 | 1332 | $item_discount = 0; |
1333 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
1333 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0; |
|
1334 | 1334 | |
1335 | - if ( wpinv_prices_include_tax() ) { |
|
1336 | - $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true ); |
|
1335 | + if (wpinv_prices_include_tax()) { |
|
1336 | + $item_subtotal -= wpinv_format_amount($item_tax, NULL, true); |
|
1337 | 1337 | } |
1338 | 1338 | |
1339 | 1339 | $item_total = $item_subtotal - $item_discount + $item_tax; |
1340 | 1340 | // Do not allow totals to go negative |
1341 | - if ( $item_total < 0 ) { |
|
1341 | + if ($item_total < 0) { |
|
1342 | 1342 | $item_total = 0; |
1343 | 1343 | } |
1344 | 1344 | |
@@ -1346,107 +1346,107 @@ discard block |
||
1346 | 1346 | $cart_discount += (float)($item_discount); |
1347 | 1347 | $cart_tax += (float)($item_tax); |
1348 | 1348 | |
1349 | - $data['cart_details'][$key]['discount'] = wpinv_format_amount( $item_discount, NULL, true ); |
|
1350 | - $data['cart_details'][$key]['tax'] = wpinv_format_amount( $item_tax, NULL, true ); |
|
1351 | - $data['cart_details'][$key]['price'] = wpinv_format_amount( $item_total, NULL, true ); |
|
1349 | + $data['cart_details'][$key]['discount'] = wpinv_format_amount($item_discount, NULL, true); |
|
1350 | + $data['cart_details'][$key]['tax'] = wpinv_format_amount($item_tax, NULL, true); |
|
1351 | + $data['cart_details'][$key]['price'] = wpinv_format_amount($item_total, NULL, true); |
|
1352 | 1352 | } |
1353 | 1353 | |
1354 | - $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
1355 | - $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true ); |
|
1356 | - $data['tax'] = wpinv_format_amount( $cart_tax, NULL, true ); |
|
1357 | - $data['total'] = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true ); |
|
1354 | + $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true); |
|
1355 | + $data['discount'] = wpinv_format_amount($cart_discount, NULL, true); |
|
1356 | + $data['tax'] = wpinv_format_amount($cart_tax, NULL, true); |
|
1357 | + $data['total'] = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true); |
|
1358 | 1358 | } |
1359 | 1359 | } |
1360 | 1360 | } |
1361 | 1361 | |
1362 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1362 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1363 | 1363 | |
1364 | - if ( isset( $data[$field] ) ) { |
|
1365 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1364 | + if (isset($data[$field])) { |
|
1365 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | 1368 | return $data; |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - public function get_final_tax( $currency = false ) { |
|
1372 | - $final_total = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
1373 | - if ( $currency ) { |
|
1374 | - $final_total = wpinv_price( $final_total, $this->get_currency() ); |
|
1371 | + public function get_final_tax($currency = false) { |
|
1372 | + $final_total = wpinv_format_amount($this->tax, NULL, !$currency); |
|
1373 | + if ($currency) { |
|
1374 | + $final_total = wpinv_price($final_total, $this->get_currency()); |
|
1375 | 1375 | } |
1376 | 1376 | |
1377 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1377 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1378 | 1378 | } |
1379 | 1379 | |
1380 | - public function get_discounts( $array = false ) { |
|
1380 | + public function get_discounts($array = false) { |
|
1381 | 1381 | $discounts = $this->discounts; |
1382 | - if ( $array && $discounts ) { |
|
1383 | - $discounts = explode( ',', $discounts ); |
|
1382 | + if ($array && $discounts) { |
|
1383 | + $discounts = explode(',', $discounts); |
|
1384 | 1384 | } |
1385 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1385 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1386 | 1386 | } |
1387 | 1387 | |
1388 | - public function get_discount( $currency = false, $dash = false ) { |
|
1389 | - if ( !empty( $this->discounts ) ) { |
|
1388 | + public function get_discount($currency = false, $dash = false) { |
|
1389 | + if (!empty($this->discounts)) { |
|
1390 | 1390 | global $ajax_cart_details; |
1391 | 1391 | $ajax_cart_details = $this->get_cart_details(); |
1392 | 1392 | |
1393 | - $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts ); |
|
1393 | + $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts); |
|
1394 | 1394 | } |
1395 | - $discount = wpinv_format_amount( $this->discount, NULL, !$currency ); |
|
1395 | + $discount = wpinv_format_amount($this->discount, NULL, !$currency); |
|
1396 | 1396 | $dash = $dash && $discount > 0 ? '–' : ''; |
1397 | 1397 | |
1398 | - if ( $currency ) { |
|
1399 | - $discount = wpinv_price( $discount, $this->get_currency() ); |
|
1398 | + if ($currency) { |
|
1399 | + $discount = wpinv_price($discount, $this->get_currency()); |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | - $discount = $dash . $discount; |
|
1402 | + $discount = $dash . $discount; |
|
1403 | 1403 | |
1404 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1404 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | public function get_discount_code() { |
1408 | 1408 | return $this->discount_code; |
1409 | 1409 | } |
1410 | 1410 | |
1411 | - public function get_tax( $currency = false ) { |
|
1412 | - $tax = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
1411 | + public function get_tax($currency = false) { |
|
1412 | + $tax = wpinv_format_amount($this->tax, NULL, !$currency); |
|
1413 | 1413 | |
1414 | - if ( $currency ) { |
|
1415 | - $tax = wpinv_price( $tax, $this->get_currency() ); |
|
1414 | + if ($currency) { |
|
1415 | + $tax = wpinv_price($tax, $this->get_currency()); |
|
1416 | 1416 | } |
1417 | 1417 | |
1418 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1418 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | - public function get_fees( $type = 'all' ) { |
|
1422 | - $fees = array(); |
|
1421 | + public function get_fees($type = 'all') { |
|
1422 | + $fees = array(); |
|
1423 | 1423 | |
1424 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1425 | - foreach ( $this->fees as $fee ) { |
|
1426 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1424 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1425 | + foreach ($this->fees as $fee) { |
|
1426 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1427 | 1427 | continue; |
1428 | 1428 | } |
1429 | 1429 | |
1430 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1431 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1432 | - $fees[] = $fee; |
|
1430 | + $fee['label'] = stripslashes($fee['label']); |
|
1431 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1432 | + $fees[] = $fee; |
|
1433 | 1433 | } |
1434 | 1434 | } |
1435 | 1435 | |
1436 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1436 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1437 | 1437 | } |
1438 | 1438 | |
1439 | - public function get_fees_total( $type = 'all' ) { |
|
1440 | - $fees_total = (float) 0.00; |
|
1439 | + public function get_fees_total($type = 'all') { |
|
1440 | + $fees_total = (float)0.00; |
|
1441 | 1441 | |
1442 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1443 | - if ( ! empty( $payment_fees ) ) { |
|
1444 | - foreach ( $payment_fees as $fee ) { |
|
1445 | - $fees_total += (float) $fee['amount']; |
|
1442 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1443 | + if (!empty($payment_fees)) { |
|
1444 | + foreach ($payment_fees as $fee) { |
|
1445 | + $fees_total += (float)$fee['amount']; |
|
1446 | 1446 | } |
1447 | 1447 | } |
1448 | 1448 | |
1449 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1449 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1450 | 1450 | /* |
1451 | 1451 | $fees = $this->get_fees( $type ); |
1452 | 1452 | |
@@ -1466,116 +1466,116 @@ discard block |
||
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | public function get_user_id() { |
1469 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1469 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | public function get_first_name() { |
1473 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1473 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | public function get_last_name() { |
1477 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1477 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1478 | 1478 | } |
1479 | 1479 | |
1480 | 1480 | public function get_user_full_name() { |
1481 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1481 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1482 | 1482 | } |
1483 | 1483 | |
1484 | 1484 | public function get_user_info() { |
1485 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1485 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | public function get_email() { |
1489 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1489 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1490 | 1490 | } |
1491 | 1491 | |
1492 | 1492 | public function get_address() { |
1493 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1493 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1494 | 1494 | } |
1495 | 1495 | |
1496 | 1496 | public function get_phone() { |
1497 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1497 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1498 | 1498 | } |
1499 | 1499 | |
1500 | 1500 | public function get_number() { |
1501 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1501 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | public function get_items() { |
1505 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1505 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1506 | 1506 | } |
1507 | 1507 | |
1508 | 1508 | public function get_key() { |
1509 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1509 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1510 | 1510 | } |
1511 | 1511 | |
1512 | 1512 | public function get_transaction_id() { |
1513 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1513 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | public function get_gateway() { |
1517 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1517 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | public function get_gateway_title() { |
1521 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1521 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1522 | 1522 | |
1523 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1523 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | public function get_currency() { |
1527 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1527 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | public function get_created_date() { |
1531 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1531 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1532 | 1532 | } |
1533 | 1533 | |
1534 | - public function get_due_date( $display = false ) { |
|
1535 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1534 | + public function get_due_date($display = false) { |
|
1535 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1536 | 1536 | |
1537 | - if ( !$display || empty( $due_date ) ) { |
|
1537 | + if (!$display || empty($due_date)) { |
|
1538 | 1538 | return $due_date; |
1539 | 1539 | } |
1540 | 1540 | |
1541 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
1541 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
1542 | 1542 | } |
1543 | 1543 | |
1544 | 1544 | public function get_completed_date() { |
1545 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1545 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | - public function get_invoice_date( $formatted = true ) { |
|
1548 | + public function get_invoice_date($formatted = true) { |
|
1549 | 1549 | $date_completed = $this->completed_date; |
1550 | 1550 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1551 | 1551 | |
1552 | - if ( $invoice_date == '' ) { |
|
1552 | + if ($invoice_date == '') { |
|
1553 | 1553 | $date_created = $this->date; |
1554 | 1554 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1555 | 1555 | } |
1556 | 1556 | |
1557 | - if ( $formatted && $invoice_date ) { |
|
1558 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
1557 | + if ($formatted && $invoice_date) { |
|
1558 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
1559 | 1559 | } |
1560 | 1560 | |
1561 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1561 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1562 | 1562 | } |
1563 | 1563 | |
1564 | 1564 | public function get_ip() { |
1565 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1565 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1566 | 1566 | } |
1567 | 1567 | |
1568 | - public function has_status( $status ) { |
|
1569 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1568 | + public function has_status($status) { |
|
1569 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1570 | 1570 | } |
1571 | 1571 | |
1572 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1572 | + public function add_item($item_id = 0, $args = array()) { |
|
1573 | 1573 | global $wpi_current_id, $wpi_item_id; |
1574 | 1574 | |
1575 | - $item = new WPInv_Item( $item_id ); |
|
1575 | + $item = new WPInv_Item($item_id); |
|
1576 | 1576 | |
1577 | 1577 | // Bail if this post isn't a item |
1578 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1578 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1579 | 1579 | return false; |
1580 | 1580 | } |
1581 | 1581 | |
@@ -1593,8 +1593,8 @@ discard block |
||
1593 | 1593 | 'fees' => array() |
1594 | 1594 | ); |
1595 | 1595 | |
1596 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1597 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1596 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1597 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1598 | 1598 | |
1599 | 1599 | $wpi_current_id = $this->ID; |
1600 | 1600 | $wpi_item_id = $item->ID; |
@@ -1606,19 +1606,19 @@ discard block |
||
1606 | 1606 | $found_cart_key = false; |
1607 | 1607 | |
1608 | 1608 | if ($has_quantities) { |
1609 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1609 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1610 | 1610 | |
1611 | - foreach ( $this->items as $key => $cart_item ) { |
|
1612 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1611 | + foreach ($this->items as $key => $cart_item) { |
|
1612 | + if ((int)$item_id !== (int)$cart_item['id']) { |
|
1613 | 1613 | continue; |
1614 | 1614 | } |
1615 | 1615 | |
1616 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1616 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1617 | 1617 | break; |
1618 | 1618 | } |
1619 | 1619 | |
1620 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1621 | - if ( $item_id != $cart_item['id'] ) { |
|
1620 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1621 | + if ($item_id != $cart_item['id']) { |
|
1622 | 1622 | continue; |
1623 | 1623 | } |
1624 | 1624 | |
@@ -1630,29 +1630,29 @@ discard block |
||
1630 | 1630 | if ($has_quantities && $found_cart_key !== false) { |
1631 | 1631 | $cart_item = $this->cart_details[$found_cart_key]; |
1632 | 1632 | $item_price = $cart_item['item_price']; |
1633 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1634 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1633 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1634 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1635 | 1635 | |
1636 | 1636 | $new_quantity = $quantity + $args['quantity']; |
1637 | 1637 | $subtotal = $item_price * $new_quantity; |
1638 | 1638 | |
1639 | 1639 | $args['quantity'] = $new_quantity; |
1640 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1641 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1640 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1641 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1642 | 1642 | |
1643 | 1643 | $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
1644 | 1644 | $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
1645 | 1645 | // The total increase equals the number removed * the item_price |
1646 | - $total_increased = wpinv_format_amount( $item_price, NULL, true ); |
|
1646 | + $total_increased = wpinv_format_amount($item_price, NULL, true); |
|
1647 | 1647 | |
1648 | - if ( wpinv_prices_include_tax() ) { |
|
1649 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1648 | + if (wpinv_prices_include_tax()) { |
|
1649 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1650 | 1650 | } |
1651 | 1651 | |
1652 | - $total = $subtotal - $discount + $tax; |
|
1652 | + $total = $subtotal - $discount + $tax; |
|
1653 | 1653 | |
1654 | 1654 | // Do not allow totals to go negative |
1655 | - if( $total < 0 ) { |
|
1655 | + if ($total < 0) { |
|
1656 | 1656 | $total = 0; |
1657 | 1657 | } |
1658 | 1658 | |
@@ -1668,20 +1668,20 @@ discard block |
||
1668 | 1668 | $this->cart_details[$found_cart_key] = $cart_item; |
1669 | 1669 | } else { |
1670 | 1670 | // Allow overriding the price |
1671 | - if( false !== $args['item_price'] ) { |
|
1671 | + if (false !== $args['item_price']) { |
|
1672 | 1672 | $item_price = $args['item_price']; |
1673 | 1673 | } else { |
1674 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1674 | + $item_price = wpinv_get_item_price($item->ID); |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | // Sanitizing the price here so we don't have a dozen calls later |
1678 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1679 | - $subtotal = wpinv_format_amount( $item_price * $args['quantity'], NULL, true ); |
|
1678 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1679 | + $subtotal = wpinv_format_amount($item_price * $args['quantity'], NULL, true); |
|
1680 | 1680 | |
1681 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1682 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1683 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1684 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1681 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1682 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1683 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1684 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1685 | 1685 | |
1686 | 1686 | // Setup the items meta item |
1687 | 1687 | $new_item = array( |
@@ -1689,28 +1689,28 @@ discard block |
||
1689 | 1689 | 'quantity' => $args['quantity'], |
1690 | 1690 | ); |
1691 | 1691 | |
1692 | - $this->items[] = $new_item; |
|
1692 | + $this->items[] = $new_item; |
|
1693 | 1693 | |
1694 | - if ( wpinv_prices_include_tax() ) { |
|
1695 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1694 | + if (wpinv_prices_include_tax()) { |
|
1695 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1696 | 1696 | } |
1697 | 1697 | |
1698 | - $total = $subtotal - $discount + $tax; |
|
1698 | + $total = $subtotal - $discount + $tax; |
|
1699 | 1699 | |
1700 | 1700 | // Do not allow totals to go negative |
1701 | - if( $total < 0 ) { |
|
1701 | + if ($total < 0) { |
|
1702 | 1702 | $total = 0; |
1703 | 1703 | } |
1704 | 1704 | |
1705 | 1705 | $this->cart_details[] = array( |
1706 | 1706 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1707 | 1707 | 'id' => $item->ID, |
1708 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
1708 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
1709 | 1709 | 'quantity' => $args['quantity'], |
1710 | 1710 | 'discount' => $discount, |
1711 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
1712 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
1713 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
1711 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
1712 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
1713 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
1714 | 1714 | 'vat_rate' => $tax_rate, |
1715 | 1715 | 'vat_class' => $tax_class, |
1716 | 1716 | 'meta' => $args['meta'], |
@@ -1720,69 +1720,69 @@ discard block |
||
1720 | 1720 | $subtotal = $subtotal - $discount; |
1721 | 1721 | } |
1722 | 1722 | |
1723 | - $added_item = end( $this->cart_details ); |
|
1724 | - $added_item['action'] = 'add'; |
|
1723 | + $added_item = end($this->cart_details); |
|
1724 | + $added_item['action'] = 'add'; |
|
1725 | 1725 | |
1726 | 1726 | $this->pending['items'][] = $added_item; |
1727 | 1727 | |
1728 | - $this->increase_subtotal( $subtotal ); |
|
1729 | - $this->increase_tax( $tax ); |
|
1728 | + $this->increase_subtotal($subtotal); |
|
1729 | + $this->increase_tax($tax); |
|
1730 | 1730 | |
1731 | 1731 | return true; |
1732 | 1732 | } |
1733 | 1733 | |
1734 | - public function remove_item( $item_id, $args = array() ) { |
|
1734 | + public function remove_item($item_id, $args = array()) { |
|
1735 | 1735 | // Set some defaults |
1736 | 1736 | $defaults = array( |
1737 | 1737 | 'quantity' => 1, |
1738 | 1738 | 'item_price' => false, |
1739 | 1739 | 'cart_index' => false, |
1740 | 1740 | ); |
1741 | - $args = wp_parse_args( $args, $defaults ); |
|
1741 | + $args = wp_parse_args($args, $defaults); |
|
1742 | 1742 | |
1743 | 1743 | // Bail if this post isn't a item |
1744 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1744 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1745 | 1745 | return false; |
1746 | 1746 | } |
1747 | 1747 | |
1748 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1748 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1749 | 1749 | |
1750 | - foreach ( $this->items as $key => $item ) { |
|
1751 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1750 | + foreach ($this->items as $key => $item) { |
|
1751 | + if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) { |
|
1752 | 1752 | continue; |
1753 | 1753 | } |
1754 | 1754 | |
1755 | - if ( false !== $args['cart_index'] ) { |
|
1756 | - $cart_index = absint( $args['cart_index'] ); |
|
1757 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
1755 | + if (false !== $args['cart_index']) { |
|
1756 | + $cart_index = absint($args['cart_index']); |
|
1757 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
1758 | 1758 | |
1759 | - if ( ! empty( $cart_item ) ) { |
|
1759 | + if (!empty($cart_item)) { |
|
1760 | 1760 | // If the cart index item isn't the same item ID, don't remove it |
1761 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
1761 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
1762 | 1762 | continue; |
1763 | 1763 | } |
1764 | 1764 | } |
1765 | 1765 | } |
1766 | 1766 | |
1767 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
1768 | - if ( $item_quantity > $args['quantity'] ) { |
|
1769 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
1767 | + $item_quantity = $this->items[$key]['quantity']; |
|
1768 | + if ($item_quantity > $args['quantity']) { |
|
1769 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
1770 | 1770 | break; |
1771 | 1771 | } else { |
1772 | - unset( $this->items[ $key ] ); |
|
1772 | + unset($this->items[$key]); |
|
1773 | 1773 | break; |
1774 | 1774 | } |
1775 | 1775 | } |
1776 | 1776 | |
1777 | 1777 | $found_cart_key = false; |
1778 | - if ( false === $args['cart_index'] ) { |
|
1779 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
1780 | - if ( $item_id != $item['id'] ) { |
|
1778 | + if (false === $args['cart_index']) { |
|
1779 | + foreach ($this->cart_details as $cart_key => $item) { |
|
1780 | + if ($item_id != $item['id']) { |
|
1781 | 1781 | continue; |
1782 | 1782 | } |
1783 | 1783 | |
1784 | - if ( false !== $args['item_price'] ) { |
|
1785 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
1784 | + if (false !== $args['item_price']) { |
|
1785 | + if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) { |
|
1786 | 1786 | continue; |
1787 | 1787 | } |
1788 | 1788 | } |
@@ -1791,13 +1791,13 @@ discard block |
||
1791 | 1791 | break; |
1792 | 1792 | } |
1793 | 1793 | } else { |
1794 | - $cart_index = absint( $args['cart_index'] ); |
|
1794 | + $cart_index = absint($args['cart_index']); |
|
1795 | 1795 | |
1796 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
1796 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
1797 | 1797 | return false; // Invalid cart index passed. |
1798 | 1798 | } |
1799 | 1799 | |
1800 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
1800 | + if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) { |
|
1801 | 1801 | return false; // We still need the proper Item ID to be sure. |
1802 | 1802 | } |
1803 | 1803 | |
@@ -1805,41 +1805,41 @@ discard block |
||
1805 | 1805 | } |
1806 | 1806 | |
1807 | 1807 | $cart_item = $this->cart_details[$found_cart_key]; |
1808 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1808 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1809 | 1809 | |
1810 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
1810 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
1811 | 1811 | return false; // Invoice must contain at least one item. |
1812 | 1812 | } |
1813 | 1813 | |
1814 | - $discounts = $this->get_discounts(); |
|
1814 | + $discounts = $this->get_discounts(); |
|
1815 | 1815 | |
1816 | - if ( $quantity > $args['quantity'] ) { |
|
1816 | + if ($quantity > $args['quantity']) { |
|
1817 | 1817 | $item_price = $cart_item['item_price']; |
1818 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1818 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1819 | 1819 | |
1820 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
1820 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
1821 | 1821 | $subtotal = $item_price * $new_quantity; |
1822 | 1822 | |
1823 | 1823 | $args['quantity'] = $new_quantity; |
1824 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1825 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1824 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1825 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1826 | 1826 | |
1827 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0; |
|
1827 | + $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0; |
|
1828 | 1828 | $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
1829 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0; |
|
1829 | + $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0; |
|
1830 | 1830 | $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
1831 | 1831 | |
1832 | 1832 | // The total increase equals the number removed * the item_price |
1833 | - $total_decrease = wpinv_format_amount( $item_price, NULL, true ); |
|
1833 | + $total_decrease = wpinv_format_amount($item_price, NULL, true); |
|
1834 | 1834 | |
1835 | - if ( wpinv_prices_include_tax() ) { |
|
1836 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1835 | + if (wpinv_prices_include_tax()) { |
|
1836 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1837 | 1837 | } |
1838 | 1838 | |
1839 | - $total = $subtotal - $discount + $tax; |
|
1839 | + $total = $subtotal - $discount + $tax; |
|
1840 | 1840 | |
1841 | 1841 | // Do not allow totals to go negative |
1842 | - if( $total < 0 ) { |
|
1842 | + if ($total < 0) { |
|
1843 | 1843 | $total = 0; |
1844 | 1844 | } |
1845 | 1845 | |
@@ -1858,16 +1858,16 @@ discard block |
||
1858 | 1858 | |
1859 | 1859 | $this->cart_details[$found_cart_key] = $cart_item; |
1860 | 1860 | |
1861 | - $remove_item = end( $this->cart_details ); |
|
1861 | + $remove_item = end($this->cart_details); |
|
1862 | 1862 | } else { |
1863 | 1863 | $item_price = $cart_item['item_price']; |
1864 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1865 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
1864 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1865 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
1866 | 1866 | |
1867 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
1867 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
1868 | 1868 | $tax_decrease = $tax; |
1869 | 1869 | |
1870 | - unset( $this->cart_details[$found_cart_key] ); |
|
1870 | + unset($this->cart_details[$found_cart_key]); |
|
1871 | 1871 | |
1872 | 1872 | $remove_item = $args; |
1873 | 1873 | $remove_item['id'] = $item_id; |
@@ -1878,8 +1878,8 @@ discard block |
||
1878 | 1878 | $remove_item['action'] = 'remove'; |
1879 | 1879 | $this->pending['items'][] = $remove_item; |
1880 | 1880 | |
1881 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
1882 | - $this->decrease_tax( $tax_decrease ); |
|
1881 | + $this->decrease_subtotal($subtotal_decrease); |
|
1882 | + $this->decrease_tax($tax_decrease); |
|
1883 | 1883 | |
1884 | 1884 | return true; |
1885 | 1885 | } |
@@ -1887,7 +1887,7 @@ discard block |
||
1887 | 1887 | public function update_items($temp = false) { |
1888 | 1888 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
1889 | 1889 | |
1890 | - if ( !empty( $this->cart_details ) ) { |
|
1890 | + if (!empty($this->cart_details)) { |
|
1891 | 1891 | $wpi_nosave = $temp; |
1892 | 1892 | $cart_subtotal = 0; |
1893 | 1893 | $cart_discount = 0; |
@@ -1897,41 +1897,41 @@ discard block |
||
1897 | 1897 | $_POST['wpinv_country'] = $this->country; |
1898 | 1898 | $_POST['wpinv_state'] = $this->state; |
1899 | 1899 | |
1900 | - foreach ( $this->cart_details as $key => $item ) { |
|
1900 | + foreach ($this->cart_details as $key => $item) { |
|
1901 | 1901 | $item_price = $item['item_price']; |
1902 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1903 | - $amount = wpinv_format_amount( $item_price * $quantity, NULL, true ); |
|
1902 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1903 | + $amount = wpinv_format_amount($item_price * $quantity, NULL, true); |
|
1904 | 1904 | $subtotal = $item_price * $quantity; |
1905 | 1905 | |
1906 | 1906 | $wpi_current_id = $this->ID; |
1907 | 1907 | $wpi_item_id = $item['id']; |
1908 | 1908 | |
1909 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
1909 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
1910 | 1910 | |
1911 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
1912 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
1913 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1911 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
1912 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
1913 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1914 | 1914 | |
1915 | - if ( wpinv_prices_include_tax() ) { |
|
1916 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1915 | + if (wpinv_prices_include_tax()) { |
|
1916 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1917 | 1917 | } |
1918 | 1918 | |
1919 | - $total = $subtotal - $discount + $tax; |
|
1919 | + $total = $subtotal - $discount + $tax; |
|
1920 | 1920 | |
1921 | 1921 | // Do not allow totals to go negative |
1922 | - if( $total < 0 ) { |
|
1922 | + if ($total < 0) { |
|
1923 | 1923 | $total = 0; |
1924 | 1924 | } |
1925 | 1925 | |
1926 | 1926 | $cart_details[] = array( |
1927 | 1927 | 'id' => $item['id'], |
1928 | 1928 | 'name' => $item['name'], |
1929 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
1929 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
1930 | 1930 | 'quantity' => $quantity, |
1931 | 1931 | 'discount' => $discount, |
1932 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
1933 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
1934 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
1932 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
1933 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
1934 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
1935 | 1935 | 'vat_rate' => $tax_rate, |
1936 | 1936 | 'vat_class' => $tax_class, |
1937 | 1937 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
@@ -1942,9 +1942,9 @@ discard block |
||
1942 | 1942 | $cart_discount += (float)($discount); |
1943 | 1943 | $cart_tax += (float)($tax); |
1944 | 1944 | } |
1945 | - $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
1946 | - $this->tax = wpinv_format_amount( $cart_tax, NULL, true ); |
|
1947 | - $this->discount = wpinv_format_amount( $cart_discount, NULL, true ); |
|
1945 | + $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true); |
|
1946 | + $this->tax = wpinv_format_amount($cart_tax, NULL, true); |
|
1947 | + $this->discount = wpinv_format_amount($cart_discount, NULL, true); |
|
1948 | 1948 | |
1949 | 1949 | $this->recalculate_total(); |
1950 | 1950 | |
@@ -1956,221 +1956,221 @@ discard block |
||
1956 | 1956 | |
1957 | 1957 | public function recalculate_totals($temp = false) { |
1958 | 1958 | $this->update_items($temp); |
1959 | - $this->save( true ); |
|
1959 | + $this->save(true); |
|
1960 | 1960 | |
1961 | 1961 | return $this; |
1962 | 1962 | } |
1963 | 1963 | |
1964 | 1964 | public function needs_payment() { |
1965 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this ); |
|
1965 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this); |
|
1966 | 1966 | |
1967 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) { |
|
1967 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) { |
|
1968 | 1968 | $needs_payment = true; |
1969 | 1969 | } else { |
1970 | 1970 | $needs_payment = false; |
1971 | 1971 | } |
1972 | 1972 | |
1973 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
1973 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
1974 | 1974 | } |
1975 | 1975 | |
1976 | - public function get_checkout_payment_url( $on_checkout = false, $secret = false ) { |
|
1976 | + public function get_checkout_payment_url($on_checkout = false, $secret = false) { |
|
1977 | 1977 | $pay_url = wpinv_get_checkout_uri(); |
1978 | 1978 | |
1979 | - if ( is_ssl() ) { |
|
1980 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
1979 | + if (is_ssl()) { |
|
1980 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
1981 | 1981 | } |
1982 | 1982 | |
1983 | 1983 | $key = $this->get_key(); |
1984 | 1984 | |
1985 | - if ( $on_checkout ) { |
|
1986 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
1985 | + if ($on_checkout) { |
|
1986 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
1987 | 1987 | } else { |
1988 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
1988 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | - if ( $secret ) { |
|
1992 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
1991 | + if ($secret) { |
|
1992 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
1993 | 1993 | } |
1994 | 1994 | |
1995 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this ); |
|
1995 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this); |
|
1996 | 1996 | } |
1997 | 1997 | |
1998 | - public function get_view_url( $secret = false ) { |
|
1999 | - $print_url = get_permalink( $this->ID ); |
|
1998 | + public function get_view_url($secret = false) { |
|
1999 | + $print_url = get_permalink($this->ID); |
|
2000 | 2000 | |
2001 | - if ( $secret ) { |
|
2002 | - $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url ); |
|
2001 | + if ($secret) { |
|
2002 | + $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url); |
|
2003 | 2003 | } |
2004 | 2004 | |
2005 | - return apply_filters( 'wpinv_get_view_url', $print_url, $this ); |
|
2005 | + return apply_filters('wpinv_get_view_url', $print_url, $this); |
|
2006 | 2006 | } |
2007 | 2007 | |
2008 | - public function generate_key( $string = '' ) { |
|
2009 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
2010 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
2008 | + public function generate_key($string = '') { |
|
2009 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
2010 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
2011 | 2011 | } |
2012 | 2012 | |
2013 | 2013 | public function is_recurring() { |
2014 | - if ( empty( $this->cart_details ) ) { |
|
2014 | + if (empty($this->cart_details)) { |
|
2015 | 2015 | return false; |
2016 | 2016 | } |
2017 | 2017 | |
2018 | 2018 | $has_subscription = false; |
2019 | - foreach( $this->cart_details as $cart_item ) { |
|
2020 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2019 | + foreach ($this->cart_details as $cart_item) { |
|
2020 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2021 | 2021 | $has_subscription = true; |
2022 | 2022 | break; |
2023 | 2023 | } |
2024 | 2024 | } |
2025 | 2025 | |
2026 | - if ( count( $this->cart_details ) > 1 ) { |
|
2026 | + if (count($this->cart_details) > 1) { |
|
2027 | 2027 | $has_subscription = false; |
2028 | 2028 | } |
2029 | 2029 | |
2030 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
2030 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
2031 | 2031 | } |
2032 | 2032 | |
2033 | 2033 | public function is_free_trial() { |
2034 | 2034 | $is_free_trial = false; |
2035 | 2035 | |
2036 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
2037 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
2036 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
2037 | + if (!empty($item) && $item->has_free_trial()) { |
|
2038 | 2038 | $is_free_trial = true; |
2039 | 2039 | } |
2040 | 2040 | } |
2041 | 2041 | |
2042 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details ); |
|
2042 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details); |
|
2043 | 2043 | } |
2044 | 2044 | |
2045 | - public function get_recurring( $object = false ) { |
|
2045 | + public function get_recurring($object = false) { |
|
2046 | 2046 | $item = NULL; |
2047 | 2047 | |
2048 | - if ( empty( $this->cart_details ) ) { |
|
2048 | + if (empty($this->cart_details)) { |
|
2049 | 2049 | return $item; |
2050 | 2050 | } |
2051 | 2051 | |
2052 | - foreach( $this->cart_details as $cart_item ) { |
|
2053 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2052 | + foreach ($this->cart_details as $cart_item) { |
|
2053 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2054 | 2054 | $item = $cart_item['id']; |
2055 | 2055 | break; |
2056 | 2056 | } |
2057 | 2057 | } |
2058 | 2058 | |
2059 | - if ( $object ) { |
|
2060 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
2059 | + if ($object) { |
|
2060 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
2061 | 2061 | |
2062 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
2062 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
2063 | 2063 | } |
2064 | 2064 | |
2065 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
2065 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
2066 | 2066 | } |
2067 | 2067 | |
2068 | 2068 | public function get_subscription_name() { |
2069 | - $item = $this->get_recurring( true ); |
|
2069 | + $item = $this->get_recurring(true); |
|
2070 | 2070 | |
2071 | - if ( empty( $item ) ) { |
|
2071 | + if (empty($item)) { |
|
2072 | 2072 | return NULL; |
2073 | 2073 | } |
2074 | 2074 | |
2075 | - if ( !($name = $item->get_name()) ) { |
|
2075 | + if (!($name = $item->get_name())) { |
|
2076 | 2076 | $name = $item->post_name; |
2077 | 2077 | } |
2078 | 2078 | |
2079 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
2079 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
2080 | 2080 | } |
2081 | 2081 | |
2082 | 2082 | public function get_expiration() { |
2083 | - $expiration = $this->get_meta( '_wpinv_subscr_expiration', true ); |
|
2083 | + $expiration = $this->get_meta('_wpinv_subscr_expiration', true); |
|
2084 | 2084 | return $expiration; |
2085 | 2085 | } |
2086 | 2086 | |
2087 | - public function get_cancelled_date( $formatted = true ) { |
|
2088 | - $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : ''; |
|
2087 | + public function get_cancelled_date($formatted = true) { |
|
2088 | + $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : ''; |
|
2089 | 2089 | |
2090 | - if ( $formatted && $cancelled_date ) { |
|
2091 | - $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) ); |
|
2090 | + if ($formatted && $cancelled_date) { |
|
2091 | + $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date)); |
|
2092 | 2092 | } |
2093 | 2093 | |
2094 | 2094 | return $cancelled_date; |
2095 | 2095 | } |
2096 | 2096 | |
2097 | - public function get_trial_end_date( $formatted = true ) { |
|
2098 | - if ( !$this->is_free_trial() || !$this->is_paid() ) { |
|
2097 | + public function get_trial_end_date($formatted = true) { |
|
2098 | + if (!$this->is_free_trial() || !$this->is_paid()) { |
|
2099 | 2099 | return NULL; |
2100 | 2100 | } |
2101 | 2101 | |
2102 | - $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : ''; |
|
2102 | + $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : ''; |
|
2103 | 2103 | |
2104 | - if ( empty( $trial_end_date ) ) { |
|
2105 | - $trial_start_time = strtotime( $this->get_subscription_start() ); |
|
2106 | - $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2104 | + if (empty($trial_end_date)) { |
|
2105 | + $trial_start_time = strtotime($this->get_subscription_start()); |
|
2106 | + $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
2107 | 2107 | |
2108 | - $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time ); |
|
2108 | + $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time); |
|
2109 | 2109 | } |
2110 | 2110 | |
2111 | - if ( $formatted && $trial_end_date ) { |
|
2112 | - $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) ); |
|
2111 | + if ($formatted && $trial_end_date) { |
|
2112 | + $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date)); |
|
2113 | 2113 | } |
2114 | 2114 | |
2115 | 2115 | return $trial_end_date; |
2116 | 2116 | } |
2117 | 2117 | |
2118 | - public function get_subscription_created( $default = true ) { |
|
2119 | - $created = $this->get_meta( '_wpinv_subscr_created', true ); |
|
2118 | + public function get_subscription_created($default = true) { |
|
2119 | + $created = $this->get_meta('_wpinv_subscr_created', true); |
|
2120 | 2120 | |
2121 | - if ( empty( $created ) && $default ) { |
|
2121 | + if (empty($created) && $default) { |
|
2122 | 2122 | $created = $this->date; |
2123 | 2123 | } |
2124 | 2124 | return $created; |
2125 | 2125 | } |
2126 | 2126 | |
2127 | - public function get_subscription_start( $formatted = true ) { |
|
2128 | - if ( !$this->is_paid() ) { |
|
2127 | + public function get_subscription_start($formatted = true) { |
|
2128 | + if (!$this->is_paid()) { |
|
2129 | 2129 | return '-'; |
2130 | 2130 | } |
2131 | - $start = $this->get_subscription_created(); |
|
2131 | + $start = $this->get_subscription_created(); |
|
2132 | 2132 | |
2133 | - if ( $formatted ) { |
|
2134 | - $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) ); |
|
2133 | + if ($formatted) { |
|
2134 | + $date = date_i18n(get_option('date_format'), strtotime($start)); |
|
2135 | 2135 | } else { |
2136 | - $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) ); |
|
2136 | + $date = date_i18n('Y-m-d H:i:s', strtotime($start)); |
|
2137 | 2137 | } |
2138 | 2138 | |
2139 | 2139 | return $date; |
2140 | 2140 | } |
2141 | 2141 | |
2142 | - public function get_subscription_end( $formatted = true ) { |
|
2143 | - if ( !$this->is_paid() ) { |
|
2142 | + public function get_subscription_end($formatted = true) { |
|
2143 | + if (!$this->is_paid()) { |
|
2144 | 2144 | return '-'; |
2145 | 2145 | } |
2146 | 2146 | $start = $this->get_subscription_created(); |
2147 | 2147 | $interval = $this->get_subscription_interval(); |
2148 | - $period = $this->get_subscription_period( true ); |
|
2148 | + $period = $this->get_subscription_period(true); |
|
2149 | 2149 | $bill_times = (int)$this->get_bill_times(); |
2150 | 2150 | |
2151 | - if ( $bill_times == 0 ) { |
|
2152 | - return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times; |
|
2151 | + if ($bill_times == 0) { |
|
2152 | + return $formatted ? __('Until cancelled', 'invoicing') : $bill_times; |
|
2153 | 2153 | } |
2154 | 2154 | |
2155 | - $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period; |
|
2155 | + $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period; |
|
2156 | 2156 | |
2157 | - $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period ); |
|
2157 | + $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period); |
|
2158 | 2158 | |
2159 | - if ( $this->is_free_trial() ) { |
|
2160 | - $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2159 | + if ($this->is_free_trial()) { |
|
2160 | + $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
2161 | 2161 | } |
2162 | 2162 | |
2163 | - if ( $formatted ) { |
|
2164 | - $date = date_i18n( get_option( 'date_format' ), $end_time ); |
|
2163 | + if ($formatted) { |
|
2164 | + $date = date_i18n(get_option('date_format'), $end_time); |
|
2165 | 2165 | } else { |
2166 | - $date = date_i18n( 'Y-m-d H:i:s', $end_time ); |
|
2166 | + $date = date_i18n('Y-m-d H:i:s', $end_time); |
|
2167 | 2167 | } |
2168 | 2168 | |
2169 | 2169 | return $date; |
2170 | 2170 | } |
2171 | 2171 | |
2172 | 2172 | public function get_expiration_time() { |
2173 | - return strtotime( $this->get_expiration(), current_time( 'timestamp' ) ); |
|
2173 | + return strtotime($this->get_expiration(), current_time('timestamp')); |
|
2174 | 2174 | } |
2175 | 2175 | |
2176 | 2176 | public function get_original_invoice_id() { |
@@ -2182,125 +2182,125 @@ discard block |
||
2182 | 2182 | return $subscription_data['bill_times']; |
2183 | 2183 | } |
2184 | 2184 | |
2185 | - public function get_child_payments( $self = false ) { |
|
2186 | - $invoices = get_posts( array( |
|
2185 | + public function get_child_payments($self = false) { |
|
2186 | + $invoices = get_posts(array( |
|
2187 | 2187 | 'post_type' => 'wpi_invoice', |
2188 | 2188 | 'post_parent' => (int)$this->ID, |
2189 | 2189 | 'posts_per_page' => '999', |
2190 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
2190 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
2191 | 2191 | 'orderby' => 'ID', |
2192 | 2192 | 'order' => 'DESC', |
2193 | 2193 | 'fields' => 'ids' |
2194 | - ) ); |
|
2194 | + )); |
|
2195 | 2195 | |
2196 | - if ( $this->is_free_trial() ) { |
|
2196 | + if ($this->is_free_trial()) { |
|
2197 | 2197 | $self = false; |
2198 | 2198 | } |
2199 | 2199 | |
2200 | - if ( $self && $this->is_paid() ) { |
|
2201 | - if ( !empty( $invoices ) ) { |
|
2200 | + if ($self && $this->is_paid()) { |
|
2201 | + if (!empty($invoices)) { |
|
2202 | 2202 | $invoices[] = (int)$this->ID; |
2203 | 2203 | } else { |
2204 | - $invoices = array( $this->ID ); |
|
2204 | + $invoices = array($this->ID); |
|
2205 | 2205 | } |
2206 | 2206 | |
2207 | - $invoices = array_unique( $invoices ); |
|
2207 | + $invoices = array_unique($invoices); |
|
2208 | 2208 | } |
2209 | 2209 | |
2210 | 2210 | return $invoices; |
2211 | 2211 | } |
2212 | 2212 | |
2213 | - public function get_total_payments( $self = true ) { |
|
2214 | - return count( $this->get_child_payments( $self ) ); |
|
2213 | + public function get_total_payments($self = true) { |
|
2214 | + return count($this->get_child_payments($self)); |
|
2215 | 2215 | } |
2216 | 2216 | |
2217 | - public function get_subscriptions( $limit = -1 ) { |
|
2218 | - $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) ); |
|
2217 | + public function get_subscriptions($limit = -1) { |
|
2218 | + $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit)); |
|
2219 | 2219 | |
2220 | 2220 | return $subscriptions; |
2221 | 2221 | } |
2222 | 2222 | |
2223 | 2223 | public function get_subscription_id() { |
2224 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2224 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
2225 | 2225 | |
2226 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
2227 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
2226 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
2227 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
2228 | 2228 | |
2229 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2229 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
2230 | 2230 | } |
2231 | 2231 | |
2232 | 2232 | return $subscription_id; |
2233 | 2233 | } |
2234 | 2234 | |
2235 | 2235 | public function get_subscription_status() { |
2236 | - $subscription_status = $this->get_meta( '_wpinv_subscr_status', true ); |
|
2236 | + $subscription_status = $this->get_meta('_wpinv_subscr_status', true); |
|
2237 | 2237 | |
2238 | - if ( empty( $subscription_status ) ) { |
|
2238 | + if (empty($subscription_status)) { |
|
2239 | 2239 | $status = 'pending'; |
2240 | 2240 | |
2241 | - if ( $this->is_paid() ) { |
|
2241 | + if ($this->is_paid()) { |
|
2242 | 2242 | $bill_times = (int)$this->get_bill_times(); |
2243 | 2243 | $times_billed = (int)$this->get_total_payments(); |
2244 | - $expiration = $this->get_subscription_end( false ); |
|
2245 | - $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false; |
|
2244 | + $expiration = $this->get_subscription_end(false); |
|
2245 | + $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false; |
|
2246 | 2246 | |
2247 | - if ( (int)$bill_times == 0 ) { |
|
2247 | + if ((int)$bill_times == 0) { |
|
2248 | 2248 | $status = $expired ? 'expired' : 'active'; |
2249 | - } else if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
2249 | + } else if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
2250 | 2250 | $status = 'completed'; |
2251 | - } else if ( $expired ) { |
|
2251 | + } else if ($expired) { |
|
2252 | 2252 | $status = 'expired'; |
2253 | - } else if ( $bill_times > 0 ) { |
|
2253 | + } else if ($bill_times > 0) { |
|
2254 | 2254 | $status = 'active'; |
2255 | 2255 | } else { |
2256 | 2256 | $status = 'pending'; |
2257 | 2257 | } |
2258 | 2258 | } |
2259 | 2259 | |
2260 | - if ( $status && $status != $subscription_status ) { |
|
2260 | + if ($status && $status != $subscription_status) { |
|
2261 | 2261 | $subscription_status = $status; |
2262 | 2262 | |
2263 | - $this->update_meta( '_wpinv_subscr_status', $status ); |
|
2263 | + $this->update_meta('_wpinv_subscr_status', $status); |
|
2264 | 2264 | } |
2265 | 2265 | } |
2266 | 2266 | |
2267 | 2267 | return $subscription_status; |
2268 | 2268 | } |
2269 | 2269 | |
2270 | - public function get_subscription_status_label( $status = '' ) { |
|
2271 | - $status = !empty( $status ) ? $status : $this->get_subscription_status(); |
|
2270 | + public function get_subscription_status_label($status = '') { |
|
2271 | + $status = !empty($status) ? $status : $this->get_subscription_status(); |
|
2272 | 2272 | |
2273 | - switch( $status ) { |
|
2273 | + switch ($status) { |
|
2274 | 2274 | case 'active' : |
2275 | - $status_label = __( 'Active', 'invoicing' ); |
|
2275 | + $status_label = __('Active', 'invoicing'); |
|
2276 | 2276 | break; |
2277 | 2277 | |
2278 | 2278 | case 'cancelled' : |
2279 | - $status_label = __( 'Cancelled', 'invoicing' ); |
|
2279 | + $status_label = __('Cancelled', 'invoicing'); |
|
2280 | 2280 | break; |
2281 | 2281 | |
2282 | 2282 | case 'completed' : |
2283 | - $status_label = __( 'Completed', 'invoicing' ); |
|
2283 | + $status_label = __('Completed', 'invoicing'); |
|
2284 | 2284 | break; |
2285 | 2285 | |
2286 | 2286 | case 'expired' : |
2287 | - $status_label = __( 'Expired', 'invoicing' ); |
|
2287 | + $status_label = __('Expired', 'invoicing'); |
|
2288 | 2288 | break; |
2289 | 2289 | |
2290 | 2290 | case 'pending' : |
2291 | - $status_label = __( 'Pending', 'invoicing' ); |
|
2291 | + $status_label = __('Pending', 'invoicing'); |
|
2292 | 2292 | break; |
2293 | 2293 | |
2294 | 2294 | case 'failing' : |
2295 | - $status_label = __( 'Failing', 'invoicing' ); |
|
2295 | + $status_label = __('Failing', 'invoicing'); |
|
2296 | 2296 | break; |
2297 | 2297 | |
2298 | 2298 | case 'stopped' : |
2299 | - $status_label = __( 'Stopped', 'invoicing' ); |
|
2299 | + $status_label = __('Stopped', 'invoicing'); |
|
2300 | 2300 | break; |
2301 | 2301 | |
2302 | 2302 | case 'trialing' : |
2303 | - $status_label = __( 'Trialing', 'invoicing' ); |
|
2303 | + $status_label = __('Trialing', 'invoicing'); |
|
2304 | 2304 | break; |
2305 | 2305 | |
2306 | 2306 | default: |
@@ -2311,15 +2311,15 @@ discard block |
||
2311 | 2311 | return $status_label; |
2312 | 2312 | } |
2313 | 2313 | |
2314 | - public function get_subscription_period( $full = false ) { |
|
2315 | - $period = $this->get_meta( '_wpinv_subscr_period', true ); |
|
2314 | + public function get_subscription_period($full = false) { |
|
2315 | + $period = $this->get_meta('_wpinv_subscr_period', true); |
|
2316 | 2316 | |
2317 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
2317 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
2318 | 2318 | $period = 'D'; |
2319 | 2319 | } |
2320 | 2320 | |
2321 | - if ( $full ) { |
|
2322 | - switch( $period ) { |
|
2321 | + if ($full) { |
|
2322 | + switch ($period) { |
|
2323 | 2323 | case 'D': |
2324 | 2324 | $period = 'day'; |
2325 | 2325 | break; |
@@ -2339,28 +2339,28 @@ discard block |
||
2339 | 2339 | } |
2340 | 2340 | |
2341 | 2341 | public function get_subscription_interval() { |
2342 | - $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true ); |
|
2342 | + $interval = (int)$this->get_meta('_wpinv_subscr_interval', true); |
|
2343 | 2343 | |
2344 | - if ( !$interval > 0 ) { |
|
2344 | + if (!$interval > 0) { |
|
2345 | 2345 | $interval = 1; |
2346 | 2346 | } |
2347 | 2347 | |
2348 | 2348 | return $interval; |
2349 | 2349 | } |
2350 | 2350 | |
2351 | - public function get_subscription_trial_period( $full = false ) { |
|
2352 | - if ( !$this->is_free_trial() ) { |
|
2351 | + public function get_subscription_trial_period($full = false) { |
|
2352 | + if (!$this->is_free_trial()) { |
|
2353 | 2353 | return ''; |
2354 | 2354 | } |
2355 | 2355 | |
2356 | - $period = $this->get_meta( '_wpinv_subscr_trial_period', true ); |
|
2356 | + $period = $this->get_meta('_wpinv_subscr_trial_period', true); |
|
2357 | 2357 | |
2358 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
2358 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
2359 | 2359 | $period = 'D'; |
2360 | 2360 | } |
2361 | 2361 | |
2362 | - if ( $full ) { |
|
2363 | - switch( $period ) { |
|
2362 | + if ($full) { |
|
2363 | + switch ($period) { |
|
2364 | 2364 | case 'D': |
2365 | 2365 | $period = 'day'; |
2366 | 2366 | break; |
@@ -2380,13 +2380,13 @@ discard block |
||
2380 | 2380 | } |
2381 | 2381 | |
2382 | 2382 | public function get_subscription_trial_interval() { |
2383 | - if ( !$this->is_free_trial() ) { |
|
2383 | + if (!$this->is_free_trial()) { |
|
2384 | 2384 | return 0; |
2385 | 2385 | } |
2386 | 2386 | |
2387 | - $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true ); |
|
2387 | + $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true); |
|
2388 | 2388 | |
2389 | - if ( !$interval > 0 ) { |
|
2389 | + if (!$interval > 0) { |
|
2390 | 2390 | $interval = 1; |
2391 | 2391 | } |
2392 | 2392 | |
@@ -2398,8 +2398,8 @@ discard block |
||
2398 | 2398 | 'status' => 'failing' |
2399 | 2399 | ); |
2400 | 2400 | |
2401 | - if ( $this->update_subscription( $args ) ) { |
|
2402 | - do_action( 'wpinv_subscription_failing', $this->ID, $this ); |
|
2401 | + if ($this->update_subscription($args)) { |
|
2402 | + do_action('wpinv_subscription_failing', $this->ID, $this); |
|
2403 | 2403 | return true; |
2404 | 2404 | } |
2405 | 2405 | |
@@ -2411,8 +2411,8 @@ discard block |
||
2411 | 2411 | 'status' => 'stopped' |
2412 | 2412 | ); |
2413 | 2413 | |
2414 | - if ( $this->update_subscription( $args ) ) { |
|
2415 | - do_action( 'wpinv_subscription_stopped', $this->ID, $this ); |
|
2414 | + if ($this->update_subscription($args)) { |
|
2415 | + do_action('wpinv_subscription_stopped', $this->ID, $this); |
|
2416 | 2416 | return true; |
2417 | 2417 | } |
2418 | 2418 | |
@@ -2424,8 +2424,8 @@ discard block |
||
2424 | 2424 | 'status' => 'active' |
2425 | 2425 | ); |
2426 | 2426 | |
2427 | - if ( $this->update_subscription( $args ) ) { |
|
2428 | - do_action( 'wpinv_subscription_restarted', $this->ID, $this ); |
|
2427 | + if ($this->update_subscription($args)) { |
|
2428 | + do_action('wpinv_subscription_restarted', $this->ID, $this); |
|
2429 | 2429 | return true; |
2430 | 2430 | } |
2431 | 2431 | |
@@ -2437,23 +2437,23 @@ discard block |
||
2437 | 2437 | 'status' => 'cancelled' |
2438 | 2438 | ); |
2439 | 2439 | |
2440 | - if ( $this->update_subscription( $args ) ) { |
|
2441 | - if ( is_user_logged_in() ) { |
|
2442 | - $userdata = get_userdata( get_current_user_id() ); |
|
2440 | + if ($this->update_subscription($args)) { |
|
2441 | + if (is_user_logged_in()) { |
|
2442 | + $userdata = get_userdata(get_current_user_id()); |
|
2443 | 2443 | $user = $userdata->user_login; |
2444 | 2444 | } else { |
2445 | - $user = __( 'gateway', 'invoicing' ); |
|
2445 | + $user = __('gateway', 'invoicing'); |
|
2446 | 2446 | } |
2447 | 2447 | |
2448 | 2448 | $subscription_id = $this->get_subscription_id(); |
2449 | - if ( !$subscription_id ) { |
|
2449 | + if (!$subscription_id) { |
|
2450 | 2450 | $subscription_id = $this->ID; |
2451 | 2451 | } |
2452 | 2452 | |
2453 | - $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user ); |
|
2454 | - $this->add_note( $note ); |
|
2453 | + $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user); |
|
2454 | + $this->add_note($note); |
|
2455 | 2455 | |
2456 | - do_action( 'wpinv_subscription_cancelled', $this->ID, $this ); |
|
2456 | + do_action('wpinv_subscription_cancelled', $this->ID, $this); |
|
2457 | 2457 | return true; |
2458 | 2458 | } |
2459 | 2459 | |
@@ -2461,11 +2461,11 @@ discard block |
||
2461 | 2461 | } |
2462 | 2462 | |
2463 | 2463 | public function can_cancel() { |
2464 | - return apply_filters( 'wpinv_subscription_can_cancel', false, $this ); |
|
2464 | + return apply_filters('wpinv_subscription_can_cancel', false, $this); |
|
2465 | 2465 | } |
2466 | 2466 | |
2467 | - public function add_subscription( $data = array() ) { |
|
2468 | - if ( empty( $this->ID ) ) { |
|
2467 | + public function add_subscription($data = array()) { |
|
2468 | + if (empty($this->ID)) { |
|
2469 | 2469 | return false; |
2470 | 2470 | } |
2471 | 2471 | |
@@ -2484,85 +2484,85 @@ discard block |
||
2484 | 2484 | 'profile_id' => '', |
2485 | 2485 | ); |
2486 | 2486 | |
2487 | - $args = wp_parse_args( $data, $defaults ); |
|
2487 | + $args = wp_parse_args($data, $defaults); |
|
2488 | 2488 | |
2489 | - if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
2490 | - if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) { |
|
2489 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
2490 | + if ('active' == $args['status'] || $args['status'] == 'trialing') { |
|
2491 | 2491 | $args['status'] = 'expired'; |
2492 | 2492 | } |
2493 | 2493 | } |
2494 | 2494 | |
2495 | - do_action( 'wpinv_subscription_pre_create', $args, $data, $this ); |
|
2495 | + do_action('wpinv_subscription_pre_create', $args, $data, $this); |
|
2496 | 2496 | |
2497 | - if ( !empty( $args ) ) { |
|
2498 | - foreach ( $args as $key => $value ) { |
|
2499 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
2497 | + if (!empty($args)) { |
|
2498 | + foreach ($args as $key => $value) { |
|
2499 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
2500 | 2500 | } |
2501 | 2501 | } |
2502 | 2502 | |
2503 | - do_action( 'wpinv_subscription_post_create', $args, $data, $this ); |
|
2503 | + do_action('wpinv_subscription_post_create', $args, $data, $this); |
|
2504 | 2504 | |
2505 | 2505 | return true; |
2506 | 2506 | } |
2507 | 2507 | |
2508 | - public function update_subscription( $args = array() ) { |
|
2509 | - if ( empty( $this->ID ) ) { |
|
2508 | + public function update_subscription($args = array()) { |
|
2509 | + if (empty($this->ID)) { |
|
2510 | 2510 | return false; |
2511 | 2511 | } |
2512 | 2512 | |
2513 | - if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
2514 | - if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) { |
|
2513 | + if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
2514 | + if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) { |
|
2515 | 2515 | $args['status'] = 'expired'; |
2516 | 2516 | } |
2517 | 2517 | } |
2518 | 2518 | |
2519 | - if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) { |
|
2520 | - $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ); |
|
2519 | + if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) { |
|
2520 | + $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp')); |
|
2521 | 2521 | } |
2522 | 2522 | |
2523 | - do_action( 'wpinv_subscription_pre_update', $args, $this ); |
|
2523 | + do_action('wpinv_subscription_pre_update', $args, $this); |
|
2524 | 2524 | |
2525 | - if ( !empty( $args ) ) { |
|
2526 | - foreach ( $args as $key => $value ) { |
|
2527 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
2525 | + if (!empty($args)) { |
|
2526 | + foreach ($args as $key => $value) { |
|
2527 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
2528 | 2528 | } |
2529 | 2529 | } |
2530 | 2530 | |
2531 | - do_action( 'wpinv_subscription_post_update', $args, $this ); |
|
2531 | + do_action('wpinv_subscription_post_update', $args, $this); |
|
2532 | 2532 | |
2533 | 2533 | return true; |
2534 | 2534 | } |
2535 | 2535 | |
2536 | 2536 | public function renew_subscription() { |
2537 | 2537 | $parent_invoice = $this->get_parent_payment(); |
2538 | - $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice; |
|
2538 | + $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice; |
|
2539 | 2539 | |
2540 | - $current_time = current_time( 'timestamp' ); |
|
2540 | + $current_time = current_time('timestamp'); |
|
2541 | 2541 | $start = $this->get_subscription_created(); |
2542 | - $start = $start ? strtotime( $start ) : $current_time; |
|
2542 | + $start = $start ? strtotime($start) : $current_time; |
|
2543 | 2543 | $expires = $this->get_expiration_time(); |
2544 | 2544 | |
2545 | - if ( !$expires ) { |
|
2546 | - $expires = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start ); |
|
2545 | + if (!$expires) { |
|
2546 | + $expires = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start); |
|
2547 | 2547 | } |
2548 | 2548 | |
2549 | - $expiration = date_i18n( 'Y-m-d 23:59:59', $expires ); |
|
2550 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this ); |
|
2549 | + $expiration = date_i18n('Y-m-d 23:59:59', $expires); |
|
2550 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this); |
|
2551 | 2551 | $bill_times = $parent_invoice->get_bill_times(); |
2552 | 2552 | $times_billed = $parent_invoice->get_total_payments(); |
2553 | 2553 | |
2554 | - if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) { |
|
2554 | + if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) { |
|
2555 | 2555 | $args = array( |
2556 | 2556 | 'status' => 'active', |
2557 | 2557 | ); |
2558 | 2558 | |
2559 | - $parent_invoice->update_subscription( $args ); |
|
2559 | + $parent_invoice->update_subscription($args); |
|
2560 | 2560 | } |
2561 | 2561 | |
2562 | - do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this ); |
|
2562 | + do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this); |
|
2563 | 2563 | |
2564 | - $status = 'active'; |
|
2565 | - if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
2564 | + $status = 'active'; |
|
2565 | + if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
2566 | 2566 | $this->complete_subscription(); |
2567 | 2567 | $status = 'completed'; |
2568 | 2568 | } |
@@ -2572,10 +2572,10 @@ discard block |
||
2572 | 2572 | 'status' => $status, |
2573 | 2573 | ); |
2574 | 2574 | |
2575 | - $this->update_subscription( $args ); |
|
2575 | + $this->update_subscription($args); |
|
2576 | 2576 | |
2577 | - do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this ); |
|
2578 | - do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this ); |
|
2577 | + do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this); |
|
2578 | + do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this); |
|
2579 | 2579 | } |
2580 | 2580 | |
2581 | 2581 | public function complete_subscription() { |
@@ -2583,8 +2583,8 @@ discard block |
||
2583 | 2583 | 'status' => 'completed' |
2584 | 2584 | ); |
2585 | 2585 | |
2586 | - if ( $this->update_subscription( $args ) ) { |
|
2587 | - do_action( 'wpinv_subscription_completed', $this->ID, $this ); |
|
2586 | + if ($this->update_subscription($args)) { |
|
2587 | + do_action('wpinv_subscription_completed', $this->ID, $this); |
|
2588 | 2588 | } |
2589 | 2589 | } |
2590 | 2590 | |
@@ -2593,44 +2593,44 @@ discard block |
||
2593 | 2593 | 'status' => 'expired' |
2594 | 2594 | ); |
2595 | 2595 | |
2596 | - if ( $this->update_subscription( $args ) ) { |
|
2597 | - do_action( 'wpinv_subscription_expired', $this->ID, $this ); |
|
2596 | + if ($this->update_subscription($args)) { |
|
2597 | + do_action('wpinv_subscription_expired', $this->ID, $this); |
|
2598 | 2598 | } |
2599 | 2599 | } |
2600 | 2600 | |
2601 | 2601 | public function get_cancel_url() { |
2602 | - $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' ); |
|
2602 | + $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel'); |
|
2603 | 2603 | |
2604 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
2604 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
2605 | 2605 | } |
2606 | 2606 | |
2607 | 2607 | public function can_update() { |
2608 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
2608 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
2609 | 2609 | } |
2610 | 2610 | |
2611 | 2611 | public function get_update_url() { |
2612 | - $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) ); |
|
2612 | + $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID)); |
|
2613 | 2613 | |
2614 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
2614 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
2615 | 2615 | } |
2616 | 2616 | |
2617 | 2617 | public function is_parent() { |
2618 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
2618 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
2619 | 2619 | |
2620 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
2620 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
2621 | 2621 | } |
2622 | 2622 | |
2623 | 2623 | public function is_renewal() { |
2624 | 2624 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
2625 | 2625 | |
2626 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
2626 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
2627 | 2627 | } |
2628 | 2628 | |
2629 | 2629 | public function get_parent_payment() { |
2630 | 2630 | $parent_payment = NULL; |
2631 | 2631 | |
2632 | - if ( $this->is_renewal() ) { |
|
2633 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
2632 | + if ($this->is_renewal()) { |
|
2633 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
2634 | 2634 | } |
2635 | 2635 | |
2636 | 2636 | return $parent_payment; |
@@ -2641,100 +2641,100 @@ discard block |
||
2641 | 2641 | |
2642 | 2642 | $subscription_status = $this->get_subscription_status(); |
2643 | 2643 | |
2644 | - if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) { |
|
2644 | + if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) { |
|
2645 | 2645 | $ret = true; |
2646 | 2646 | } |
2647 | 2647 | |
2648 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this ); |
|
2648 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this); |
|
2649 | 2649 | } |
2650 | 2650 | |
2651 | 2651 | public function is_subscription_expired() { |
2652 | 2652 | $ret = false; |
2653 | 2653 | $subscription_status = $this->get_subscription_status(); |
2654 | 2654 | |
2655 | - if ( $subscription_status == 'expired' ) { |
|
2655 | + if ($subscription_status == 'expired') { |
|
2656 | 2656 | $ret = true; |
2657 | - } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) { |
|
2657 | + } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) { |
|
2658 | 2658 | $ret = false; |
2659 | 2659 | $expiration = $this->get_expiration_time(); |
2660 | 2660 | |
2661 | - if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
2661 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
2662 | 2662 | $ret = true; |
2663 | 2663 | |
2664 | - if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) { |
|
2664 | + if ('active' === $subscription_status || 'trialing' === $subscription_status) { |
|
2665 | 2665 | $this->expire_subscription(); |
2666 | 2666 | } |
2667 | 2667 | } |
2668 | 2668 | } |
2669 | 2669 | |
2670 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this ); |
|
2670 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this); |
|
2671 | 2671 | } |
2672 | 2672 | |
2673 | - public function get_new_expiration( $item_id = 0, $trial = true ) { |
|
2674 | - $item = new WPInv_Item( $item_id ); |
|
2673 | + public function get_new_expiration($item_id = 0, $trial = true) { |
|
2674 | + $item = new WPInv_Item($item_id); |
|
2675 | 2675 | $interval = $item->get_recurring_interval(); |
2676 | - $period = $item->get_recurring_period( true ); |
|
2676 | + $period = $item->get_recurring_period(true); |
|
2677 | 2677 | |
2678 | - $expiration_time = strtotime( '+' . $interval . ' ' . $period ); |
|
2678 | + $expiration_time = strtotime('+' . $interval . ' ' . $period); |
|
2679 | 2679 | |
2680 | - if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) { |
|
2681 | - $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2680 | + if ($trial && $this->is_free_trial() && $item->has_free_trial()) { |
|
2681 | + $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS); |
|
2682 | 2682 | } |
2683 | 2683 | |
2684 | - return date_i18n( 'Y-m-d 23:59:59', $expiration_time ); |
|
2684 | + return date_i18n('Y-m-d 23:59:59', $expiration_time); |
|
2685 | 2685 | } |
2686 | 2686 | |
2687 | - public function get_subscription_data( $filed = '' ) { |
|
2688 | - $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' ); |
|
2687 | + public function get_subscription_data($filed = '') { |
|
2688 | + $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on'); |
|
2689 | 2689 | |
2690 | 2690 | $subscription_meta = array(); |
2691 | - foreach ( $fields as $field ) { |
|
2692 | - $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field ); |
|
2691 | + foreach ($fields as $field) { |
|
2692 | + $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field); |
|
2693 | 2693 | } |
2694 | 2694 | |
2695 | - $item = $this->get_recurring( true ); |
|
2695 | + $item = $this->get_recurring(true); |
|
2696 | 2696 | |
2697 | - if ( !empty( $item ) ) { |
|
2698 | - if ( empty( $subscription_meta['item_id'] ) ) { |
|
2697 | + if (!empty($item)) { |
|
2698 | + if (empty($subscription_meta['item_id'])) { |
|
2699 | 2699 | $subscription_meta['item_id'] = $item->ID; |
2700 | 2700 | } |
2701 | - if ( empty( $subscription_meta['period'] ) ) { |
|
2701 | + if (empty($subscription_meta['period'])) { |
|
2702 | 2702 | $subscription_meta['period'] = $item->get_recurring_period(); |
2703 | 2703 | } |
2704 | - if ( empty( $subscription_meta['interval'] ) ) { |
|
2704 | + if (empty($subscription_meta['interval'])) { |
|
2705 | 2705 | $subscription_meta['interval'] = $item->get_recurring_interval(); |
2706 | 2706 | } |
2707 | - if ( $item->has_free_trial() ) { |
|
2708 | - if ( empty( $subscription_meta['trial_period'] ) ) { |
|
2707 | + if ($item->has_free_trial()) { |
|
2708 | + if (empty($subscription_meta['trial_period'])) { |
|
2709 | 2709 | $subscription_meta['trial_period'] = $item->get_trial_period(); |
2710 | 2710 | } |
2711 | - if ( empty( $subscription_meta['trial_interval'] ) ) { |
|
2711 | + if (empty($subscription_meta['trial_interval'])) { |
|
2712 | 2712 | $subscription_meta['trial_interval'] = $item->get_trial_interval(); |
2713 | 2713 | } |
2714 | 2714 | } else { |
2715 | 2715 | $subscription_meta['trial_period'] = ''; |
2716 | 2716 | $subscription_meta['trial_interval'] = 0; |
2717 | 2717 | } |
2718 | - if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) { |
|
2718 | + if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) { |
|
2719 | 2719 | $subscription_meta['bill_times'] = $item->get_recurring_limit(); |
2720 | 2720 | } |
2721 | - if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) { |
|
2722 | - $subscription_meta['initial_amount'] = wpinv_format_amount( $this->get_total() ); |
|
2723 | - $subscription_meta['recurring_amount'] = wpinv_format_amount( $this->get_recurring_details( 'total' ) ); |
|
2721 | + if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') { |
|
2722 | + $subscription_meta['initial_amount'] = wpinv_format_amount($this->get_total()); |
|
2723 | + $subscription_meta['recurring_amount'] = wpinv_format_amount($this->get_recurring_details('total')); |
|
2724 | 2724 | } |
2725 | 2725 | } |
2726 | 2726 | |
2727 | - if ( $filed === '' ) { |
|
2728 | - return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this ); |
|
2727 | + if ($filed === '') { |
|
2728 | + return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this); |
|
2729 | 2729 | } |
2730 | 2730 | |
2731 | - $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : ''; |
|
2731 | + $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : ''; |
|
2732 | 2732 | |
2733 | - return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this ); |
|
2733 | + return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this); |
|
2734 | 2734 | } |
2735 | 2735 | |
2736 | 2736 | public function is_paid() { |
2737 | - if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
2737 | + if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
2738 | 2738 | return true; |
2739 | 2739 | } |
2740 | 2740 | |
@@ -2746,28 +2746,28 @@ discard block |
||
2746 | 2746 | |
2747 | 2747 | $requires_vat = false; |
2748 | 2748 | |
2749 | - if ( $this->country ) { |
|
2749 | + if ($this->country) { |
|
2750 | 2750 | $wpi_country = $this->country; |
2751 | 2751 | |
2752 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2752 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2753 | 2753 | } |
2754 | 2754 | |
2755 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2755 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2756 | 2756 | } |
2757 | 2757 | |
2758 | 2758 | public function refresh_item_ids() { |
2759 | 2759 | $item_ids = array(); |
2760 | 2760 | |
2761 | - if ( !empty( $this->cart_details ) ) { |
|
2762 | - foreach ( $this->cart_details as $key => $item ) { |
|
2763 | - if ( !empty( $item['id'] ) ) { |
|
2761 | + if (!empty($this->cart_details)) { |
|
2762 | + foreach ($this->cart_details as $key => $item) { |
|
2763 | + if (!empty($item['id'])) { |
|
2764 | 2764 | $item_ids[] = $item['id']; |
2765 | 2765 | } |
2766 | 2766 | } |
2767 | 2767 | } |
2768 | 2768 | |
2769 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2769 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2770 | 2770 | |
2771 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2771 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2772 | 2772 | } |
2773 | 2773 | } |
@@ -1,121 +1,121 @@ discard block |
||
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 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish' ), |
|
149 | + 'post_status' => array('publish'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,60 +255,60 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
266 | 266 | ); |
267 | 267 | |
268 | - if ( $return ) { |
|
268 | + if ($return) { |
|
269 | 269 | return $response; |
270 | 270 | } |
271 | 271 | |
272 | - wp_send_json( $response ); |
|
272 | + wp_send_json($response); |
|
273 | 273 | } |
274 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
274 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
275 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | 276 | |
277 | 277 | // VAT Settings |
278 | -function wpinv_vat_rate_add_callback( $args ) { |
|
278 | +function wpinv_vat_rate_add_callback($args) { |
|
279 | 279 | ?> |
280 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
280 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | 281 | <?php |
282 | 282 | } |
283 | 283 | |
284 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
284 | +function wpinv_vat_rate_delete_callback($args) { |
|
285 | 285 | global $wpinv_euvat; |
286 | 286 | |
287 | 287 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
288 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
289 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
288 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
289 | + if (isset($vat_classes[$vat_class])) { |
|
290 | 290 | ?> |
291 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
291 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | 292 | <?php |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | -function wpinv_vat_rates_callback( $args ) { |
|
296 | +function wpinv_vat_rates_callback($args) { |
|
297 | 297 | global $wpinv_euvat; |
298 | 298 | |
299 | 299 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
300 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
300 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
301 | 301 | |
302 | 302 | $eu_states = $wpinv_euvat->get_eu_states(); |
303 | 303 | $countries = wpinv_get_country_list(); |
304 | 304 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
305 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
305 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
306 | 306 | ob_start(); |
307 | 307 | ?> |
308 | 308 | </td><tr> |
309 | 309 | <td colspan="2" class="wpinv_vat_tdbox"> |
310 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
311 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
310 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
311 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
312 | 312 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
313 | 313 | <colgroup> |
314 | 314 | <col width="50px" /> |
@@ -320,43 +320,43 @@ discard block |
||
320 | 320 | </colgroup> |
321 | 321 | <thead> |
322 | 322 | <tr> |
323 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
324 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
323 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
324 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
328 | 328 | </tr> |
329 | 329 | </thead> |
330 | 330 | <tbody> |
331 | - <?php if( !empty( $eu_states ) ) { ?> |
|
331 | + <?php if (!empty($eu_states)) { ?> |
|
332 | 332 | <?php |
333 | - foreach ( $eu_states as $state ) { |
|
334 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
333 | + foreach ($eu_states as $state) { |
|
334 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
335 | 335 | |
336 | 336 | // Filter the rate for each country |
337 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
337 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
338 | 338 | |
339 | 339 | // If one does not exist create a default |
340 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
340 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
341 | 341 | |
342 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
343 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
344 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
345 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
342 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
343 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
344 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
345 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
346 | 346 | ?> |
347 | 347 | <tr> |
348 | 348 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
349 | 349 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
350 | 350 | <td class="wpinv_vat_global"> |
351 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
352 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
353 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
351 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
352 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
353 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
354 | 354 | </td> |
355 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
355 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
357 | 357 | <td class="wpinv_vat_group"> |
358 | 358 | <?php |
359 | - echo wpinv_html_select( array( |
|
359 | + echo wpinv_html_select(array( |
|
360 | 360 | 'name' => 'vat_rates[' . $state . '][group]', |
361 | 361 | 'selected' => $vat_group, |
362 | 362 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'chosen' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
413 | + $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | )); |
464 | 464 | |
465 | 465 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
466 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
466 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
467 | 467 | $desc .= '<p>'; |
468 | - if ( empty( $geoip2_message ) ) { |
|
469 | - if ( $geoip2_database ) { |
|
468 | + if (empty($geoip2_message)) { |
|
469 | + if ($geoip2_database) { |
|
470 | 470 | $last_updated = ''; |
471 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
472 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
473 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
471 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
472 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
473 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
474 | 474 | } |
475 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
475 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
476 | 476 | } else { |
477 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
477 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
478 | 478 | } |
479 | 479 | } else { |
480 | 480 | $desc .= $geoip2_message; |
481 | 481 | } |
482 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
482 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
483 | 483 | $desc .= '</label>'; |
484 | 484 | |
485 | 485 | $html .= $desc; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,49 +55,49 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | 77 | //$invoice->set( 'status', 'publish' ); |
78 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
79 | - $invoice->set( 'key', $parent_invoice->get_key() ); |
|
78 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
79 | + $invoice->set('key', $parent_invoice->get_key()); |
|
80 | 80 | |
81 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
82 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
83 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
84 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
81 | + $invoice->set('ip', $parent_invoice->ip); |
|
82 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
83 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
84 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
85 | 85 | ///$invoice->set( 'email', $parent_invoice->get_email() ); |
86 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
87 | - $invoice->set( 'address', $parent_invoice->address ); |
|
88 | - $invoice->set( 'city', $parent_invoice->city ); |
|
89 | - $invoice->set( 'country', $parent_invoice->country ); |
|
90 | - $invoice->set( 'state', $parent_invoice->state ); |
|
91 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
92 | - $invoice->set( 'company', $parent_invoice->company ); |
|
93 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
94 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
95 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
96 | - |
|
97 | - if ( empty( $args['gateway'] ) ) { |
|
98 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
86 | + $invoice->set('phone', $parent_invoice->phone); |
|
87 | + $invoice->set('address', $parent_invoice->address); |
|
88 | + $invoice->set('city', $parent_invoice->city); |
|
89 | + $invoice->set('country', $parent_invoice->country); |
|
90 | + $invoice->set('state', $parent_invoice->state); |
|
91 | + $invoice->set('zip', $parent_invoice->zip); |
|
92 | + $invoice->set('company', $parent_invoice->company); |
|
93 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
94 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
95 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
96 | + |
|
97 | + if (empty($args['gateway'])) { |
|
98 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
99 | 99 | } else { |
100 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
100 | + $invoice->set('gateway', $args['gateway']); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | // increase the earnings for each item in the subscription |
106 | 106 | $items = $recurring_details['cart_details']; |
107 | 107 | |
108 | - if ( $items ) { |
|
108 | + if ($items) { |
|
109 | 109 | $add_items = array(); |
110 | 110 | $cart_details = array(); |
111 | 111 | |
112 | - foreach ( $items as $item ) { |
|
112 | + foreach ($items as $item) { |
|
113 | 113 | $add_item = array(); |
114 | 114 | $add_item['id'] = $item['id']; |
115 | 115 | $add_item['quantity'] = $item['quantity']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - $invoice->set( 'items', $add_items ); |
|
122 | + $invoice->set('items', $add_items); |
|
123 | 123 | $invoice->cart_details = $cart_details; |
124 | 124 | } |
125 | 125 | |
@@ -129,277 +129,277 @@ discard block |
||
129 | 129 | $tax = $recurring_details['tax']; |
130 | 130 | $discount = $recurring_details['discount']; |
131 | 131 | |
132 | - if ( $discount > 0 ) { |
|
133 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
132 | + if ($discount > 0) { |
|
133 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
134 | 134 | } |
135 | 135 | |
136 | - $invoice->subtotal = wpinv_format_amount( $subtotal, NULL, true ); |
|
137 | - $invoice->tax = wpinv_format_amount( $tax, NULL, true ); |
|
138 | - $invoice->discount = wpinv_format_amount( $discount, NULL, true ); |
|
139 | - $invoice->total = wpinv_format_amount( $total, NULL, true ); |
|
136 | + $invoice->subtotal = wpinv_format_amount($subtotal, NULL, true); |
|
137 | + $invoice->tax = wpinv_format_amount($tax, NULL, true); |
|
138 | + $invoice->discount = wpinv_format_amount($discount, NULL, true); |
|
139 | + $invoice->total = wpinv_format_amount($total, NULL, true); |
|
140 | 140 | $invoice->save(); |
141 | 141 | |
142 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
142 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
143 | 143 | sleep(1); |
144 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
144 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
145 | 145 | |
146 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
146 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
147 | 147 | |
148 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
148 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
149 | 149 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
150 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
151 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
150 | + $subscription_data['created'] = current_time('mysql', 0); |
|
151 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
152 | 152 | |
153 | 153 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
154 | - $invoice->update_subscription( $subscription_data ); |
|
154 | + $invoice->update_subscription($subscription_data); |
|
155 | 155 | |
156 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
157 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
156 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
157 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
158 | 158 | |
159 | 159 | return $invoice; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
162 | +function wpinv_payment_exists($txn_id = '') { |
|
163 | 163 | global $wpdb; |
164 | 164 | |
165 | - if ( empty( $txn_id ) ) { |
|
165 | + if (empty($txn_id)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | - $txn_id = esc_sql( $txn_id ); |
|
169 | + $txn_id = esc_sql($txn_id); |
|
170 | 170 | |
171 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
171 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
172 | 172 | |
173 | - if ( $invoice != null ) { |
|
173 | + if ($invoice != null) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
181 | - if ( empty( $invoice ) ) { |
|
180 | +function wpinv_is_subscription_payment($invoice = '') { |
|
181 | + if (empty($invoice)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
186 | - $invoice = wpinv_get_invoice( $invoice ); |
|
185 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
186 | + $invoice = wpinv_get_invoice($invoice); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( empty( $invoice ) ) { |
|
189 | + if (empty($invoice)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( $invoice->is_renewal() ) { |
|
193 | + if ($invoice->is_renewal()) { |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
201 | - if ( empty( $invoice ) ) { |
|
200 | +function wpinv_payment_subscription_data($invoice = '') { |
|
201 | + if (empty($invoice)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $invoice ); |
|
205 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
206 | + $invoice = wpinv_get_invoice($invoice); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( empty( $invoice ) ) { |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $invoice->get_subscription_data(); |
214 | 214 | } |
215 | 215 | |
216 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
217 | - if ( empty( $invoice ) ) { |
|
216 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
217 | + if (empty($invoice)) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
222 | - $invoice = wpinv_get_invoice( $invoice ); |
|
221 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
222 | + $invoice = wpinv_get_invoice($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( empty( $invoice ) ) { |
|
225 | + if (empty($invoice)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
229 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
232 | +function wpinv_get_pretty_subscription_period($period) { |
|
233 | 233 | $frequency = ''; |
234 | 234 | //Format period details |
235 | - switch ( $period ) { |
|
235 | + switch ($period) { |
|
236 | 236 | case 'D' : |
237 | 237 | case 'day' : |
238 | - $frequency = __( 'Daily', 'invoicing' ); |
|
238 | + $frequency = __('Daily', 'invoicing'); |
|
239 | 239 | break; |
240 | 240 | case 'W' : |
241 | 241 | case 'week' : |
242 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
242 | + $frequency = __('Weekly', 'invoicing'); |
|
243 | 243 | break; |
244 | 244 | case 'M' : |
245 | 245 | case 'month' : |
246 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
246 | + $frequency = __('Monthly', 'invoicing'); |
|
247 | 247 | break; |
248 | 248 | case 'Y' : |
249 | 249 | case 'year' : |
250 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
250 | + $frequency = __('Yearly', 'invoicing'); |
|
251 | 251 | break; |
252 | 252 | default : |
253 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
253 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
254 | 254 | break; |
255 | 255 | } |
256 | 256 | |
257 | 257 | return $frequency; |
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
260 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
261 | 261 | $frequency = ''; |
262 | 262 | //Format period details |
263 | - switch ( $period ) { |
|
263 | + switch ($period) { |
|
264 | 264 | case 'D' : |
265 | 265 | case 'day' : |
266 | - $frequency = __( 'Day', 'invoicing' ); |
|
266 | + $frequency = __('Day', 'invoicing'); |
|
267 | 267 | break; |
268 | 268 | case 'W' : |
269 | 269 | case 'week' : |
270 | - $frequency = __( 'Week', 'invoicing' ); |
|
270 | + $frequency = __('Week', 'invoicing'); |
|
271 | 271 | break; |
272 | 272 | case 'M' : |
273 | 273 | case 'month' : |
274 | - $frequency = __( 'Month', 'invoicing' ); |
|
274 | + $frequency = __('Month', 'invoicing'); |
|
275 | 275 | break; |
276 | 276 | case 'Y' : |
277 | 277 | case 'year' : |
278 | - $frequency = __( 'Year', 'invoicing' ); |
|
278 | + $frequency = __('Year', 'invoicing'); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
281 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
282 | 282 | break; |
283 | 283 | } |
284 | 284 | |
285 | 285 | return $frequency; |
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
288 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
289 | 289 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
290 | 290 | |
291 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
292 | - $amount = __( 'Free', 'invoicing' ); |
|
291 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
292 | + $amount = __('Free', 'invoicing'); |
|
293 | 293 | $interval = $trial_interval; |
294 | 294 | $period = $trial_period; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $description = ''; |
298 | - switch ( $period ) { |
|
298 | + switch ($period) { |
|
299 | 299 | case 'D' : |
300 | 300 | case 'day' : |
301 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
301 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
302 | 302 | break; |
303 | 303 | case 'W' : |
304 | 304 | case 'week' : |
305 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
305 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
306 | 306 | break; |
307 | 307 | case 'M' : |
308 | 308 | case 'month' : |
309 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
309 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
310 | 310 | break; |
311 | 311 | case 'Y' : |
312 | 312 | case 'year' : |
313 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
313 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
314 | 314 | break; |
315 | 315 | } |
316 | 316 | |
317 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
317 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
320 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
321 | 321 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
322 | 322 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
323 | 323 | |
324 | 324 | $description = ''; |
325 | - switch ( $period ) { |
|
325 | + switch ($period) { |
|
326 | 326 | case 'D' : |
327 | 327 | case 'day' : |
328 | - if ( (int)$bill_times > 0 ) { |
|
329 | - if ( $interval > 1 ) { |
|
330 | - if ( $bill_times > 1 ) { |
|
331 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
328 | + if ((int)$bill_times > 0) { |
|
329 | + if ($interval > 1) { |
|
330 | + if ($bill_times > 1) { |
|
331 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
332 | 332 | } else { |
333 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
333 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
336 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
339 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'W' : |
343 | 343 | case 'week' : |
344 | - if ( (int)$bill_times > 0 ) { |
|
345 | - if ( $interval > 1 ) { |
|
346 | - if ( $bill_times > 1 ) { |
|
347 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
344 | + if ((int)$bill_times > 0) { |
|
345 | + if ($interval > 1) { |
|
346 | + if ($bill_times > 1) { |
|
347 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
348 | 348 | } else { |
349 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
349 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
352 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
355 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
356 | 356 | } |
357 | 357 | break; |
358 | 358 | case 'M' : |
359 | 359 | case 'month' : |
360 | - if ( (int)$bill_times > 0 ) { |
|
361 | - if ( $interval > 1 ) { |
|
362 | - if ( $bill_times > 1 ) { |
|
363 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
360 | + if ((int)$bill_times > 0) { |
|
361 | + if ($interval > 1) { |
|
362 | + if ($bill_times > 1) { |
|
363 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
364 | 364 | } else { |
365 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
365 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
368 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
371 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
372 | 372 | } |
373 | 373 | break; |
374 | 374 | case 'Y' : |
375 | 375 | case 'year' : |
376 | - if ( (int)$bill_times > 0 ) { |
|
377 | - if ( $interval > 1 ) { |
|
378 | - if ( $bill_times > 1 ) { |
|
379 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
376 | + if ((int)$bill_times > 0) { |
|
377 | + if ($interval > 1) { |
|
378 | + if ($bill_times > 1) { |
|
379 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
380 | 380 | } else { |
381 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
381 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
384 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
385 | 385 | } |
386 | 386 | } else { |
387 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
387 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
388 | 388 | } |
389 | 389 | break; |
390 | 390 | } |
391 | 391 | |
392 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
392 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
393 | 393 | } |
394 | 394 | |
395 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
396 | - if ( empty( $invoice ) ) { |
|
395 | +function wpinv_subscription_payment_desc($invoice) { |
|
396 | + if (empty($invoice)) { |
|
397 | 397 | return NULL; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $description = ''; |
401 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
402 | - if ( $item->has_free_trial() ) { |
|
401 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
402 | + if ($item->has_free_trial()) { |
|
403 | 403 | $trial_period = $item->get_trial_period(); |
404 | 404 | $trial_interval = $item->get_trial_interval(); |
405 | 405 | } else { |
@@ -407,45 +407,45 @@ discard block |
||
407 | 407 | $trial_interval = 0; |
408 | 408 | } |
409 | 409 | |
410 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
410 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
411 | 411 | } |
412 | 412 | |
413 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
413 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
417 | - $initial_total = wpinv_format_amount( $initial ); |
|
418 | - $recurring_total = wpinv_format_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_format_amount($initial); |
|
418 | + $recurring_total = wpinv_format_amount($recurring); |
|
419 | 419 | |
420 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
420 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
421 | 421 | // Free trial |
422 | 422 | } else { |
423 | - if ( $bill_times == 1 ) { |
|
423 | + if ($bill_times == 1) { |
|
424 | 424 | $recurring_total = $initial_total; |
425 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
425 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
426 | 426 | $bill_times--; |
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
431 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
430 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
431 | + $recurring_amount = wpinv_price($recurring_total, $currency); |
|
432 | 432 | |
433 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
433 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - if ( $initial_total != $recurring_total ) { |
|
436 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
435 | + if ($initial_total != $recurring_total) { |
|
436 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
437 | 437 | |
438 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
438 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
439 | 439 | } else { |
440 | 440 | $description = $recurring; |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
443 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
447 | - if ( !empty( $invoice->ID ) ) { |
|
448 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
446 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
447 | + if (!empty($invoice->ID)) { |
|
448 | + wpinv_failed_invoice_notification($invoice->ID); |
|
449 | 449 | } |
450 | 450 | } |
451 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
452 | 451 | \ No newline at end of file |
452 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
453 | 453 | \ No newline at end of file |
@@ -7,90 +7,90 @@ discard block |
||
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_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!current_user_can('manage_options')) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!current_user_can('manage_options')) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!current_user_can('manage_options')) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = 'gd_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $discounts = wpinv_get_discounts(); |
104 | 104 | |
105 | - if ( $discounts) { |
|
106 | - foreach ( $discounts as $discount ) { |
|
107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
105 | + if ($discounts) { |
|
106 | + foreach ($discounts as $discount) { |
|
107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
108 | 108 | $has_active = true; |
109 | 109 | break; |
110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | return $has_active; |
114 | 114 | } |
115 | 115 | |
116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
117 | - if( empty( $discount_id ) ) { |
|
116 | +function wpinv_get_discount($discount_id = 0) { |
|
117 | + if (empty($discount_id)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | - $discount = get_post( $discount_id ); |
|
125 | + $discount = get_post($discount_id); |
|
126 | 126 | |
127 | 127 | return $discount; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
130 | +function wpinv_get_discount_by_code($code = '') { |
|
131 | + if (empty($code) || !is_string($code)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return wpinv_get_discount_by( 'code', $code ); |
|
135 | + return wpinv_get_discount_by('code', $code); |
|
136 | 136 | } |
137 | 137 | |
138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
139 | - if( empty( $field ) || empty( $value ) ) { |
|
138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
139 | + if (empty($field) || empty($value)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if( ! is_string( $field ) ) { |
|
143 | + if (!is_string($field)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - switch( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | |
149 | 149 | case 'code': |
150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | 'compare' => '=' |
155 | 155 | ); |
156 | 156 | |
157 | - $discount = wpinv_get_discounts( array( |
|
157 | + $discount = wpinv_get_discounts(array( |
|
158 | 158 | 'posts_per_page' => 1, |
159 | 159 | 'post_status' => 'any', |
160 | 160 | 'meta_query' => $meta_query, |
161 | - ) ); |
|
161 | + )); |
|
162 | 162 | |
163 | - if( $discount ) { |
|
163 | + if ($discount) { |
|
164 | 164 | $discount = $discount[0]; |
165 | 165 | } |
166 | 166 | |
167 | 167 | break; |
168 | 168 | |
169 | 169 | case 'id': |
170 | - $discount = wpinv_get_discount( $value ); |
|
170 | + $discount = wpinv_get_discount($value); |
|
171 | 171 | |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'name': |
175 | - $discount = get_posts( array( |
|
175 | + $discount = get_posts(array( |
|
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'name' => $value, |
178 | 178 | 'posts_per_page' => 1, |
179 | 179 | 'post_status' => 'any' |
180 | - ) ); |
|
180 | + )); |
|
181 | 181 | |
182 | - if( $discount ) { |
|
182 | + if ($discount) { |
|
183 | 183 | $discount = $discount[0]; |
184 | 184 | } |
185 | 185 | |
@@ -189,99 +189,99 @@ discard block |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - if( ! empty( $discount ) ) { |
|
192 | + if (!empty($discount)) { |
|
193 | 193 | return $discount; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
200 | 200 | $meta = array( |
201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
214 | 214 | ); |
215 | 215 | |
216 | - $start_timestamp = strtotime( $meta['start'] ); |
|
216 | + $start_timestamp = strtotime($meta['start']); |
|
217 | 217 | |
218 | - if ( !empty( $meta['start'] ) ) { |
|
219 | - $meta['start'] = date( 'Y-m-d H:i:s', $start_timestamp ); |
|
218 | + if (!empty($meta['start'])) { |
|
219 | + $meta['start'] = date('Y-m-d H:i:s', $start_timestamp); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
222 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
223 | 223 | $meta['amount'] = 100; |
224 | 224 | } |
225 | 225 | |
226 | - if ( !empty( $meta['expiration'] ) ) { |
|
227 | - $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) ); |
|
228 | - $end_timestamp = strtotime( $meta['expiration'] ); |
|
226 | + if (!empty($meta['expiration'])) { |
|
227 | + $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59')); |
|
228 | + $end_timestamp = strtotime($meta['expiration']); |
|
229 | 229 | |
230 | - if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) { |
|
230 | + if (!empty($meta['start']) && $start_timestamp > $end_timestamp) { |
|
231 | 231 | $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date. |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if ( $meta['uses'] === false ) { |
|
236 | - unset( $meta['uses'] ); |
|
235 | + if ($meta['uses'] === false) { |
|
236 | + unset($meta['uses']); |
|
237 | 237 | } |
238 | 238 | |
239 | - if ( ! empty( $meta['items'] ) ) { |
|
240 | - foreach ( $meta['items'] as $key => $item ) { |
|
241 | - if ( 0 === intval( $item ) ) { |
|
242 | - unset( $meta['items'][ $key ] ); |
|
239 | + if (!empty($meta['items'])) { |
|
240 | + foreach ($meta['items'] as $key => $item) { |
|
241 | + if (0 === intval($item)) { |
|
242 | + unset($meta['items'][$key]); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
248 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
249 | - if ( 0 === intval( $item ) ) { |
|
250 | - unset( $meta['excluded_items'][ $key ] ); |
|
247 | + if (!empty($meta['excluded_items'])) { |
|
248 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
249 | + if (0 === intval($item)) { |
|
250 | + unset($meta['excluded_items'][$key]); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
255 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
256 | 256 | |
257 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
257 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
258 | 258 | |
259 | - foreach( $meta as $key => $value ) { |
|
260 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
259 | + foreach ($meta as $key => $value) { |
|
260 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
261 | 261 | } |
262 | 262 | |
263 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
263 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
264 | 264 | |
265 | 265 | return $post_id; |
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
269 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
268 | +function wpinv_remove_discount($discount_id = 0) { |
|
269 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
270 | 270 | |
271 | - wp_delete_post( $discount_id, true ); |
|
271 | + wp_delete_post($discount_id, true); |
|
272 | 272 | |
273 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
273 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
274 | 274 | } |
275 | 275 | |
276 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
277 | - $discount = wpinv_get_discount( $code_id ); |
|
276 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
277 | + $discount = wpinv_get_discount($code_id); |
|
278 | 278 | |
279 | - if ( $discount ) { |
|
280 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
279 | + if ($discount) { |
|
280 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
281 | 281 | |
282 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
282 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
283 | 283 | |
284 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
284 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
285 | 285 | |
286 | 286 | return true; |
287 | 287 | } |
@@ -289,173 +289,173 @@ discard block |
||
289 | 289 | return false; |
290 | 290 | } |
291 | 291 | |
292 | -function wpinv_discount_exists( $code_id ) { |
|
293 | - if ( wpinv_get_discount( $code_id ) ) { |
|
292 | +function wpinv_discount_exists($code_id) { |
|
293 | + if (wpinv_get_discount($code_id)) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | -function wpinv_is_discount_active( $code_id = null ) { |
|
301 | - $discount = wpinv_get_discount( $code_id ); |
|
300 | +function wpinv_is_discount_active($code_id = null) { |
|
301 | + $discount = wpinv_get_discount($code_id); |
|
302 | 302 | $return = false; |
303 | 303 | |
304 | - if ( $discount ) { |
|
305 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
306 | - if( defined( 'DOING_AJAX' ) ) { |
|
307 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
304 | + if ($discount) { |
|
305 | + if (wpinv_is_discount_expired($code_id)) { |
|
306 | + if (defined('DOING_AJAX')) { |
|
307 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
308 | 308 | } |
309 | - } elseif ( $discount->post_status == 'publish' ) { |
|
309 | + } elseif ($discount->post_status == 'publish') { |
|
310 | 310 | $return = true; |
311 | 311 | } else { |
312 | - if( defined( 'DOING_AJAX' ) ) { |
|
313 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
312 | + if (defined('DOING_AJAX')) { |
|
313 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
318 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_get_discount_code( $code_id = null ) { |
|
322 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
321 | +function wpinv_get_discount_code($code_id = null) { |
|
322 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
323 | 323 | |
324 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
324 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
325 | 325 | } |
326 | 326 | |
327 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
328 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
327 | +function wpinv_get_discount_start_date($code_id = null) { |
|
328 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
329 | 329 | |
330 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
330 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
331 | 331 | } |
332 | 332 | |
333 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
334 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
333 | +function wpinv_get_discount_expiration($code_id = null) { |
|
334 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
335 | 335 | |
336 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
336 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
337 | 337 | } |
338 | 338 | |
339 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
340 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
339 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
340 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
341 | 341 | |
342 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
342 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
343 | 343 | } |
344 | 344 | |
345 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
346 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
345 | +function wpinv_get_discount_uses($code_id = null) { |
|
346 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
347 | 347 | |
348 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
348 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
352 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
351 | +function wpinv_get_discount_min_total($code_id = null) { |
|
352 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
353 | 353 | |
354 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
354 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
355 | 355 | } |
356 | 356 | |
357 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
358 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
357 | +function wpinv_get_discount_max_total($code_id = null) { |
|
358 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
359 | 359 | |
360 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
360 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
364 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
363 | +function wpinv_get_discount_amount($code_id = null) { |
|
364 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
365 | 365 | |
366 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
366 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
367 | 367 | } |
368 | 368 | |
369 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
370 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
369 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
370 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
371 | 371 | |
372 | - if ( $name ) { |
|
373 | - $name = wpinv_get_discount_type_name( $type ); |
|
372 | + if ($name) { |
|
373 | + $name = wpinv_get_discount_type_name($type); |
|
374 | 374 | |
375 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
375 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
376 | 376 | } |
377 | 377 | |
378 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
378 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
379 | 379 | } |
380 | 380 | |
381 | -function wpinv_discount_status( $status ) { |
|
382 | - switch( $status ){ |
|
381 | +function wpinv_discount_status($status) { |
|
382 | + switch ($status) { |
|
383 | 383 | case 'expired' : |
384 | - $name = __( 'Expired', 'invoicing' ); |
|
384 | + $name = __('Expired', 'invoicing'); |
|
385 | 385 | break; |
386 | 386 | case 'publish' : |
387 | 387 | case 'active' : |
388 | - $name = __( 'Active', 'invoicing' ); |
|
388 | + $name = __('Active', 'invoicing'); |
|
389 | 389 | break; |
390 | 390 | default : |
391 | - $name = __( 'Inactive', 'invoicing' ); |
|
391 | + $name = __('Inactive', 'invoicing'); |
|
392 | 392 | break; |
393 | 393 | } |
394 | 394 | return $name; |
395 | 395 | } |
396 | 396 | |
397 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
398 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
397 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
398 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
399 | 399 | |
400 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
400 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
401 | 401 | $excluded_items = array(); |
402 | 402 | } |
403 | 403 | |
404 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
404 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
408 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
407 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
408 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
409 | 409 | |
410 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
410 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
411 | 411 | $item_reqs = array(); |
412 | 412 | } |
413 | 413 | |
414 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
414 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
415 | 415 | } |
416 | 416 | |
417 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
418 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
417 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
418 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
422 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
421 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
422 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
426 | - $discount = wpinv_get_discount( $code_id ); |
|
425 | +function wpinv_is_discount_expired($code_id = null) { |
|
426 | + $discount = wpinv_get_discount($code_id); |
|
427 | 427 | $return = false; |
428 | 428 | |
429 | - if ( $discount ) { |
|
430 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
431 | - if ( $expiration ) { |
|
432 | - $expiration = strtotime( $expiration ); |
|
433 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
429 | + if ($discount) { |
|
430 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
431 | + if ($expiration) { |
|
432 | + $expiration = strtotime($expiration); |
|
433 | + if ($expiration < current_time('timestamp')) { |
|
434 | 434 | // Discount is expired |
435 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
435 | + wpinv_update_discount_status($code_id, 'pending'); |
|
436 | 436 | $return = true; |
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
441 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_is_discount_started( $code_id = null ) { |
|
445 | - $discount = wpinv_get_discount( $code_id ); |
|
444 | +function wpinv_is_discount_started($code_id = null) { |
|
445 | + $discount = wpinv_get_discount($code_id); |
|
446 | 446 | $return = false; |
447 | 447 | |
448 | - if ( $discount ) { |
|
449 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
448 | + if ($discount) { |
|
449 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
450 | 450 | |
451 | - if ( $start_date ) { |
|
452 | - $start_date = strtotime( $start_date ); |
|
451 | + if ($start_date) { |
|
452 | + $start_date = strtotime($start_date); |
|
453 | 453 | |
454 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
454 | + if ($start_date < current_time('timestamp')) { |
|
455 | 455 | // Discount has past the start date |
456 | 456 | $return = true; |
457 | 457 | } else { |
458 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
458 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
459 | 459 | } |
460 | 460 | } else { |
461 | 461 | // No start date for this discount, so has to be true |
@@ -463,159 +463,159 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
466 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
467 | 467 | } |
468 | 468 | |
469 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
470 | - $discount = wpinv_get_discount( $code_id ); |
|
469 | +function wpinv_check_discount_dates($code_id = null) { |
|
470 | + $discount = wpinv_get_discount($code_id); |
|
471 | 471 | $return = false; |
472 | 472 | |
473 | - if ( $discount ) { |
|
474 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
473 | + if ($discount) { |
|
474 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
475 | 475 | |
476 | - if ( $start_date ) { |
|
477 | - $start_date = strtotime( $start_date ); |
|
476 | + if ($start_date) { |
|
477 | + $start_date = strtotime($start_date); |
|
478 | 478 | |
479 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
479 | + if ($start_date < current_time('timestamp')) { |
|
480 | 480 | // Discount has past the start date |
481 | 481 | $return = true; |
482 | 482 | } else { |
483 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
483 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
484 | 484 | } |
485 | 485 | } else { |
486 | 486 | // No start date for this discount, so has to be true |
487 | 487 | $return = true; |
488 | 488 | } |
489 | 489 | |
490 | - if ( $return ) { |
|
491 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
490 | + if ($return) { |
|
491 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
492 | 492 | |
493 | - if ( $expiration ) { |
|
494 | - $expiration = strtotime( $expiration ); |
|
495 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
493 | + if ($expiration) { |
|
494 | + $expiration = strtotime($expiration); |
|
495 | + if ($expiration < current_time('timestamp')) { |
|
496 | 496 | // Discount is expired |
497 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
497 | + wpinv_update_discount_status($code_id, 'pending'); |
|
498 | 498 | $return = true; |
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | } |
503 | 503 | |
504 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
504 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
508 | - $discount = wpinv_get_discount( $code_id ); |
|
507 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
508 | + $discount = wpinv_get_discount($code_id); |
|
509 | 509 | $return = false; |
510 | 510 | |
511 | - if ( $discount ) { |
|
512 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
511 | + if ($discount) { |
|
512 | + $uses = wpinv_get_discount_uses($code_id); |
|
513 | 513 | // Large number that will never be reached |
514 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
514 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
515 | 515 | // Should never be greater than, but just in case |
516 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
516 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
517 | 517 | // Discount is maxed out |
518 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
518 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
519 | 519 | $return = true; |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
523 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
524 | 524 | } |
525 | 525 | |
526 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
527 | - $discount = wpinv_get_discount( $code_id ); |
|
526 | +function wpinv_discount_is_min_met($code_id = null) { |
|
527 | + $discount = wpinv_get_discount($code_id); |
|
528 | 528 | $return = false; |
529 | 529 | |
530 | - if ( $discount ) { |
|
531 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
532 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
530 | + if ($discount) { |
|
531 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
532 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
533 | 533 | |
534 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
534 | + if (!$min > 0 || $cart_amount >= $min) { |
|
535 | 535 | // Minimum has been met |
536 | 536 | $return = true; |
537 | 537 | } else { |
538 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
538 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
542 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
542 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
543 | 543 | } |
544 | 544 | |
545 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
546 | - $discount = wpinv_get_discount( $code_id ); |
|
545 | +function wpinv_discount_is_max_met($code_id = null) { |
|
546 | + $discount = wpinv_get_discount($code_id); |
|
547 | 547 | $return = false; |
548 | 548 | |
549 | - if ( $discount ) { |
|
550 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
551 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
549 | + if ($discount) { |
|
550 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
551 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
552 | 552 | |
553 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
553 | + if (!$max > 0 || $cart_amount <= $max) { |
|
554 | 554 | // Minimum has been met |
555 | 555 | $return = true; |
556 | 556 | } else { |
557 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
557 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
561 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
562 | 562 | } |
563 | 563 | |
564 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
565 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
566 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
564 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
565 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
566 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
567 | 567 | } |
568 | 568 | |
569 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
570 | - if ( $code ) { |
|
571 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
569 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
570 | + if ($code) { |
|
571 | + $discount = wpinv_get_discount_by_code($code_id); |
|
572 | 572 | |
573 | - if ( !empty( $discount ) ) { |
|
573 | + if (!empty($discount)) { |
|
574 | 574 | $code_id = $discount->ID; |
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
578 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
578 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
579 | 579 | |
580 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
580 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
584 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
585 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
586 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
583 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
584 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
585 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
586 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
587 | 587 | $cart_items = wpinv_get_cart_contents(); |
588 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
588 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
589 | 589 | $ret = false; |
590 | 590 | |
591 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
591 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
592 | 592 | $ret = true; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // Normalize our data for item requirements, exclusions and cart data |
596 | 596 | // First absint the items, then sort, and reset the array keys |
597 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
598 | - asort( $item_reqs ); |
|
599 | - $item_reqs = array_values( $item_reqs ); |
|
597 | + $item_reqs = array_map('absint', $item_reqs); |
|
598 | + asort($item_reqs); |
|
599 | + $item_reqs = array_values($item_reqs); |
|
600 | 600 | |
601 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
602 | - asort( $excluded_ps ); |
|
603 | - $excluded_ps = array_values( $excluded_ps ); |
|
601 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
602 | + asort($excluded_ps); |
|
603 | + $excluded_ps = array_values($excluded_ps); |
|
604 | 604 | |
605 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
606 | - asort( $cart_ids ); |
|
607 | - $cart_ids = array_values( $cart_ids ); |
|
605 | + $cart_ids = array_map('absint', $cart_ids); |
|
606 | + asort($cart_ids); |
|
607 | + $cart_ids = array_values($cart_ids); |
|
608 | 608 | |
609 | 609 | // Ensure we have requirements before proceeding |
610 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
611 | - switch( $condition ) { |
|
610 | + if (!$ret && !empty($item_reqs)) { |
|
611 | + switch ($condition) { |
|
612 | 612 | case 'all' : |
613 | 613 | // Default back to true |
614 | 614 | $ret = true; |
615 | 615 | |
616 | - foreach ( $item_reqs as $item_id ) { |
|
617 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
618 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
616 | + foreach ($item_reqs as $item_id) { |
|
617 | + if (!wpinv_item_in_cart($item_id)) { |
|
618 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
619 | 619 | $ret = false; |
620 | 620 | break; |
621 | 621 | } |
@@ -624,15 +624,15 @@ discard block |
||
624 | 624 | break; |
625 | 625 | |
626 | 626 | default : // Any |
627 | - foreach ( $item_reqs as $item_id ) { |
|
628 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
627 | + foreach ($item_reqs as $item_id) { |
|
628 | + if (wpinv_item_in_cart($item_id)) { |
|
629 | 629 | $ret = true; |
630 | 630 | break; |
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
634 | - if( ! $ret ) { |
|
635 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
634 | + if (!$ret) { |
|
635 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | break; |
@@ -641,68 +641,68 @@ discard block |
||
641 | 641 | $ret = true; |
642 | 642 | } |
643 | 643 | |
644 | - if( ! empty( $excluded_ps ) ) { |
|
644 | + if (!empty($excluded_ps)) { |
|
645 | 645 | // Check that there are items other than excluded ones in the cart |
646 | - if( $cart_ids == $excluded_ps ) { |
|
647 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
646 | + if ($cart_ids == $excluded_ps) { |
|
647 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
648 | 648 | $ret = false; |
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
652 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
652 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
655 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
656 | 656 | global $wpi_checkout_id; |
657 | 657 | |
658 | 658 | $return = false; |
659 | 659 | |
660 | - if ( empty( $code_id ) ) { |
|
661 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
660 | + if (empty($code_id)) { |
|
661 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
662 | 662 | |
663 | - if( empty( $code_id ) ) { |
|
663 | + if (empty($code_id)) { |
|
664 | 664 | return false; // No discount was found |
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
668 | + if (wpinv_discount_is_single_use($code_id)) { |
|
669 | 669 | $payments = array(); |
670 | 670 | |
671 | 671 | $user_id = 0; |
672 | - if ( is_int( $user ) ) { |
|
672 | + if (is_int($user)) { |
|
673 | 673 | $user_id = $user; |
674 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
674 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
675 | 675 | $user_id = $user_data->ID; |
676 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
676 | + } else if ($user_data = get_user_by('login', $user)) { |
|
677 | 677 | $user_id = $user_data->ID; |
678 | 678 | } |
679 | 679 | |
680 | - if ( !$user_id ) { |
|
681 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
682 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching email |
|
680 | + if (!$user_id) { |
|
681 | + $query = array('user' => $user_id, 'limit' => false); |
|
682 | + $payments = wpinv_get_invoices($query); // Get all payments with matching email |
|
683 | 683 | } |
684 | 684 | |
685 | - if ( $payments ) { |
|
686 | - foreach ( $payments as $payment ) { |
|
687 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
685 | + if ($payments) { |
|
686 | + foreach ($payments as $payment) { |
|
687 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | 691 | // Don't count discount used for current invoice chekcout. |
692 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
692 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
693 | 693 | continue; |
694 | 694 | } |
695 | 695 | |
696 | - $discounts = $payment->get_discounts( true ); |
|
697 | - if ( empty( $discounts ) ) { |
|
696 | + $discounts = $payment->get_discounts(true); |
|
697 | + if (empty($discounts)) { |
|
698 | 698 | continue; |
699 | 699 | } |
700 | 700 | |
701 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
701 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
702 | 702 | |
703 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
704 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
705 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
703 | + if (!empty($discounts) && is_array($discounts)) { |
|
704 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
705 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
706 | 706 | $return = true; |
707 | 707 | break; |
708 | 708 | } |
@@ -711,61 +711,61 @@ discard block |
||
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
714 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
715 | 715 | } |
716 | 716 | |
717 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
717 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
718 | 718 | $return = false; |
719 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
720 | - $user = trim( $user ); |
|
719 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
720 | + $user = trim($user); |
|
721 | 721 | |
722 | - if ( wpinv_get_cart_contents() ) { |
|
723 | - if ( $discount_id ) { |
|
722 | + if (wpinv_get_cart_contents()) { |
|
723 | + if ($discount_id) { |
|
724 | 724 | if ( |
725 | - wpinv_is_discount_active( $discount_id ) && |
|
726 | - wpinv_check_discount_dates( $discount_id ) && |
|
727 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
728 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
729 | - wpinv_discount_is_min_met( $discount_id ) && |
|
730 | - wpinv_discount_is_max_met( $discount_id ) && |
|
731 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
725 | + wpinv_is_discount_active($discount_id) && |
|
726 | + wpinv_check_discount_dates($discount_id) && |
|
727 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
728 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
729 | + wpinv_discount_is_min_met($discount_id) && |
|
730 | + wpinv_discount_is_max_met($discount_id) && |
|
731 | + wpinv_discount_item_reqs_met($discount_id) |
|
732 | 732 | ) { |
733 | 733 | $return = true; |
734 | 734 | } |
735 | - } elseif( $set_error ) { |
|
736 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
735 | + } elseif ($set_error) { |
|
736 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
740 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
741 | 741 | } |
742 | 742 | |
743 | -function wpinv_get_discount_id_by_code( $code ) { |
|
744 | - $discount = wpinv_get_discount_by_code( $code ); |
|
745 | - if( $discount ) { |
|
743 | +function wpinv_get_discount_id_by_code($code) { |
|
744 | + $discount = wpinv_get_discount_by_code($code); |
|
745 | + if ($discount) { |
|
746 | 746 | return $discount->ID; |
747 | 747 | } |
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
751 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
751 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
752 | 752 | $amount = $base_price; |
753 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
753 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
754 | 754 | |
755 | - if( $discount_id ) { |
|
756 | - $type = wpinv_get_discount_type( $discount_id ); |
|
757 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
755 | + if ($discount_id) { |
|
756 | + $type = wpinv_get_discount_type($discount_id); |
|
757 | + $rate = wpinv_get_discount_amount($discount_id); |
|
758 | 758 | |
759 | - if ( $type == 'flat' ) { |
|
759 | + if ($type == 'flat') { |
|
760 | 760 | // Set amount |
761 | 761 | $amount = $base_price - $rate; |
762 | - if ( $amount < 0 ) { |
|
762 | + if ($amount < 0) { |
|
763 | 763 | $amount = 0; |
764 | 764 | } |
765 | 765 | |
766 | 766 | } else { |
767 | 767 | // Percentage discount |
768 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
768 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | } else { |
@@ -774,108 +774,108 @@ discard block |
||
774 | 774 | |
775 | 775 | } |
776 | 776 | |
777 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
777 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
778 | 778 | } |
779 | 779 | |
780 | -function wpinv_increase_discount_usage( $code ) { |
|
780 | +function wpinv_increase_discount_usage($code) { |
|
781 | 781 | |
782 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
783 | - $uses = wpinv_get_discount_uses( $id ); |
|
782 | + $id = wpinv_get_discount_id_by_code($code); |
|
783 | + $uses = wpinv_get_discount_uses($id); |
|
784 | 784 | |
785 | - if ( $uses ) { |
|
785 | + if ($uses) { |
|
786 | 786 | $uses++; |
787 | 787 | } else { |
788 | 788 | $uses = 1; |
789 | 789 | } |
790 | 790 | |
791 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
791 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
792 | 792 | |
793 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
793 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
794 | 794 | |
795 | 795 | return $uses; |
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | -function wpinv_decrease_discount_usage( $code ) { |
|
799 | +function wpinv_decrease_discount_usage($code) { |
|
800 | 800 | |
801 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
802 | - $uses = wpinv_get_discount_uses( $id ); |
|
801 | + $id = wpinv_get_discount_id_by_code($code); |
|
802 | + $uses = wpinv_get_discount_uses($id); |
|
803 | 803 | |
804 | - if ( $uses ) { |
|
804 | + if ($uses) { |
|
805 | 805 | $uses--; |
806 | 806 | } |
807 | 807 | |
808 | - if ( $uses < 0 ) { |
|
808 | + if ($uses < 0) { |
|
809 | 809 | $uses = 0; |
810 | 810 | } |
811 | 811 | |
812 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
812 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
813 | 813 | |
814 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
814 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
815 | 815 | |
816 | 816 | return $uses; |
817 | 817 | |
818 | 818 | } |
819 | 819 | |
820 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
821 | - if ( $type == 'flat' ) { |
|
822 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
820 | +function wpinv_format_discount_rate($type, $amount) { |
|
821 | + if ($type == 'flat') { |
|
822 | + return wpinv_price(wpinv_format_amount($amount)); |
|
823 | 823 | } else { |
824 | 824 | return $amount . '%'; |
825 | 825 | } |
826 | 826 | } |
827 | 827 | |
828 | -function wpinv_set_cart_discount( $code = '' ) { |
|
829 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
828 | +function wpinv_set_cart_discount($code = '') { |
|
829 | + if (wpinv_multiple_discounts_allowed()) { |
|
830 | 830 | // Get all active cart discounts |
831 | 831 | $discounts = wpinv_get_cart_discounts(); |
832 | 832 | } else { |
833 | 833 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
834 | 834 | } |
835 | 835 | |
836 | - if ( $discounts ) { |
|
837 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
838 | - if( false !== $key ) { |
|
839 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
836 | + if ($discounts) { |
|
837 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
838 | + if (false !== $key) { |
|
839 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
840 | 840 | } |
841 | 841 | $discounts[] = $code; |
842 | 842 | } else { |
843 | 843 | $discounts = array(); |
844 | 844 | $discounts[] = $code; |
845 | 845 | } |
846 | - $discounts = array_values( $discounts ); |
|
846 | + $discounts = array_values($discounts); |
|
847 | 847 | |
848 | 848 | $data = wpinv_get_checkout_session(); |
849 | - if ( empty( $data ) ) { |
|
849 | + if (empty($data)) { |
|
850 | 850 | $data = array(); |
851 | 851 | } else { |
852 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
853 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
854 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
852 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
853 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
854 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | $data['cart_discounts'] = $discounts; |
858 | 858 | |
859 | - wpinv_set_checkout_session( $data ); |
|
859 | + wpinv_set_checkout_session($data); |
|
860 | 860 | |
861 | 861 | return $discounts; |
862 | 862 | } |
863 | 863 | |
864 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
864 | +function wpinv_unset_cart_discount($code = '') { |
|
865 | 865 | $discounts = wpinv_get_cart_discounts(); |
866 | 866 | |
867 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
868 | - $key = array_search( $code, $discounts ); |
|
869 | - unset( $discounts[ $key ] ); |
|
867 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
868 | + $key = array_search($code, $discounts); |
|
869 | + unset($discounts[$key]); |
|
870 | 870 | |
871 | 871 | $data = wpinv_get_checkout_session(); |
872 | 872 | $data['cart_discounts'] = $discounts; |
873 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
874 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
875 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
873 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
874 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
875 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
876 | 876 | } |
877 | 877 | |
878 | - wpinv_set_checkout_session( $data ); |
|
878 | + wpinv_set_checkout_session($data); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | return $discounts; |
@@ -884,27 +884,27 @@ discard block |
||
884 | 884 | function wpinv_unset_all_cart_discounts() { |
885 | 885 | $data = wpinv_get_checkout_session(); |
886 | 886 | |
887 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
888 | - unset( $data['cart_discounts'] ); |
|
887 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
888 | + unset($data['cart_discounts']); |
|
889 | 889 | |
890 | - wpinv_set_checkout_session( $data ); |
|
890 | + wpinv_set_checkout_session($data); |
|
891 | 891 | return true; |
892 | 892 | } |
893 | 893 | |
894 | 894 | return false; |
895 | 895 | } |
896 | 896 | |
897 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
897 | +function wpinv_get_cart_discounts($items = array()) { |
|
898 | 898 | $session = wpinv_get_checkout_session(); |
899 | 899 | |
900 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
900 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
901 | 901 | return $discounts; |
902 | 902 | } |
903 | 903 | |
904 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
904 | +function wpinv_cart_has_discounts($items = array()) { |
|
905 | 905 | $ret = false; |
906 | 906 | |
907 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
907 | + if (wpinv_get_cart_discounts($items)) { |
|
908 | 908 | $ret = true; |
909 | 909 | } |
910 | 910 | |
@@ -915,131 +915,131 @@ discard block |
||
915 | 915 | } |
916 | 916 | */ |
917 | 917 | |
918 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
918 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
919 | 919 | } |
920 | 920 | |
921 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
921 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
922 | 922 | $amount = 0.00; |
923 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
923 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
924 | 924 | |
925 | - if ( $items ) { |
|
926 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
925 | + if ($items) { |
|
926 | + $discounts = wp_list_pluck($items, 'discount'); |
|
927 | 927 | |
928 | - if ( is_array( $discounts ) ) { |
|
929 | - $discounts = array_map( 'floatval', $discounts ); |
|
930 | - $amount = array_sum( $discounts ); |
|
928 | + if (is_array($discounts)) { |
|
929 | + $discounts = array_map('floatval', $discounts); |
|
930 | + $amount = array_sum($discounts); |
|
931 | 931 | } |
932 | 932 | } |
933 | 933 | |
934 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
934 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
935 | 935 | } |
936 | 936 | |
937 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
938 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
937 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
938 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
939 | 939 | |
940 | - if ( empty( $discount ) || empty( $items ) ) { |
|
940 | + if (empty($discount) || empty($items)) { |
|
941 | 941 | return 0; |
942 | 942 | } |
943 | 943 | |
944 | 944 | $amount = 0; |
945 | 945 | |
946 | - foreach ( $items as $item ) { |
|
947 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
946 | + foreach ($items as $item) { |
|
947 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
948 | 948 | } |
949 | 949 | |
950 | - $amount = wpinv_format_amount( $amount ); |
|
950 | + $amount = wpinv_format_amount($amount); |
|
951 | 951 | |
952 | 952 | return $amount; |
953 | 953 | } |
954 | 954 | |
955 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
955 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
956 | 956 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
957 | 957 | |
958 | 958 | $amount = 0; |
959 | 959 | |
960 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
960 | + if (empty($item) || empty($item['id'])) { |
|
961 | 961 | return $amount; |
962 | 962 | } |
963 | 963 | |
964 | - if ( empty( $item['quantity'] ) ) { |
|
964 | + if (empty($item['quantity'])) { |
|
965 | 965 | return $amount; |
966 | 966 | } |
967 | 967 | |
968 | - if ( empty( $item['options'] ) ) { |
|
968 | + if (empty($item['options'])) { |
|
969 | 969 | $item['options'] = array(); |
970 | 970 | } |
971 | 971 | |
972 | - $price = wpinv_get_cart_item_price( $item['id'], $item['options'] ); |
|
972 | + $price = wpinv_get_cart_item_price($item['id'], $item['options']); |
|
973 | 973 | $discounted_price = $price; |
974 | 974 | |
975 | 975 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
976 | - if ( empty( $discounts ) ) { |
|
976 | + if (empty($discounts)) { |
|
977 | 977 | return $amount; |
978 | 978 | } |
979 | 979 | |
980 | - if ( $discounts ) { |
|
981 | - if ( is_array( $discounts ) ) { |
|
982 | - $discounts = array_values( $discounts ); |
|
980 | + if ($discounts) { |
|
981 | + if (is_array($discounts)) { |
|
982 | + $discounts = array_values($discounts); |
|
983 | 983 | } else { |
984 | - $discounts = explode( ',', $discounts ); |
|
984 | + $discounts = explode(',', $discounts); |
|
985 | 985 | } |
986 | 986 | } |
987 | 987 | |
988 | - if( $discounts ) { |
|
989 | - foreach ( $discounts as $discount ) { |
|
990 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
988 | + if ($discounts) { |
|
989 | + foreach ($discounts as $discount) { |
|
990 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
991 | 991 | |
992 | 992 | // Check discount exists |
993 | - if( ! $code_id ) { |
|
993 | + if (!$code_id) { |
|
994 | 994 | continue; |
995 | 995 | } |
996 | 996 | |
997 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
998 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
997 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
998 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
999 | 999 | |
1000 | 1000 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1001 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1002 | - foreach ( $reqs as $item_id ) { |
|
1003 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1004 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1001 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1002 | + foreach ($reqs as $item_id) { |
|
1003 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1004 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | } else { |
1008 | 1008 | // This is a global cart discount |
1009 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1010 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1009 | + if (!in_array($item['id'], $excluded_items)) { |
|
1010 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1011 | 1011 | $items_subtotal = 0.00; |
1012 | 1012 | $cart_items = wpinv_get_cart_contents(); |
1013 | 1013 | |
1014 | - foreach ( $cart_items as $cart_item ) { |
|
1015 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1016 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1017 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $options ); |
|
1014 | + foreach ($cart_items as $cart_item) { |
|
1015 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1016 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1017 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $options); |
|
1018 | 1018 | $items_subtotal += $item_price * $cart_item['quantity']; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1023 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1022 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1023 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1024 | 1024 | $discounted_amount = $code_amount * $subtotal_percent; |
1025 | 1025 | $discounted_price -= $discounted_amount; |
1026 | 1026 | |
1027 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1027 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1028 | 1028 | |
1029 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1029 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1030 | 1030 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1031 | 1031 | $discounted_price -= $adjustment; |
1032 | 1032 | } |
1033 | 1033 | } else { |
1034 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1034 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1040 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1041 | 1041 | |
1042 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1042 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1043 | 1043 | $amount = $amount * $item['quantity']; |
1044 | 1044 | } |
1045 | 1045 | } |
@@ -1047,59 +1047,59 @@ discard block |
||
1047 | 1047 | return $amount; |
1048 | 1048 | } |
1049 | 1049 | |
1050 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1051 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1050 | +function wpinv_cart_discounts_html($items = array()) { |
|
1051 | + echo wpinv_get_cart_discounts_html($items); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1054 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1055 | 1055 | global $wpi_cart_columns; |
1056 | 1056 | |
1057 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1057 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1058 | 1058 | |
1059 | - if ( !$discounts ) { |
|
1060 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1059 | + if (!$discounts) { |
|
1060 | + $discounts = wpinv_get_cart_discounts($items); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | - if ( !$discounts ) { |
|
1063 | + if (!$discounts) { |
|
1064 | 1064 | return; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1067 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1068 | 1068 | |
1069 | 1069 | $html = ''; |
1070 | 1070 | |
1071 | - foreach ( $discounts as $discount ) { |
|
1072 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1073 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1074 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1075 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1076 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1071 | + foreach ($discounts as $discount) { |
|
1072 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1073 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1074 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1075 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1076 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1077 | 1077 | |
1078 | 1078 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1079 | 1079 | ob_start(); |
1080 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1080 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1081 | 1081 | $html .= ob_get_clean(); |
1082 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( $amount ) . '</span></td>'; |
|
1082 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price($amount) . '</span></td>'; |
|
1083 | 1083 | ob_start(); |
1084 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1084 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1085 | 1085 | $html .= ob_get_clean(); |
1086 | 1086 | $html .= '</tr>'; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1089 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
1092 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
1093 | 1093 | $discounts = wpinv_get_cart_discounts(); |
1094 | 1094 | |
1095 | - if ( empty( $discounts ) ) { |
|
1095 | + if (empty($discounts)) { |
|
1096 | 1096 | return false; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1100 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1099 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1100 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1101 | 1101 | |
1102 | - if ( $echo ) { |
|
1102 | + if ($echo) { |
|
1103 | 1103 | echo $amount; |
1104 | 1104 | } |
1105 | 1105 | |
@@ -1107,133 +1107,133 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | function wpinv_remove_cart_discount() { |
1110 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1110 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1111 | 1111 | return; |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1114 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1115 | 1115 | |
1116 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1116 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1117 | 1117 | |
1118 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1118 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1119 | 1119 | |
1120 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1120 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1121 | 1121 | } |
1122 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1122 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1123 | 1123 | |
1124 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
1124 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
1125 | 1125 | $discounts = wpinv_get_cart_discounts(); |
1126 | 1126 | |
1127 | - if ( !$discounts ) { |
|
1127 | + if (!$discounts) { |
|
1128 | 1128 | return; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - foreach ( $discounts as $discount ) { |
|
1132 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1133 | - wpinv_unset_cart_discount( $discount ); |
|
1131 | + foreach ($discounts as $discount) { |
|
1132 | + if (!wpinv_is_discount_valid($discount)) { |
|
1133 | + wpinv_unset_cart_discount($discount); |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1137 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1138 | 1138 | |
1139 | 1139 | function wpinv_multiple_discounts_allowed() { |
1140 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1141 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1140 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1141 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | function wpinv_listen_for_cart_discount() { |
1145 | 1145 | global $wpi_session; |
1146 | 1146 | |
1147 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
1147 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
1148 | 1148 | return; |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
1151 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
1152 | 1152 | |
1153 | - $wpi_session->set( 'preset_discount', $code ); |
|
1153 | + $wpi_session->set('preset_discount', $code); |
|
1154 | 1154 | } |
1155 | 1155 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
1156 | 1156 | |
1157 | 1157 | function wpinv_apply_preset_discount() { |
1158 | 1158 | global $wpi_session; |
1159 | 1159 | |
1160 | - $code = $wpi_session->get( 'preset_discount' ); |
|
1160 | + $code = $wpi_session->get('preset_discount'); |
|
1161 | 1161 | |
1162 | - if ( !$code ) { |
|
1162 | + if (!$code) { |
|
1163 | 1163 | return; |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
1166 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
1167 | 1167 | return; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
1170 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
1171 | 1171 | |
1172 | - wpinv_set_cart_discount( $code ); |
|
1172 | + wpinv_set_cart_discount($code); |
|
1173 | 1173 | |
1174 | - $wpi_session->set( 'preset_discount', null ); |
|
1174 | + $wpi_session->set('preset_discount', null); |
|
1175 | 1175 | } |
1176 | 1176 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1177 | 1177 | |
1178 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1179 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1180 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1178 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1179 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1180 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1181 | 1181 | |
1182 | - if ( $echo ) { |
|
1182 | + if ($echo) { |
|
1183 | 1183 | echo $label; |
1184 | 1184 | } else { |
1185 | 1185 | return $label; |
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | |
1189 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1190 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
1191 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1189 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1190 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
1191 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1192 | 1192 | |
1193 | - if ( $echo ) { |
|
1193 | + if ($echo) { |
|
1194 | 1194 | echo $label; |
1195 | 1195 | } else { |
1196 | 1196 | return $label; |
1197 | 1197 | } |
1198 | 1198 | } |
1199 | 1199 | |
1200 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
1201 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1200 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
1201 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1202 | 1202 | return true; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | return $check; |
1206 | 1206 | } |
1207 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
1207 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
1208 | 1208 | |
1209 | 1209 | function wpinv_checkout_form_validate_discounts() { |
1210 | 1210 | $discounts = wpinv_get_cart_discounts(); |
1211 | 1211 | |
1212 | - if ( !empty( $discounts ) ) { |
|
1212 | + if (!empty($discounts)) { |
|
1213 | 1213 | $invalid = false; |
1214 | 1214 | |
1215 | - foreach ( $discounts as $key => $code ) { |
|
1216 | - if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) { |
|
1215 | + foreach ($discounts as $key => $code) { |
|
1216 | + if (!wpinv_is_discount_valid($code, get_current_user_id())) { |
|
1217 | 1217 | $invalid = true; |
1218 | 1218 | |
1219 | - wpinv_unset_cart_discount( $code ); |
|
1219 | + wpinv_unset_cart_discount($code); |
|
1220 | 1220 | } |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - if ( $invalid ) { |
|
1223 | + if ($invalid) { |
|
1224 | 1224 | $errors = wpinv_get_errors(); |
1225 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1227 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1225 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1227 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1228 | 1228 | |
1229 | - wpinv_recalculate_tax( true ); |
|
1229 | + wpinv_recalculate_tax(true); |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1233 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1234 | 1234 | |
1235 | 1235 | function wpinv_discount_amount() { |
1236 | 1236 | $output = 0.00; |
1237 | 1237 | |
1238 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1238 | + return apply_filters('wpinv_discount_amount', $output); |
|
1239 | 1239 | } |
1240 | 1240 | \ No newline at end of file |
@@ -11,22 +11,22 @@ |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
24 | + update_option('wpinv_version', WPINV_VERSION); |
|
25 | 25 | } |
26 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
26 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
27 | 27 | |
28 | 28 | function wpinv_v005_upgrades() { |
29 | 29 | global $wpdb; |
30 | 30 | |
31 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
31 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -7,15 +7,15 @@ discard block |
||
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(); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | self::$instance->reports = new WPInv_Reports(); |
24 | 24 | } |
25 | 25 | |
26 | - do_action( 'wpinv_loaded' ); |
|
26 | + do_action('wpinv_loaded'); |
|
27 | 27 | |
28 | 28 | return self::$instance; |
29 | 29 | } |
@@ -33,31 +33,31 @@ discard block |
||
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( 'WPInv_Shortcodes', 'init' ) ); |
|
48 | - 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('WPInv_Shortcodes', 'init')); |
|
48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
49 | 49 | |
50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
50 | + if (class_exists('BuddyPress')) { |
|
51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
52 | 52 | } |
53 | 53 | |
54 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
55 | 55 | |
56 | - if ( is_admin() ) { |
|
57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
56 | + if (is_admin()) { |
|
57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
59 | 59 | } else { |
60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
69 | 69 | */ |
70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
71 | 71 | |
72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function plugins_loaded() { |
@@ -83,189 +83,189 @@ discard block |
||
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | 85 | public function load_textdomain() { |
86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
87 | 87 | |
88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Define language constants. |
93 | 93 | */ |
94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | public function includes() { |
98 | 98 | global $wpinv_options; |
99 | 99 | |
100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
101 | 101 | $wpinv_options = wpinv_get_settings(); |
102 | 102 | |
103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
126 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
126 | + if (!class_exists('Geodir_EUVat')) { |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
128 | 128 | } |
129 | 129 | |
130 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
131 | - if ( !empty( $gateways ) ) { |
|
132 | - foreach ( $gateways as $gateway ) { |
|
133 | - if ( $gateway == 'manual' ) { |
|
130 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
131 | + if (!empty($gateways)) { |
|
132 | + foreach ($gateways as $gateway) { |
|
133 | + if ($gateway == 'manual') { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
138 | 138 | |
139 | - if ( file_exists( $gateway_file ) ) { |
|
140 | - require_once( $gateway_file ); |
|
139 | + if (file_exists($gateway_file)) { |
|
140 | + require_once($gateway_file); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
145 | - |
|
146 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
154 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
145 | + |
|
146 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
154 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
158 | 158 | // include css inliner |
159 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
160 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
159 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
160 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
161 | 161 | } |
162 | 162 | |
163 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
163 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | public function init() { |
167 | 167 | } |
168 | 168 | |
169 | 169 | public function admin_init() { |
170 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
170 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
171 | 171 | } |
172 | 172 | |
173 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
173 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | public function activation_redirect() { |
177 | 177 | // Bail if no activation redirect |
178 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
178 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Delete the redirect transient |
183 | - delete_transient( '_wpinv_activation_redirect' ); |
|
183 | + delete_transient('_wpinv_activation_redirect'); |
|
184 | 184 | |
185 | 185 | // Bail if activating from network, or bulk |
186 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
186 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
190 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
190 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
191 | 191 | exit; |
192 | 192 | } |
193 | 193 | |
194 | 194 | public function enqueue_scripts() { |
195 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
195 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
196 | 196 | |
197 | - wp_deregister_style( 'font-awesome' ); |
|
198 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
199 | - wp_enqueue_style( 'font-awesome' ); |
|
197 | + wp_deregister_style('font-awesome'); |
|
198 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
199 | + wp_enqueue_style('font-awesome'); |
|
200 | 200 | |
201 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
202 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
201 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
202 | + wp_enqueue_style('wpinv_front_style'); |
|
203 | 203 | |
204 | 204 | // Register scripts |
205 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
206 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
205 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
206 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
207 | 207 | |
208 | 208 | $localize = array(); |
209 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
210 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
209 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
210 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
211 | 211 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
212 | 212 | $localize['currency_pos'] = wpinv_currency_position(); |
213 | 213 | $localize['thousand_sep'] = wpinv_thousands_seperator(); |
214 | 214 | $localize['decimal_sep'] = wpinv_decimal_seperator(); |
215 | 215 | $localize['decimals'] = wpinv_decimals(); |
216 | 216 | |
217 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
217 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
218 | 218 | |
219 | - wp_enqueue_script( 'jquery-blockui' ); |
|
220 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
221 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
219 | + wp_enqueue_script('jquery-blockui'); |
|
220 | + wp_enqueue_script('wpinv-front-script'); |
|
221 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | public function admin_enqueue_scripts() { |
225 | 225 | global $post, $pagenow; |
226 | 226 | |
227 | 227 | $post_type = wpinv_admin_post_type(); |
228 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
228 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
229 | 229 | |
230 | - wp_deregister_style( 'font-awesome' ); |
|
231 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
232 | - wp_enqueue_style( 'font-awesome' ); |
|
230 | + wp_deregister_style('font-awesome'); |
|
231 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
232 | + wp_enqueue_style('font-awesome'); |
|
233 | 233 | |
234 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
235 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
234 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
235 | + wp_enqueue_style('jquery-ui-css'); |
|
236 | 236 | |
237 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
238 | - wp_enqueue_style( 'jquery-chosen' ); |
|
237 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
238 | + wp_enqueue_style('jquery-chosen'); |
|
239 | 239 | |
240 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
241 | - wp_enqueue_script( 'jquery-chosen' ); |
|
240 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
241 | + wp_enqueue_script('jquery-chosen'); |
|
242 | 242 | |
243 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
244 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
243 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
244 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
245 | 245 | |
246 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
247 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
246 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
247 | + wp_enqueue_style('wpinv_admin_style'); |
|
248 | 248 | |
249 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
250 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
249 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
250 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
251 | 251 | } |
252 | 252 | |
253 | - wp_enqueue_style( 'wp-color-picker' ); |
|
254 | - wp_enqueue_script( 'wp-color-picker' ); |
|
253 | + wp_enqueue_style('wp-color-picker'); |
|
254 | + wp_enqueue_script('wp-color-picker'); |
|
255 | 255 | |
256 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
256 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
257 | 257 | |
258 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), WPINV_VERSION ); |
|
259 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
258 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION); |
|
259 | + wp_enqueue_script('wpinv-admin-script'); |
|
260 | 260 | |
261 | 261 | $localize = array(); |
262 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
263 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
264 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
265 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
266 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
267 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
268 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
262 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
263 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
264 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
265 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
266 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
267 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
268 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
269 | 269 | $localize['tax'] = wpinv_tax_amount(); |
270 | 270 | $localize['discount'] = wpinv_discount_amount(); |
271 | 271 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -273,55 +273,55 @@ discard block |
||
273 | 273 | $localize['thousand_sep'] = wpinv_thousands_seperator(); |
274 | 274 | $localize['decimal_sep'] = wpinv_decimal_seperator(); |
275 | 275 | $localize['decimals'] = wpinv_decimals(); |
276 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
277 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
278 | - $localize['status_pending'] = wpinv_status_nicename( 'pending' ); |
|
279 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
280 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
281 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
282 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
283 | - $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' ); |
|
284 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
285 | - $localize['hasGD'] = wpinv_gd_active();; |
|
276 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
277 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
278 | + $localize['status_pending'] = wpinv_status_nicename('pending'); |
|
279 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
280 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
281 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
282 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
283 | + $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'); |
|
284 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
285 | + $localize['hasGD'] = wpinv_gd_active(); ; |
|
286 | 286 | $localize['hasPM'] = wpinv_pm_active(); |
287 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
288 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
289 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
290 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
287 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
288 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
289 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
290 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
291 | 291 | |
292 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
292 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
293 | 293 | } |
294 | 294 | |
295 | - public function admin_body_class( $classes ) { |
|
295 | + public function admin_body_class($classes) { |
|
296 | 296 | global $pagenow; |
297 | 297 | |
298 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
298 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
299 | 299 | |
300 | 300 | $add_class = false; |
301 | - if ( $pagenow == 'admin.php' && $page ) { |
|
302 | - $add_class = strpos( $page, 'wpinv-' ); |
|
301 | + if ($pagenow == 'admin.php' && $page) { |
|
302 | + $add_class = strpos($page, 'wpinv-'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $settings_class = array(); |
306 | - if ( $page == 'wpinv-settings' ) { |
|
307 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
308 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
306 | + if ($page == 'wpinv-settings') { |
|
307 | + if (!empty($_REQUEST['tab'])) { |
|
308 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
312 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
311 | + if (!empty($_REQUEST['section'])) { |
|
312 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
313 | 313 | } |
314 | 314 | |
315 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
315 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
316 | 316 | } |
317 | 317 | |
318 | - if ( !empty( $settings_class ) ) { |
|
319 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
318 | + if (!empty($settings_class)) { |
|
319 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | $post_type = wpinv_admin_post_type(); |
323 | 323 | |
324 | - if ( $post_type == 'wpi_invoice' || $add_class !== false ) { |
|
324 | + if ($post_type == 'wpi_invoice' || $add_class !== false) { |
|
325 | 325 | return $classes .= ' wpinv'; |
326 | 326 | } else { |
327 | 327 | return $classes; |
@@ -333,26 +333,26 @@ discard block |
||
333 | 333 | public function admin_print_scripts_edit_php() { |
334 | 334 | $post_type = wpinv_admin_post_type(); |
335 | 335 | |
336 | - if ( $post_type == 'wpi_item' ) { |
|
337 | - wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); |
|
336 | + if ($post_type == 'wpi_item') { |
|
337 | + wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | 341 | public function wpinv_actions() { |
342 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
343 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
342 | + if (isset($_REQUEST['wpi_action'])) { |
|
343 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - public function pre_get_posts( $wp_query ) { |
|
348 | - 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() ) { |
|
349 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
347 | + public function pre_get_posts($wp_query) { |
|
348 | + 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()) { |
|
349 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | return $wp_query; |
353 | 353 | } |
354 | 354 | |
355 | 355 | public function bp_invoicing_init() { |
356 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
356 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | \ No newline at end of file |
@@ -1,26 +1,26 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_user_invoices( $current_page = 1 ) { |
|
5 | +function wpinv_user_invoices($current_page = 1) { |
|
6 | 6 | global $current_page; |
7 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
7 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
8 | 8 | } |
9 | 9 | |
10 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) { |
|
11 | - if ( empty( $user ) ) { |
|
10 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') { |
|
11 | + if (empty($user)) { |
|
12 | 12 | $user = get_current_user_id(); |
13 | 13 | } |
14 | 14 | |
15 | - if ( 0 === $user ) { |
|
15 | + if (0 === $user) { |
|
16 | 16 | return false; |
17 | 17 | } |
18 | 18 | |
19 | - if ( $pagination ) { |
|
20 | - if ( get_query_var( 'paged' ) ) |
|
19 | + if ($pagination) { |
|
20 | + if (get_query_var('paged')) |
|
21 | 21 | $paged = get_query_var('paged'); |
22 | - else if ( get_query_var( 'page' ) ) |
|
23 | - $paged = get_query_var( 'page' ); |
|
22 | + else if (get_query_var('page')) |
|
23 | + $paged = get_query_var('page'); |
|
24 | 24 | else |
25 | 25 | $paged = 1; |
26 | 26 | } |
@@ -29,21 +29,21 @@ discard block |
||
29 | 29 | 'post_type' => 'wpi_invoice', |
30 | 30 | 'posts_per_page' => 20, |
31 | 31 | 'paged' => null, |
32 | - 'post_status' => array( 'publish', 'pending' ), |
|
32 | + 'post_status' => array('publish', 'pending'), |
|
33 | 33 | 'user' => $user, |
34 | 34 | 'order' => 'date', |
35 | 35 | ); |
36 | 36 | |
37 | - $invoices = get_posts( $args ); |
|
37 | + $invoices = get_posts($args); |
|
38 | 38 | |
39 | 39 | // No invoices |
40 | - if ( ! $invoices ) |
|
40 | + if (!$invoices) |
|
41 | 41 | return false; |
42 | 42 | |
43 | 43 | return $invoices; |
44 | 44 | } |
45 | 45 | |
46 | -function wpinv_dropdown_users( $args = '' ) { |
|
46 | +function wpinv_dropdown_users($args = '') { |
|
47 | 47 | $defaults = array( |
48 | 48 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
49 | 49 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -54,18 +54,18 @@ discard block |
||
54 | 54 | 'option_none_value' => -1 |
55 | 55 | ); |
56 | 56 | |
57 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
57 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
58 | 58 | |
59 | - $r = wp_parse_args( $args, $defaults ); |
|
59 | + $r = wp_parse_args($args, $defaults); |
|
60 | 60 | |
61 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
61 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
62 | 62 | |
63 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
63 | + $fields = array('ID', 'user_login', 'user_email'); |
|
64 | 64 | |
65 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
66 | - if ( 'display_name_with_login' === $show ) { |
|
65 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
66 | + if ('display_name_with_login' === $show) { |
|
67 | 67 | $fields[] = 'display_name'; |
68 | - } else if ( 'display_name_with_email' === $show ) { |
|
68 | + } else if ('display_name_with_email' === $show) { |
|
69 | 69 | $fields[] = 'display_name'; |
70 | 70 | } else { |
71 | 71 | $fields[] = $show; |
@@ -77,99 +77,99 @@ discard block |
||
77 | 77 | $show_option_none = $r['show_option_none']; |
78 | 78 | $option_none_value = $r['option_none_value']; |
79 | 79 | |
80 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
80 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
81 | 81 | |
82 | - $users = get_users( $query_args ); |
|
82 | + $users = get_users($query_args); |
|
83 | 83 | |
84 | 84 | $output = ''; |
85 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
86 | - $name = esc_attr( $r['name'] ); |
|
87 | - if ( $r['multi'] && ! $r['id'] ) { |
|
85 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
86 | + $name = esc_attr($r['name']); |
|
87 | + if ($r['multi'] && !$r['id']) { |
|
88 | 88 | $id = ''; |
89 | 89 | } else { |
90 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
90 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
91 | 91 | } |
92 | 92 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
93 | 93 | |
94 | - if ( $show_option_all ) { |
|
94 | + if ($show_option_all) { |
|
95 | 95 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
96 | 96 | } |
97 | 97 | |
98 | - if ( $show_option_none ) { |
|
99 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
100 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
98 | + if ($show_option_none) { |
|
99 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
100 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
103 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
104 | 104 | $found_selected = false; |
105 | - $r['selected'] = (int) $r['selected']; |
|
106 | - foreach ( (array) $users as $user ) { |
|
107 | - $user->ID = (int) $user->ID; |
|
108 | - if ( $user->ID === $r['selected'] ) { |
|
105 | + $r['selected'] = (int)$r['selected']; |
|
106 | + foreach ((array)$users as $user) { |
|
107 | + $user->ID = (int)$user->ID; |
|
108 | + if ($user->ID === $r['selected']) { |
|
109 | 109 | $found_selected = true; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - if ( ! $found_selected ) { |
|
114 | - $users[] = get_userdata( $r['selected'] ); |
|
113 | + if (!$found_selected) { |
|
114 | + $users[] = get_userdata($r['selected']); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - foreach ( (array) $users as $user ) { |
|
119 | - if ( 'display_name_with_login' === $show ) { |
|
118 | + foreach ((array)$users as $user) { |
|
119 | + if ('display_name_with_login' === $show) { |
|
120 | 120 | /* translators: 1: display name, 2: user_login */ |
121 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
122 | - } elseif ( 'display_name_with_email' === $show ) { |
|
121 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
122 | + } elseif ('display_name_with_email' === $show) { |
|
123 | 123 | /* translators: 1: display name, 2: user_email */ |
124 | - if ( $user->display_name == $user->user_email ) { |
|
124 | + if ($user->display_name == $user->user_email) { |
|
125 | 125 | $display = $user->display_name; |
126 | 126 | } else { |
127 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
127 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
128 | 128 | } |
129 | - } elseif ( ! empty( $user->$show ) ) { |
|
129 | + } elseif (!empty($user->$show)) { |
|
130 | 130 | $display = $user->$show; |
131 | 131 | } else { |
132 | 132 | $display = '(' . $user->user_login . ')'; |
133 | 133 | } |
134 | 134 | |
135 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
136 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
135 | + $_selected = selected($user->ID, $r['selected'], false); |
|
136 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $output .= "</select>"; |
140 | 140 | } |
141 | 141 | |
142 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
142 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
143 | 143 | |
144 | - if ( $r['echo'] ) { |
|
144 | + if ($r['echo']) { |
|
145 | 145 | echo $html; |
146 | 146 | } |
147 | 147 | return $html; |
148 | 148 | } |
149 | 149 | |
150 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
151 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
152 | - wpinv_login_user( $user_id ); |
|
150 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
151 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
152 | + wpinv_login_user($user_id); |
|
153 | 153 | } else { |
154 | - $redirect_to = wp_login_url( $redirect_to ); |
|
154 | + $redirect_to = wp_login_url($redirect_to); |
|
155 | 155 | } |
156 | 156 | |
157 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
157 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
158 | 158 | |
159 | - wp_redirect( $redirect_to ); |
|
159 | + wp_redirect($redirect_to); |
|
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_login_user( $user_id ) { |
|
163 | - if ( is_user_logged_in() ) { |
|
162 | +function wpinv_login_user($user_id) { |
|
163 | + if (is_user_logged_in()) { |
|
164 | 164 | return true; |
165 | 165 | } |
166 | 166 | |
167 | - $user = get_user_by( 'id', $user_id ); |
|
167 | + $user = get_user_by('id', $user_id); |
|
168 | 168 | |
169 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
170 | - wp_set_current_user( $user_id, $user->user_login ); |
|
171 | - wp_set_auth_cookie( $user_id ); |
|
172 | - do_action( 'wp_login', $user->user_login ); |
|
169 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
170 | + wp_set_current_user($user_id, $user->user_login); |
|
171 | + wp_set_auth_cookie($user_id); |
|
172 | + do_action('wp_login', $user->user_login); |
|
173 | 173 | |
174 | 174 | return true; |
175 | 175 | } |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | function wpinv_user_invoices( $current_page = 1 ) { |
6 | 8 | global $current_page; |
@@ -17,12 +19,13 @@ discard block |
||
17 | 19 | } |
18 | 20 | |
19 | 21 | if ( $pagination ) { |
20 | - if ( get_query_var( 'paged' ) ) |
|
21 | - $paged = get_query_var('paged'); |
|
22 | - else if ( get_query_var( 'page' ) ) |
|
23 | - $paged = get_query_var( 'page' ); |
|
24 | - else |
|
25 | - $paged = 1; |
|
22 | + if ( get_query_var( 'paged' ) ) { |
|
23 | + $paged = get_query_var('paged'); |
|
24 | + } else if ( get_query_var( 'page' ) ) { |
|
25 | + $paged = get_query_var( 'page' ); |
|
26 | + } else { |
|
27 | + $paged = 1; |
|
28 | + } |
|
26 | 29 | } |
27 | 30 | |
28 | 31 | $args = array( |
@@ -37,8 +40,9 @@ discard block |
||
37 | 40 | $invoices = get_posts( $args ); |
38 | 41 | |
39 | 42 | // No invoices |
40 | - if ( ! $invoices ) |
|
41 | - return false; |
|
43 | + if ( ! $invoices ) { |
|
44 | + return false; |
|
45 | + } |
|
42 | 46 | |
43 | 47 | return $invoices; |
44 | 48 | } |
@@ -976,67 +976,67 @@ |
||
976 | 976 | function wpinv_tool_merge_fix_taxes() { |
977 | 977 | global $wpdb; |
978 | 978 | |
979 | - $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'"; |
|
980 | - $items = $wpdb->get_results( $sql ); |
|
979 | + $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'"; |
|
980 | + $items = $wpdb->get_results( $sql ); |
|
981 | 981 | |
982 | - if ( !empty( $items ) ) { |
|
983 | - foreach ( $items as $item ) { |
|
984 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
985 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
986 | - } |
|
987 | - } |
|
988 | - } |
|
982 | + if ( !empty( $items ) ) { |
|
983 | + foreach ( $items as $item ) { |
|
984 | + if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
985 | + update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
986 | + } |
|
987 | + } |
|
988 | + } |
|
989 | 989 | |
990 | 990 | $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC"; |
991 | 991 | $items = $wpdb->get_results( $sql ); |
992 | 992 | |
993 | - if ( !empty( $items ) ) { |
|
994 | - $success = false; |
|
993 | + if ( !empty( $items ) ) { |
|
994 | + $success = false; |
|
995 | 995 | $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
996 | 996 | |
997 | - global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
|
997 | + global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
|
998 | 998 | |
999 | - foreach ( $items as $item ) { |
|
1000 | - $wpi_tax_rates = NULL; |
|
1001 | - $data = wpinv_get_invoice($item->ID); |
|
999 | + foreach ( $items as $item ) { |
|
1000 | + $wpi_tax_rates = NULL; |
|
1001 | + $data = wpinv_get_invoice($item->ID); |
|
1002 | 1002 | |
1003 | - if ( empty( $data ) ) { |
|
1004 | - continue; |
|
1005 | - } |
|
1003 | + if ( empty( $data ) ) { |
|
1004 | + continue; |
|
1005 | + } |
|
1006 | 1006 | |
1007 | - $checkout_session = wpinv_get_checkout_session(); |
|
1007 | + $checkout_session = wpinv_get_checkout_session(); |
|
1008 | 1008 | |
1009 | - $data_session = array(); |
|
1010 | - $data_session['invoice_id'] = $data->ID; |
|
1011 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
1009 | + $data_session = array(); |
|
1010 | + $data_session['invoice_id'] = $data->ID; |
|
1011 | + $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
1012 | 1012 | |
1013 | - wpinv_set_checkout_session( $data_session ); |
|
1013 | + wpinv_set_checkout_session( $data_session ); |
|
1014 | 1014 | |
1015 | - $wpi_userID = (int)$data->get_user_id(); |
|
1016 | - $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
|
1015 | + $wpi_userID = (int)$data->get_user_id(); |
|
1016 | + $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
|
1017 | 1017 | |
1018 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
1019 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
1018 | + $data->country = sanitize_text_field( $_POST['country'] ); |
|
1019 | + $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
1020 | 1020 | |
1021 | - $wpinv_ip_address_country = $data->country; |
|
1021 | + $wpinv_ip_address_country = $data->country; |
|
1022 | 1022 | |
1023 | - $data->recalculate_totals(true); |
|
1023 | + $data->recalculate_totals(true); |
|
1024 | 1024 | |
1025 | - wpinv_set_checkout_session( $checkout_session ); |
|
1025 | + wpinv_set_checkout_session( $checkout_session ); |
|
1026 | 1026 | |
1027 | - $update_data = array(); |
|
1028 | - $update_data['tax_amount'] = $data->get_tax(); |
|
1029 | - $update_data['paied_amount'] = $data->get_total(); |
|
1030 | - $update_data['invoice_id'] = $data->ID; |
|
1027 | + $update_data = array(); |
|
1028 | + $update_data['tax_amount'] = $data->get_tax(); |
|
1029 | + $update_data['paied_amount'] = $data->get_total(); |
|
1030 | + $update_data['invoice_id'] = $data->ID; |
|
1031 | 1031 | |
1032 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
1033 | - } |
|
1034 | - } else { |
|
1032 | + $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
1033 | + } |
|
1034 | + } else { |
|
1035 | 1035 | $success = false; |
1036 | 1036 | $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - $response = array(); |
|
1039 | + $response = array(); |
|
1040 | 1040 | $response['success'] = $success; |
1041 | 1041 | $response['data']['message'] = $message; |
1042 | 1042 | wp_send_json( $response ); |
@@ -1,23 +1,23 @@ discard block |
||
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 | function wpinv_gd_active() { |
8 | - return (bool)defined( 'GEODIRECTORY_VERSION' ); |
|
8 | + return (bool)defined('GEODIRECTORY_VERSION'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | function wpinv_pm_active() { |
12 | - return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' ); |
|
12 | + return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION'); |
|
13 | 13 | } |
14 | 14 | |
15 | -function wpinv_is_gd_post_type( $post_type ) { |
|
15 | +function wpinv_is_gd_post_type($post_type) { |
|
16 | 16 | global $gd_posttypes; |
17 | 17 | |
18 | - $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes(); |
|
18 | + $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes(); |
|
19 | 19 | |
20 | - if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) { |
|
20 | + if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) { |
|
21 | 21 | return true; |
22 | 22 | } |
23 | 23 | |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
32 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
33 | 33 | // Add fields for force upgrade |
34 | - if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) { |
|
35 | - geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' ); |
|
34 | + if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) { |
|
35 | + geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0'); |
|
36 | 36 | |
37 | 37 | update_option('wpinv_gdp_column', '1'); |
38 | 38 | } |
@@ -40,39 +40,39 @@ discard block |
||
40 | 40 | wpinv_merge_gd_packages_to_items(); |
41 | 41 | } |
42 | 42 | } |
43 | -add_action( 'admin_init', 'wpinv_geodir_integration' ); |
|
43 | +add_action('admin_init', 'wpinv_geodir_integration'); |
|
44 | 44 | |
45 | -function wpinv_get_gdp_package_type( $item_types ) { |
|
46 | - if ( wpinv_pm_active() ) { |
|
47 | - $item_types['package'] = __( 'Package', 'invoicing' ); |
|
45 | +function wpinv_get_gdp_package_type($item_types) { |
|
46 | + if (wpinv_pm_active()) { |
|
47 | + $item_types['package'] = __('Package', 'invoicing'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $item_types; |
51 | 51 | } |
52 | -add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 ); |
|
52 | +add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1); |
|
53 | 53 | |
54 | 54 | function wpinv_update_package_item($package_id) { |
55 | 55 | return wpinv_merge_gd_package_to_item($package_id, true); |
56 | 56 | } |
57 | 57 | add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1); |
58 | 58 | |
59 | -function wpinv_merge_gd_packages_to_items( $force = false ) { |
|
60 | - if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) { |
|
59 | +function wpinv_merge_gd_packages_to_items($force = false) { |
|
60 | + if ($merged = get_option('wpinv_merge_gd_packages') && !$force) { |
|
61 | 61 | return true; |
62 | 62 | } |
63 | 63 | |
64 | - if(!function_exists('geodir_package_list_info')){ |
|
64 | + if (!function_exists('geodir_package_list_info')) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | 68 | $packages = geodir_package_list_info(); |
69 | 69 | |
70 | - foreach ( $packages as $key => $package ) { |
|
71 | - wpinv_merge_gd_package_to_item( $package->pid, $force, $package ); |
|
70 | + foreach ($packages as $key => $package) { |
|
71 | + wpinv_merge_gd_package_to_item($package->pid, $force, $package); |
|
72 | 72 | } |
73 | 73 | |
74 | - if ( !$merged ) { |
|
75 | - update_option( 'wpinv_merge_gd_packages', 1 ); |
|
74 | + if (!$merged) { |
|
75 | + update_option('wpinv_merge_gd_packages', 1); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return true; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package; |
103 | 103 | |
104 | - if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) { |
|
104 | + if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | $meta['post_type'] = $package->post_type; |
112 | 112 | $meta['cpt_singular_name'] = get_post_type_singular_label($package->post_type); |
113 | 113 | $meta['cpt_name'] = get_post_type_plural_label($package->post_type); |
114 | - $meta['price'] = wpinv_format_amount( $package->amount, NULL, true ); |
|
114 | + $meta['price'] = wpinv_format_amount($package->amount, NULL, true); |
|
115 | 115 | $meta['vat_rule'] = 'digital'; |
116 | 116 | $meta['vat_class'] = '_standard'; |
117 | 117 | |
118 | - if ( !empty( $package->sub_active ) ) { |
|
119 | - $sub_num_trial_days = absint( $package->sub_num_trial_days ); |
|
118 | + if (!empty($package->sub_active)) { |
|
119 | + $sub_num_trial_days = absint($package->sub_num_trial_days); |
|
120 | 120 | |
121 | 121 | $meta['is_recurring'] = 1; |
122 | 122 | $meta['recurring_period'] = $package->sub_units; |
123 | - $meta['recurring_interval'] = absint( $package->sub_units_num ); |
|
124 | - $meta['recurring_limit'] = absint( $package->sub_units_num_times ); |
|
123 | + $meta['recurring_interval'] = absint($package->sub_units_num); |
|
124 | + $meta['recurring_limit'] = absint($package->sub_units_num_times); |
|
125 | 125 | $meta['free_trial'] = $sub_num_trial_days > 0 ? 1 : 0; |
126 | 126 | $meta['trial_period'] = $package->sub_num_trial_units; |
127 | 127 | $meta['trial_interval'] = $sub_num_trial_days; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $meta['trial_interval'] = ''; |
136 | 136 | } |
137 | 137 | |
138 | - $data = array( |
|
138 | + $data = array( |
|
139 | 139 | 'post_title' => $package->title, |
140 | 140 | 'post_excerpt' => $package->title_desc, |
141 | 141 | 'post_status' => $package->status == 1 ? 'publish' : 'pending', |
@@ -152,48 +152,48 @@ discard block |
||
152 | 152 | return $item; |
153 | 153 | } |
154 | 154 | |
155 | -function wpinv_gdp_to_wpi_gateway( $payment_method ) { |
|
156 | - switch( $payment_method ) { |
|
155 | +function wpinv_gdp_to_wpi_gateway($payment_method) { |
|
156 | + switch ($payment_method) { |
|
157 | 157 | case 'prebanktransfer': |
158 | 158 | $gateway = 'bank_transfer'; |
159 | 159 | break; |
160 | 160 | default: |
161 | - $gateway = empty( $payment_method ) ? 'manual' : $payment_method; |
|
161 | + $gateway = empty($payment_method) ? 'manual' : $payment_method; |
|
162 | 162 | break; |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method ); |
|
165 | + return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method); |
|
166 | 166 | } |
167 | 167 | |
168 | -function wpinv_gdp_to_wpi_gateway_title( $payment_method ) { |
|
169 | - $gateway = wpinv_gdp_to_wpi_gateway( $payment_method ); |
|
168 | +function wpinv_gdp_to_wpi_gateway_title($payment_method) { |
|
169 | + $gateway = wpinv_gdp_to_wpi_gateway($payment_method); |
|
170 | 170 | |
171 | - $gateway_title = wpinv_get_gateway_checkout_label( $gateway ); |
|
171 | + $gateway_title = wpinv_get_gateway_checkout_label($gateway); |
|
172 | 172 | |
173 | - if ( $gateway == $gateway_title ) { |
|
174 | - $gateway_title = geodir_payment_method_title( $gateway ); |
|
173 | + if ($gateway == $gateway_title) { |
|
174 | + $gateway_title = geodir_payment_method_title($gateway); |
|
175 | 175 | } |
176 | 176 | |
177 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method ); |
|
177 | + return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_print_checkout_errors() { |
181 | 181 | global $wpi_session; |
182 | 182 | wpinv_print_errors(); |
183 | 183 | } |
184 | -add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 ); |
|
184 | +add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10); |
|
185 | 185 | |
186 | -function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) { |
|
186 | +function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) { |
|
187 | 187 | global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge; |
188 | 188 | |
189 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
189 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
190 | 190 | |
191 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0; |
|
191 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0; |
|
192 | 192 | |
193 | 193 | if (!empty($invoice_info)) { |
194 | - $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL; |
|
194 | + $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL; |
|
195 | 195 | |
196 | - if ( !empty( $wpi_invoice ) ) { // update invoice |
|
196 | + if (!empty($wpi_invoice)) { // update invoice |
|
197 | 197 | $save = false; |
198 | 198 | if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) { |
199 | 199 | $save = true; |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | |
204 | 204 | if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) { |
205 | 205 | $save = true; |
206 | - $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
207 | - $gateway = wpinv_gdp_to_wpi_gateway( $gateway ); |
|
208 | - $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway ); |
|
209 | - $wpi_invoice->set('gateway', $gateway ); |
|
210 | - $wpi_invoice->set('gateway_title', $gateway_title ); |
|
206 | + $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
207 | + $gateway = wpinv_gdp_to_wpi_gateway($gateway); |
|
208 | + $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway); |
|
209 | + $wpi_invoice->set('gateway', $gateway); |
|
210 | + $wpi_invoice->set('gateway_title', $gateway_title); |
|
211 | 211 | } |
212 | 212 | |
213 | - if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) { |
|
213 | + if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) { |
|
214 | 214 | $save = true; |
215 | - $wpi_invoice->set( 'status', $status ); |
|
215 | + $wpi_invoice->set('status', $status); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | if ($save) { |
@@ -223,37 +223,37 @@ discard block |
||
223 | 223 | |
224 | 224 | return $wpi_invoice; |
225 | 225 | } else { // create invoice |
226 | - $user_info = get_userdata( $invoice_info->user_id ); |
|
226 | + $user_info = get_userdata($invoice_info->user_id); |
|
227 | 227 | |
228 | - if ( !empty( $pre_status ) ) { |
|
228 | + if (!empty($pre_status)) { |
|
229 | 229 | $invoice_info->status = $pre_status; |
230 | 230 | } |
231 | - $status = wpinv_gdp_to_wpi_status( $invoice_info->status ); |
|
231 | + $status = wpinv_gdp_to_wpi_status($invoice_info->status); |
|
232 | 232 | |
233 | 233 | $wpi_zero_tax = false; |
234 | 234 | |
235 | - if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
235 | + if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
236 | 236 | $wpi_zero_tax = true; |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice_data = array(); |
240 | 240 | $invoice_data['invoice_id'] = $wpi_invoice_id; |
241 | 241 | $invoice_data['status'] = $status; |
242 | - if ( $update ) { |
|
242 | + if ($update) { |
|
243 | 243 | //$invoice_data['private_note'] = __( 'Invoice was updated.', 'invoicing' ); |
244 | 244 | } else { |
245 | - $invoice_data['private_note'] = wp_sprintf( __( 'Invoice was created with status %s.', 'invoicing' ), wpinv_status_nicename( $status ) ); |
|
245 | + $invoice_data['private_note'] = wp_sprintf(__('Invoice was created with status %s.', 'invoicing'), wpinv_status_nicename($status)); |
|
246 | 246 | } |
247 | 247 | $invoice_data['user_id'] = $invoice_info->user_id; |
248 | 248 | $invoice_data['created_via'] = 'API'; |
249 | 249 | |
250 | - if ( !empty( $invoice_info->date ) ) { |
|
251 | - $invoice_data['created_date'] = $invoice_info->date; |
|
250 | + if (!empty($invoice_info->date)) { |
|
251 | + $invoice_data['created_date'] = $invoice_info->date; |
|
252 | 252 | } |
253 | 253 | |
254 | - $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
255 | - $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod ); |
|
256 | - $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod ); |
|
254 | + $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
255 | + $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod); |
|
256 | + $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod); |
|
257 | 257 | |
258 | 258 | $invoice_data['payment_details'] = array( |
259 | 259 | 'gateway' => $paymentmethod, |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | 'paid' => $status === 'publish' ? true : false |
263 | 263 | ); |
264 | 264 | |
265 | - $user_address = wpinv_get_user_address( $invoice_info->user_id, false ); |
|
265 | + $user_address = wpinv_get_user_address($invoice_info->user_id, false); |
|
266 | 266 | |
267 | 267 | $invoice_data['user_info'] = array( |
268 | 268 | 'user_id' => $invoice_info->user_id, |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | |
286 | 286 | $post_item = wpinv_get_gd_package_item($invoice_info->package_id); |
287 | 287 | |
288 | - if ( !empty( $post_item ) ) { |
|
289 | - $cart_details = array(); |
|
288 | + if (!empty($post_item)) { |
|
289 | + $cart_details = array(); |
|
290 | 290 | $cart_details[] = array( |
291 | 291 | 'id' => $post_item->ID, |
292 | 292 | 'name' => $post_item->get_name(), |
@@ -299,19 +299,19 @@ discard block |
||
299 | 299 | ), |
300 | 300 | ); |
301 | 301 | |
302 | - $invoice_data['cart_details'] = $cart_details; |
|
302 | + $invoice_data['cart_details'] = $cart_details; |
|
303 | 303 | } |
304 | 304 | |
305 | - $data = array( 'invoice' => $invoice_data ); |
|
305 | + $data = array('invoice' => $invoice_data); |
|
306 | 306 | |
307 | 307 | $wpinv_api = new WPInv_API(); |
308 | - $data = $wpinv_api->insert_invoice( $data ); |
|
308 | + $data = $wpinv_api->insert_invoice($data); |
|
309 | 309 | |
310 | - if ( is_wp_error( $data ) ) { |
|
311 | - wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() ); |
|
310 | + if (is_wp_error($data)) { |
|
311 | + wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message()); |
|
312 | 312 | } else { |
313 | - if ( !empty( $data ) ) { |
|
314 | - update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id ); |
|
313 | + if (!empty($data)) { |
|
314 | + update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id); |
|
315 | 315 | |
316 | 316 | global $wpi_userID, $wpinv_ip_address_country; |
317 | 317 | |
@@ -319,21 +319,21 @@ discard block |
||
319 | 319 | |
320 | 320 | $data_session = array(); |
321 | 321 | $data_session['invoice_id'] = $data->ID; |
322 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
322 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
323 | 323 | |
324 | - wpinv_set_checkout_session( $data_session ); |
|
324 | + wpinv_set_checkout_session($data_session); |
|
325 | 325 | |
326 | 326 | $wpi_userID = (int)$data->get_user_id(); |
327 | 327 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
328 | 328 | |
329 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
330 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
329 | + $data->country = sanitize_text_field($_POST['country']); |
|
330 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
331 | 331 | |
332 | 332 | $wpinv_ip_address_country = $data->country; |
333 | 333 | |
334 | 334 | $data = $data->recalculate_totals(true); |
335 | 335 | |
336 | - wpinv_set_checkout_session( $checkout_session ); |
|
336 | + wpinv_set_checkout_session($checkout_session); |
|
337 | 337 | |
338 | 338 | $update_data = array(); |
339 | 339 | $update_data['tax_amount'] = $data->get_tax(); |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | $update_data['invoice_id'] = $data->ID; |
342 | 342 | |
343 | 343 | global $wpdb; |
344 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) ); |
|
344 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id)); |
|
345 | 345 | |
346 | 346 | return $data; |
347 | 347 | } else { |
348 | - if ( $update ) { |
|
349 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) ); |
|
348 | + if ($update) { |
|
349 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing')); |
|
350 | 350 | } else { |
351 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) ); |
|
351 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing')); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | } |
@@ -359,59 +359,59 @@ discard block |
||
359 | 359 | } |
360 | 360 | add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3); |
361 | 361 | |
362 | -function wpinv_cpt_update( $invoice_id ) { |
|
363 | - return wpinv_cpt_save( $invoice_id, true ); |
|
362 | +function wpinv_cpt_update($invoice_id) { |
|
363 | + return wpinv_cpt_save($invoice_id, true); |
|
364 | 364 | } |
365 | 365 | add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1); |
366 | 366 | |
367 | -function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) { |
|
368 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
369 | - if ( empty( $invoice_info ) ) { |
|
367 | +function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) { |
|
368 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
369 | + if (empty($invoice_info)) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | - $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
374 | - if ( !empty( $invoice ) ) { |
|
373 | + $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
374 | + if (!empty($invoice)) { |
|
375 | 375 | $new_status = wpinv_gdp_to_wpi_status($new_status); |
376 | - $invoice = wpinv_update_payment_status( $invoice->ID, $new_status ); |
|
376 | + $invoice = wpinv_update_payment_status($invoice->ID, $new_status); |
|
377 | 377 | } else { |
378 | - $invoice = wpinv_cpt_save( $invoice_id ); |
|
378 | + $invoice = wpinv_cpt_save($invoice_id); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | return $invoice; |
382 | 382 | } |
383 | -add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
383 | +add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
384 | 384 | |
385 | -function wpinv_transaction_details_note( $invoice_id, $html ) { |
|
386 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
387 | - if ( empty( $invoice_info ) ) { |
|
385 | +function wpinv_transaction_details_note($invoice_id, $html) { |
|
386 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
387 | + if (empty($invoice_info)) { |
|
388 | 388 | return false; |
389 | 389 | } |
390 | 390 | |
391 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL; |
|
391 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL; |
|
392 | 392 | |
393 | - if ( !$wpi_invoice_id ) { |
|
394 | - $invoice = wpinv_cpt_save( $invoice_id, false, $old_status ); |
|
393 | + if (!$wpi_invoice_id) { |
|
394 | + $invoice = wpinv_cpt_save($invoice_id, false, $old_status); |
|
395 | 395 | |
396 | - if ( !empty( $invoice ) ) { |
|
396 | + if (!empty($invoice)) { |
|
397 | 397 | $wpi_invoice_id = $invoice->ID; |
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | - $invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
401 | + $invoice = wpinv_get_invoice($wpi_invoice_id); |
|
402 | 402 | |
403 | - if ( empty( $invoice ) ) { |
|
403 | + if (empty($invoice)) { |
|
404 | 404 | return false; |
405 | 405 | } |
406 | 406 | |
407 | - return $invoice->add_note( $html, true ); |
|
407 | + return $invoice->add_note($html, true); |
|
408 | 408 | } |
409 | -add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 ); |
|
409 | +add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2); |
|
410 | 410 | |
411 | -function wpinv_gdp_to_wpi_status( $status ) { |
|
411 | +function wpinv_gdp_to_wpi_status($status) { |
|
412 | 412 | $inv_status = $status ? $status : 'pending'; |
413 | 413 | |
414 | - switch ( $status ) { |
|
414 | + switch ($status) { |
|
415 | 415 | case 'confirmed': |
416 | 416 | $inv_status = 'publish'; |
417 | 417 | break; |
@@ -420,10 +420,10 @@ discard block |
||
420 | 420 | return $inv_status; |
421 | 421 | } |
422 | 422 | |
423 | -function wpinv_wpi_to_gdp_status( $status ) { |
|
423 | +function wpinv_wpi_to_gdp_status($status) { |
|
424 | 424 | $inv_status = $status ? $status : 'pending'; |
425 | 425 | |
426 | - switch ( $status ) { |
|
426 | + switch ($status) { |
|
427 | 427 | case 'publish': |
428 | 428 | case 'wpi-processing': |
429 | 429 | case 'wpi-renewal': |
@@ -434,98 +434,98 @@ discard block |
||
434 | 434 | return $inv_status; |
435 | 435 | } |
436 | 436 | |
437 | -function wpinv_wpi_to_gdp_id( $invoice_id ) { |
|
437 | +function wpinv_wpi_to_gdp_id($invoice_id) { |
|
438 | 438 | global $wpdb; |
439 | 439 | |
440 | - return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) ); |
|
440 | + return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id))); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_gdp_to_wpi_id( $invoice_id ) { |
|
444 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
445 | - return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false); |
|
443 | +function wpinv_gdp_to_wpi_id($invoice_id) { |
|
444 | + $invoice = geodir_get_invoice($invoice_id); |
|
445 | + return (empty($invoice->invoice_id) ? $invoice->invoice_id : false); |
|
446 | 446 | } |
447 | 447 | |
448 | -function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) { |
|
448 | +function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) { |
|
449 | 449 | global $wpdb; |
450 | 450 | |
451 | - if ( !empty( $wpi_nosave ) ) { |
|
451 | + if (!empty($wpi_nosave)) { |
|
452 | 452 | return; |
453 | 453 | } |
454 | 454 | |
455 | - $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID ); |
|
455 | + $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID); |
|
456 | 456 | |
457 | - if ( $gdp_invoice_id > 0 ) { |
|
457 | + if ($gdp_invoice_id > 0) { |
|
458 | 458 | $update_data = array(); |
459 | 459 | $update_data['tax_amount'] = $invoice->tax; |
460 | 460 | $update_data['paied_amount'] = $invoice->total; |
461 | 461 | $update_data['discount'] = $invoice->discount; |
462 | 462 | $update_data['coupon_code'] = $invoice->discount_code; |
463 | 463 | |
464 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) ); |
|
464 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id)); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | return; |
468 | 468 | } |
469 | 469 | //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 ); |
470 | 470 | |
471 | -function wpinv_gdp_to_wpi_invoice( $invoice_id ) { |
|
472 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
473 | - if ( empty( $invoice->invoice_id ) ) { |
|
471 | +function wpinv_gdp_to_wpi_invoice($invoice_id) { |
|
472 | + $invoice = geodir_get_invoice($invoice_id); |
|
473 | + if (empty($invoice->invoice_id)) { |
|
474 | 474 | return false; |
475 | 475 | } |
476 | 476 | |
477 | - return wpinv_get_invoice( $invoice->invoice_id ); |
|
477 | + return wpinv_get_invoice($invoice->invoice_id); |
|
478 | 478 | } |
479 | 479 | |
480 | -function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) { |
|
481 | - $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id ); |
|
482 | - if ( empty( $invoice ) ) { |
|
480 | +function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) { |
|
481 | + $invoice = wpinv_gdp_to_wpi_invoice($invoice_id); |
|
482 | + if (empty($invoice)) { |
|
483 | 483 | return $status; |
484 | 484 | } |
485 | 485 | |
486 | - if ( $status === 1 || $status === 0 ) { |
|
487 | - if ( $status === 1 ) { |
|
488 | - $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() ); |
|
486 | + if ($status === 1 || $status === 0) { |
|
487 | + if ($status === 1) { |
|
488 | + $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal()); |
|
489 | 489 | } else { |
490 | 490 | $discount = ''; |
491 | 491 | $coupon_code = ''; |
492 | 492 | } |
493 | 493 | |
494 | - $invoice->set( 'discount', $discount ); |
|
495 | - $invoice->set( 'discount_code', $coupon_code ); |
|
494 | + $invoice->set('discount', $discount); |
|
495 | + $invoice->set('discount_code', $coupon_code); |
|
496 | 496 | $invoice->save(); |
497 | 497 | $invoice->recalculate_total(); |
498 | 498 | } |
499 | 499 | |
500 | 500 | return $status; |
501 | 501 | } |
502 | -add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 ); |
|
502 | +add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3); |
|
503 | 503 | |
504 | -function wpinv_insert_invoice( $invoice_data = array() ) { |
|
505 | - if ( empty( $invoice_data ) ) { |
|
504 | +function wpinv_insert_invoice($invoice_data = array()) { |
|
505 | + if (empty($invoice_data)) { |
|
506 | 506 | return false; |
507 | 507 | } |
508 | 508 | |
509 | 509 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
510 | 510 | $default_args = array( |
511 | - 'status' => !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending', |
|
512 | - 'user_note' => !empty( $invoice_data['note'] ) ? $invoice_data['note'] : null, |
|
513 | - 'invoice_id' => !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0, |
|
514 | - 'user_id' => !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(), |
|
511 | + 'status' => !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending', |
|
512 | + 'user_note' => !empty($invoice_data['note']) ? $invoice_data['note'] : null, |
|
513 | + 'invoice_id' => !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0, |
|
514 | + 'user_id' => !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(), |
|
515 | 515 | ); |
516 | 516 | |
517 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data ); |
|
518 | - if ( is_wp_error( $invoice ) ) { |
|
517 | + $invoice = wpinv_create_invoice($default_args, $invoice_data); |
|
518 | + if (is_wp_error($invoice)) { |
|
519 | 519 | return $invoice; |
520 | 520 | } |
521 | 521 | |
522 | - $gateway = !empty( $invoice_data['gateway'] ) ? $invoice_data['gateway'] : ''; |
|
523 | - $gateway = empty( $gateway ) && isset( $_POST['gateway'] ) ? $_POST['gateway'] : $gateway; |
|
522 | + $gateway = !empty($invoice_data['gateway']) ? $invoice_data['gateway'] : ''; |
|
523 | + $gateway = empty($gateway) && isset($_POST['gateway']) ? $_POST['gateway'] : $gateway; |
|
524 | 524 | |
525 | - if ( !empty( $gateway ) ) { |
|
526 | - $gateway = wpinv_gdp_to_wpi_gateway( $gateway ); |
|
525 | + if (!empty($gateway)) { |
|
526 | + $gateway = wpinv_gdp_to_wpi_gateway($gateway); |
|
527 | 527 | $invoice_data['payment_details']['gateway'] = $gateway; |
528 | - $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title( $gateway ); |
|
528 | + $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title($gateway); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | $user_info = array( |
@@ -546,67 +546,67 @@ discard block |
||
546 | 546 | 'discount' => array(), |
547 | 547 | ); |
548 | 548 | |
549 | - $user_info = wp_parse_args( $invoice_data['user_info'], $user_info ); |
|
549 | + $user_info = wp_parse_args($invoice_data['user_info'], $user_info); |
|
550 | 550 | |
551 | 551 | $payment_details = array(); |
552 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
552 | + if (!empty($invoice_data['payment_details'])) { |
|
553 | 553 | $payment_details = array( |
554 | 554 | 'gateway' => 'manual', |
555 | - 'gateway_title' => __( 'Manual Payment', 'invoicing' ), |
|
555 | + 'gateway_title' => __('Manual Payment', 'invoicing'), |
|
556 | 556 | 'currency' => geodir_get_currency_type(), |
557 | 557 | 'paid' => false, |
558 | 558 | 'transaction_id' => '', |
559 | 559 | ); |
560 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $payment_details ); |
|
560 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $payment_details); |
|
561 | 561 | } |
562 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) ); |
|
563 | - if ( !empty( $payment_details ) ) { |
|
564 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
565 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
566 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
567 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
562 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending')); |
|
563 | + if (!empty($payment_details)) { |
|
564 | + $invoice->set('currency', $payment_details['currency']); |
|
565 | + $invoice->set('gateway', $payment_details['gateway']); |
|
566 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
567 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
568 | 568 | } |
569 | 569 | |
570 | - $invoice->set( 'user_info', $user_info ); |
|
570 | + $invoice->set('user_info', $user_info); |
|
571 | 571 | ///$invoice->set( 'user_id', $user_info['user_id'] ); |
572 | 572 | ///$invoice->set( 'email', $user_info['email'] ); |
573 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
574 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
575 | - $invoice->set( 'address', $user_info['address'] ); |
|
576 | - $invoice->set( 'company', $user_info['company'] ); |
|
577 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
578 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
579 | - $invoice->set( 'city', $user_info['city'] ); |
|
580 | - $invoice->set( 'country', $user_info['country'] ); |
|
581 | - $invoice->set( 'state', $user_info['state'] ); |
|
582 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
583 | - $invoice->set( 'discounts', ( !empty( $user_info['discount'] ) ? $user_info['discount'] : array() ) ); |
|
584 | - $invoice->set( 'ip', wpinv_get_ip() ); |
|
585 | - if ( !empty( $invoice_data['invoice_key'] ) ) { |
|
586 | - $invoice->set( 'key', $invoice_data['invoice_key'] ); |
|
573 | + $invoice->set('first_name', $user_info['first_name']); |
|
574 | + $invoice->set('last_name', $user_info['last_name']); |
|
575 | + $invoice->set('address', $user_info['address']); |
|
576 | + $invoice->set('company', $user_info['company']); |
|
577 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
578 | + $invoice->set('phone', $user_info['phone']); |
|
579 | + $invoice->set('city', $user_info['city']); |
|
580 | + $invoice->set('country', $user_info['country']); |
|
581 | + $invoice->set('state', $user_info['state']); |
|
582 | + $invoice->set('zip', $user_info['zip']); |
|
583 | + $invoice->set('discounts', (!empty($user_info['discount']) ? $user_info['discount'] : array())); |
|
584 | + $invoice->set('ip', wpinv_get_ip()); |
|
585 | + if (!empty($invoice_data['invoice_key'])) { |
|
586 | + $invoice->set('key', $invoice_data['invoice_key']); |
|
587 | 587 | } |
588 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
589 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
588 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
589 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
590 | 590 | |
591 | 591 | // Add note |
592 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
593 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
592 | + if (!empty($invoice_data['user_note'])) { |
|
593 | + $invoice->add_note($invoice_data['user_note'], true); |
|
594 | 594 | } |
595 | 595 | |
596 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
597 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
596 | + if (!empty($invoice_data['private_note'])) { |
|
597 | + $invoice->add_note($invoice_data['private_note']); |
|
598 | 598 | } |
599 | 599 | |
600 | - if ( is_array( $invoice_data['cart_details'] ) && !empty( $invoice_data['cart_details'] ) ) { |
|
601 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
602 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
603 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
604 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
605 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
600 | + if (is_array($invoice_data['cart_details']) && !empty($invoice_data['cart_details'])) { |
|
601 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
602 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
603 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
604 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
605 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
606 | 606 | |
607 | - $post_item = new WPInv_Item( $item_id ); |
|
608 | - if ( !empty( $post_item ) ) { |
|
609 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
607 | + $post_item = new WPInv_Item($item_id); |
|
608 | + if (!empty($post_item)) { |
|
609 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
610 | 610 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
611 | 611 | } else { |
612 | 612 | continue; |
@@ -616,33 +616,33 @@ discard block |
||
616 | 616 | 'name' => $name, |
617 | 617 | 'quantity' => $quantity, |
618 | 618 | 'item_price' => $item_price, |
619 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
620 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
621 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
622 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
619 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
620 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
621 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
622 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
623 | 623 | ); |
624 | 624 | |
625 | - $invoice->add_item( $item_id, $args ); |
|
625 | + $invoice->add_item($item_id, $args); |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
629 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
629 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
630 | 630 | |
631 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
632 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
631 | + if (isset($invoice_data['post_date'])) { |
|
632 | + $invoice->set('date', $invoice_data['post_date']); |
|
633 | 633 | } |
634 | 634 | |
635 | - $number = wpinv_format_invoice_number( $invoice->ID ); |
|
636 | - $invoice->set( 'number', $number ); |
|
637 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
635 | + $number = wpinv_format_invoice_number($invoice->ID); |
|
636 | + $invoice->set('number', $number); |
|
637 | + update_option('wpinv_last_invoice_number', $number); |
|
638 | 638 | |
639 | 639 | $invoice->save(); |
640 | 640 | |
641 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
641 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
642 | 642 | |
643 | - if ( ! empty( $invoice->ID ) ) { |
|
643 | + if (!empty($invoice->ID)) { |
|
644 | 644 | // payment method (and payment_complete() if `paid` == true) |
645 | - if ( !empty( $payment_details['paid'] ) ) { |
|
645 | + if (!empty($payment_details['paid'])) { |
|
646 | 646 | //$invoice->payment_complete( !empty( $payment_details['transaction_id'] ) ? $payment_details['transaction_id'] : $invoice->ID ); |
647 | 647 | } |
648 | 648 | |
@@ -659,158 +659,158 @@ discard block |
||
659 | 659 | } |
660 | 660 | ?> |
661 | 661 | <tr> |
662 | - <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td> |
|
663 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td> |
|
664 | - <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
662 | + <td><?php _e('Merge Price Packages', 'invoicing'); ?></td> |
|
663 | + <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td> |
|
664 | + <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
665 | 665 | </tr> |
666 | 666 | <tr> |
667 | - <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td> |
|
668 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td> |
|
669 | - <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
667 | + <td><?php _e('Merge Invoices', 'invoicing'); ?></td> |
|
668 | + <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td> |
|
669 | + <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
670 | 670 | </tr> |
671 | 671 | <tr> |
672 | - <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td> |
|
673 | - <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td> |
|
674 | - <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
672 | + <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td> |
|
673 | + <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td> |
|
674 | + <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
675 | 675 | </tr> |
676 | 676 | <tr> |
677 | - <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td> |
|
678 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td> |
|
679 | - <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
677 | + <td><?php _e('Merge Coupons', 'invoicing'); ?></td> |
|
678 | + <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td> |
|
679 | + <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
680 | 680 | </tr> |
681 | 681 | <?php |
682 | 682 | } |
683 | -add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 ); |
|
683 | +add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10); |
|
684 | 684 | |
685 | 685 | function wpinv_tool_merge_packages() { |
686 | 686 | $packages = geodir_package_list_info(); |
687 | 687 | |
688 | 688 | $count = 0; |
689 | 689 | |
690 | - if ( !empty( $packages ) ) { |
|
690 | + if (!empty($packages)) { |
|
691 | 691 | $success = true; |
692 | 692 | |
693 | - foreach ( $packages as $key => $package ) { |
|
693 | + foreach ($packages as $key => $package) { |
|
694 | 694 | $item = wpinv_get_item_by('package_id', $package->pid); |
695 | - if ( !empty( $item ) ) { |
|
695 | + if (!empty($item)) { |
|
696 | 696 | continue; |
697 | 697 | } |
698 | 698 | |
699 | - $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package ); |
|
699 | + $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package); |
|
700 | 700 | |
701 | - if ( !empty( $merged ) ) { |
|
702 | - wpinv_error_log( 'Package merge S : ' . $package->pid ); |
|
701 | + if (!empty($merged)) { |
|
702 | + wpinv_error_log('Package merge S : ' . $package->pid); |
|
703 | 703 | $count++; |
704 | 704 | } else { |
705 | - wpinv_error_log( 'Package merge F : ' . $package->pid ); |
|
705 | + wpinv_error_log('Package merge F : ' . $package->pid); |
|
706 | 706 | } |
707 | 707 | } |
708 | 708 | |
709 | - if ( $count > 0 ) { |
|
710 | - $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count ); |
|
709 | + if ($count > 0) { |
|
710 | + $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count); |
|
711 | 711 | } else { |
712 | - $message = __( 'No price packages merged.', 'invoicing' ); |
|
712 | + $message = __('No price packages merged.', 'invoicing'); |
|
713 | 713 | } |
714 | 714 | } else { |
715 | 715 | $success = false; |
716 | - $message = __( 'No price packages found to merge!', 'invoicing' ); |
|
716 | + $message = __('No price packages found to merge!', 'invoicing'); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | $response = array(); |
720 | 720 | $response['success'] = $success; |
721 | 721 | $response['data']['message'] = $message; |
722 | - wp_send_json( $response ); |
|
722 | + wp_send_json($response); |
|
723 | 723 | } |
724 | -add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' ); |
|
724 | +add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages'); |
|
725 | 725 | |
726 | 726 | function wpinv_tool_merge_invoices() { |
727 | 727 | global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates; |
728 | 728 | |
729 | 729 | $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC"; |
730 | - $items = $wpdb->get_results( $sql ); |
|
730 | + $items = $wpdb->get_results($sql); |
|
731 | 731 | |
732 | 732 | $count = 0; |
733 | 733 | |
734 | - if ( !empty( $items ) ) { |
|
734 | + if (!empty($items)) { |
|
735 | 735 | $success = true; |
736 | 736 | $wpi_gdp_inv_merge = true; |
737 | 737 | |
738 | - foreach ( $items as $item ) { |
|
738 | + foreach ($items as $item) { |
|
739 | 739 | $wpi_tax_rates = NULL; |
740 | 740 | |
741 | - $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" ); |
|
741 | + $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'"); |
|
742 | 742 | |
743 | - $merged = wpinv_cpt_save( $item->id ); |
|
743 | + $merged = wpinv_cpt_save($item->id); |
|
744 | 744 | |
745 | - if ( !empty( $merged ) && !empty( $merged->ID ) ) { |
|
745 | + if (!empty($merged) && !empty($merged->ID)) { |
|
746 | 746 | $count++; |
747 | 747 | |
748 | 748 | //$wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = '" . $merged->ID . "' WHERE id = '" . $item->id . "'" ); |
749 | 749 | |
750 | - $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' ); |
|
751 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
752 | - $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
753 | - $post_modified_gmt = get_gmt_from_date( $post_modified ); |
|
750 | + $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql'); |
|
751 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
752 | + $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
753 | + $post_modified_gmt = get_gmt_from_date($post_modified); |
|
754 | 754 | |
755 | - $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) ); |
|
755 | + $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID)); |
|
756 | 756 | |
757 | - if ( $merged->is_paid() ) { |
|
758 | - update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified ); |
|
757 | + if ($merged->is_paid()) { |
|
758 | + update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified); |
|
759 | 759 | } |
760 | 760 | |
761 | - clean_post_cache( $merged->ID ); |
|
761 | + clean_post_cache($merged->ID); |
|
762 | 762 | |
763 | - wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID ); |
|
763 | + wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID); |
|
764 | 764 | } else { |
765 | - wpinv_error_log( 'Invoice merge F : ' . $item->id ); |
|
765 | + wpinv_error_log('Invoice merge F : ' . $item->id); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
769 | 769 | $wpi_gdp_inv_merge = false; |
770 | 770 | |
771 | - if ( $count > 0 ) { |
|
772 | - $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count ); |
|
771 | + if ($count > 0) { |
|
772 | + $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count); |
|
773 | 773 | } else { |
774 | - $message = __( 'No invoices merged.', 'invoicing' ); |
|
774 | + $message = __('No invoices merged.', 'invoicing'); |
|
775 | 775 | } |
776 | 776 | } else { |
777 | 777 | $success = false; |
778 | - $message = __( 'No invoices found to merge!', 'invoicing' ); |
|
778 | + $message = __('No invoices found to merge!', 'invoicing'); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | $response = array(); |
782 | 782 | $response['success'] = $success; |
783 | 783 | $response['data']['message'] = $message; |
784 | - wp_send_json( $response ); |
|
784 | + wp_send_json($response); |
|
785 | 785 | } |
786 | -add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' ); |
|
786 | +add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices'); |
|
787 | 787 | |
788 | 788 | function wpinv_tool_merge_coupons() { |
789 | 789 | global $wpdb; |
790 | 790 | |
791 | 791 | $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC"; |
792 | - $items = $wpdb->get_results( $sql ); |
|
792 | + $items = $wpdb->get_results($sql); |
|
793 | 793 | $count = 0; |
794 | 794 | |
795 | - if ( !empty( $items ) ) { |
|
795 | + if (!empty($items)) { |
|
796 | 796 | $success = true; |
797 | 797 | |
798 | - foreach ( $items as $item ) { |
|
799 | - if ( wpinv_get_discount_by_code( $item->coupon_code ) ) { |
|
798 | + foreach ($items as $item) { |
|
799 | + if (wpinv_get_discount_by_code($item->coupon_code)) { |
|
800 | 800 | continue; |
801 | 801 | } |
802 | 802 | |
803 | 803 | $args = array( |
804 | 804 | 'post_type' => 'wpi_discount', |
805 | 805 | 'post_title' => $item->coupon_code, |
806 | - 'post_status' => !empty( $item->status ) ? 'publish' : 'pending' |
|
806 | + 'post_status' => !empty($item->status) ? 'publish' : 'pending' |
|
807 | 807 | ); |
808 | 808 | |
809 | - $merged = wp_insert_post( $args ); |
|
809 | + $merged = wp_insert_post($args); |
|
810 | 810 | |
811 | 811 | $item_id = $item->cid; |
812 | 812 | |
813 | - if ( $merged ) { |
|
813 | + if ($merged) { |
|
814 | 814 | $meta = array( |
815 | 815 | 'code' => $item->coupon_code, |
816 | 816 | 'type' => $item->discount_type != 'per' ? 'flat' : 'percent', |
@@ -818,65 +818,65 @@ discard block |
||
818 | 818 | 'max_uses' => (int)$item->usage_limit, |
819 | 819 | 'uses' => (int)$item->usage_count, |
820 | 820 | ); |
821 | - wpinv_store_discount( $merged, $meta, get_post( $merged ) ); |
|
821 | + wpinv_store_discount($merged, $meta, get_post($merged)); |
|
822 | 822 | |
823 | 823 | $count++; |
824 | 824 | |
825 | - wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged ); |
|
825 | + wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged); |
|
826 | 826 | } else { |
827 | - wpinv_error_log( 'Coupon merge F : ' . $item_id ); |
|
827 | + wpinv_error_log('Coupon merge F : ' . $item_id); |
|
828 | 828 | } |
829 | 829 | } |
830 | 830 | |
831 | - if ( $count > 0 ) { |
|
832 | - $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count ); |
|
831 | + if ($count > 0) { |
|
832 | + $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count); |
|
833 | 833 | } else { |
834 | - $message = __( 'No coupons merged.', 'invoicing' ); |
|
834 | + $message = __('No coupons merged.', 'invoicing'); |
|
835 | 835 | } |
836 | 836 | } else { |
837 | 837 | $success = false; |
838 | - $message = __( 'No coupons found to merge!', 'invoicing' ); |
|
838 | + $message = __('No coupons found to merge!', 'invoicing'); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | $response = array(); |
842 | 842 | $response['success'] = $success; |
843 | 843 | $response['data']['message'] = $message; |
844 | - wp_send_json( $response ); |
|
844 | + wp_send_json($response); |
|
845 | 845 | } |
846 | -add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' ); |
|
846 | +add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons'); |
|
847 | 847 | |
848 | -function wpinv_gdp_to_wpi_currency( $value, $option = '' ) { |
|
848 | +function wpinv_gdp_to_wpi_currency($value, $option = '') { |
|
849 | 849 | return wpinv_get_currency(); |
850 | 850 | } |
851 | -add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 ); |
|
851 | +add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2); |
|
852 | 852 | |
853 | -function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) { |
|
853 | +function wpinv_gdp_to_wpi_currency_sign($value, $option = '') { |
|
854 | 854 | return wpinv_currency_symbol(); |
855 | 855 | } |
856 | -add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 ); |
|
856 | +add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2); |
|
857 | 857 | |
858 | -function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) { |
|
859 | - if ( !$display ) { |
|
860 | - $price = wpinv_format_amount( $amount, NULL, true ); |
|
858 | +function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) { |
|
859 | + if (!$display) { |
|
860 | + $price = wpinv_format_amount($amount, NULL, true); |
|
861 | 861 | } else { |
862 | - $price = wpinv_price( wpinv_format_amount( $amount ) ); |
|
862 | + $price = wpinv_price(wpinv_format_amount($amount)); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | return $price; |
866 | 866 | } |
867 | -add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 ); |
|
867 | +add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5); |
|
868 | 868 | |
869 | -function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) { |
|
869 | +function wpinv_gdp_to_inv_checkout_redirect($redirect_url) { |
|
870 | 870 | $invoice_id = geodir_payment_cart_id(); |
871 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
872 | - $wpi_invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
871 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
872 | + $wpi_invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
873 | 873 | |
874 | - if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) { |
|
875 | - $wpi_invoice_id = wpinv_cpt_save( $invoice_id ); |
|
876 | - $wpi_invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
874 | + if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) { |
|
875 | + $wpi_invoice_id = wpinv_cpt_save($invoice_id); |
|
876 | + $wpi_invoice = wpinv_get_invoice($wpi_invoice_id); |
|
877 | 877 | } |
878 | 878 | |
879 | - if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) { |
|
879 | + if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) { |
|
880 | 880 | |
881 | 881 | // Clear cart |
882 | 882 | geodir_payment_clear_cart(); |
@@ -886,121 +886,121 @@ discard block |
||
886 | 886 | |
887 | 887 | return $redirect_url; |
888 | 888 | } |
889 | -add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 ); |
|
889 | +add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1); |
|
890 | 890 | |
891 | -function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) { |
|
892 | - if ( get_current_user_id() ) { |
|
893 | - $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>'; |
|
891 | +function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) { |
|
892 | + if (get_current_user_id()) { |
|
893 | + $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>'; |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | return $dashboard_links; |
897 | 897 | } |
898 | -add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
|
899 | -remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
|
898 | +add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link'); |
|
899 | +remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link'); |
|
900 | 900 | |
901 | -function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
|
901 | +function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) { |
|
902 | 902 | if (!defined('GEODIRPAYMENT_VERSION')) { |
903 | 903 | return false; |
904 | 904 | } |
905 | 905 | |
906 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
907 | - if ( empty( $invoice ) ) { |
|
906 | + $invoice = wpinv_get_invoice($invoice_id); |
|
907 | + if (empty($invoice)) { |
|
908 | 908 | return false; |
909 | 909 | } |
910 | 910 | |
911 | - remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
911 | + remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
912 | 912 | |
913 | - $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id ); |
|
914 | - $new_status = wpinv_wpi_to_gdp_status( $new_status ); |
|
913 | + $invoice_id = wpinv_wpi_to_gdp_id($invoice_id); |
|
914 | + $new_status = wpinv_wpi_to_gdp_status($new_status); |
|
915 | 915 | |
916 | - geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() ); |
|
916 | + geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring()); |
|
917 | 917 | } |
918 | -add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 ); |
|
918 | +add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3); |
|
919 | 919 | |
920 | -function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) { |
|
921 | - $item = wpinv_get_item_by( 'package_id', $gd_package_id ); |
|
920 | +function wpinv_gdp_to_wpi_delete_package($gd_package_id) { |
|
921 | + $item = wpinv_get_item_by('package_id', $gd_package_id); |
|
922 | 922 | |
923 | - if ( !empty( $item ) ) { |
|
924 | - wpinv_remove_item( $item, true ); |
|
923 | + if (!empty($item)) { |
|
924 | + wpinv_remove_item($item, true); |
|
925 | 925 | } |
926 | 926 | } |
927 | -add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ; |
|
927 | +add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1); |
|
928 | 928 | |
929 | -function wpinv_can_delete_package_item( $return, $post_id ) { |
|
930 | - if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_package_id', true ) ) { |
|
931 | - $gd_package = geodir_get_package_info_by_id( $package_id, '' ); |
|
929 | +function wpinv_can_delete_package_item($return, $post_id) { |
|
930 | + if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_package_id', true)) { |
|
931 | + $gd_package = geodir_get_package_info_by_id($package_id, ''); |
|
932 | 932 | |
933 | - if ( !empty( $gd_package ) ) { |
|
933 | + if (!empty($gd_package)) { |
|
934 | 934 | $return = false; |
935 | 935 | } |
936 | 936 | } |
937 | 937 | |
938 | 938 | return $return; |
939 | 939 | } |
940 | -add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 ); |
|
940 | +add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2); |
|
941 | 941 | |
942 | -function wpinv_package_item_classes( $classes, $class, $post_id ) { |
|
942 | +function wpinv_package_item_classes($classes, $class, $post_id) { |
|
943 | 943 | global $typenow; |
944 | 944 | |
945 | - if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) { |
|
946 | - if ( wpinv_item_in_use( $post_id ) ) { |
|
945 | + if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) { |
|
946 | + if (wpinv_item_in_use($post_id)) { |
|
947 | 947 | $classes[] = 'wpi-inuse-pkg'; |
948 | - } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_package_id', true ), '' ) ) ) { |
|
948 | + } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_package_id', true), ''))) { |
|
949 | 949 | $classes[] = 'wpi-delete-pkg'; |
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
953 | 953 | return $classes; |
954 | 954 | } |
955 | -add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 ); |
|
955 | +add_filter('post_class', 'wpinv_package_item_classes', 10, 3); |
|
956 | 956 | |
957 | -function wpinv_gdp_package_type_info( $post ) { |
|
958 | - if ( wpinv_pm_active() ) { |
|
959 | - ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p> |
|
957 | +function wpinv_gdp_package_type_info($post) { |
|
958 | + if (wpinv_pm_active()) { |
|
959 | + ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p> |
|
960 | 960 | <?php |
961 | 961 | } |
962 | 962 | } |
963 | -add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ; |
|
963 | +add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1); |
|
964 | 964 | |
965 | -function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) { |
|
965 | +function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) { |
|
966 | 966 | global $wpi_zero_tax; |
967 | 967 | |
968 | - if ( $wpi_zero_tax ) { |
|
968 | + if ($wpi_zero_tax) { |
|
969 | 969 | $is_taxable = false; |
970 | 970 | } |
971 | 971 | |
972 | 972 | return $is_taxable; |
973 | 973 | } |
974 | -add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ; |
|
974 | +add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4); |
|
975 | 975 | |
976 | 976 | function wpinv_tool_merge_fix_taxes() { |
977 | 977 | global $wpdb; |
978 | 978 | |
979 | 979 | $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'"; |
980 | - $items = $wpdb->get_results( $sql ); |
|
980 | + $items = $wpdb->get_results($sql); |
|
981 | 981 | |
982 | - if ( !empty( $items ) ) { |
|
983 | - foreach ( $items as $item ) { |
|
984 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
985 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
982 | + if (!empty($items)) { |
|
983 | + foreach ($items as $item) { |
|
984 | + if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') { |
|
985 | + update_post_meta($item->ID, '_wpinv_vat_class', '_standard'); |
|
986 | 986 | } |
987 | 987 | } |
988 | 988 | } |
989 | 989 | |
990 | 990 | $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC"; |
991 | - $items = $wpdb->get_results( $sql ); |
|
991 | + $items = $wpdb->get_results($sql); |
|
992 | 992 | |
993 | - if ( !empty( $items ) ) { |
|
993 | + if (!empty($items)) { |
|
994 | 994 | $success = false; |
995 | - $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
|
995 | + $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing'); |
|
996 | 996 | |
997 | 997 | global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
998 | 998 | |
999 | - foreach ( $items as $item ) { |
|
999 | + foreach ($items as $item) { |
|
1000 | 1000 | $wpi_tax_rates = NULL; |
1001 | 1001 | $data = wpinv_get_invoice($item->ID); |
1002 | 1002 | |
1003 | - if ( empty( $data ) ) { |
|
1003 | + if (empty($data)) { |
|
1004 | 1004 | continue; |
1005 | 1005 | } |
1006 | 1006 | |
@@ -1008,51 +1008,51 @@ discard block |
||
1008 | 1008 | |
1009 | 1009 | $data_session = array(); |
1010 | 1010 | $data_session['invoice_id'] = $data->ID; |
1011 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
1011 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
1012 | 1012 | |
1013 | - wpinv_set_checkout_session( $data_session ); |
|
1013 | + wpinv_set_checkout_session($data_session); |
|
1014 | 1014 | |
1015 | 1015 | $wpi_userID = (int)$data->get_user_id(); |
1016 | 1016 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
1017 | 1017 | |
1018 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
1019 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
1018 | + $data->country = sanitize_text_field($_POST['country']); |
|
1019 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
1020 | 1020 | |
1021 | 1021 | $wpinv_ip_address_country = $data->country; |
1022 | 1022 | |
1023 | 1023 | $data->recalculate_totals(true); |
1024 | 1024 | |
1025 | - wpinv_set_checkout_session( $checkout_session ); |
|
1025 | + wpinv_set_checkout_session($checkout_session); |
|
1026 | 1026 | |
1027 | 1027 | $update_data = array(); |
1028 | 1028 | $update_data['tax_amount'] = $data->get_tax(); |
1029 | 1029 | $update_data['paied_amount'] = $data->get_total(); |
1030 | 1030 | $update_data['invoice_id'] = $data->ID; |
1031 | 1031 | |
1032 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
1032 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id)); |
|
1033 | 1033 | } |
1034 | 1034 | } else { |
1035 | 1035 | $success = false; |
1036 | - $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
|
1036 | + $message = __('No invoices found to fix taxes!', 'invoicing'); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | $response = array(); |
1040 | 1040 | $response['success'] = $success; |
1041 | 1041 | $response['data']['message'] = $message; |
1042 | - wp_send_json( $response ); |
|
1042 | + wp_send_json($response); |
|
1043 | 1043 | } |
1044 | -add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' ); |
|
1045 | -remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 ); |
|
1044 | +add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes'); |
|
1045 | +remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2); |
|
1046 | 1046 | |
1047 | -function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) { |
|
1048 | - if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) { |
|
1049 | - if ( $invoice->is_renewal() ) { |
|
1047 | +function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) { |
|
1048 | + if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) { |
|
1049 | + if ($invoice->is_renewal()) { |
|
1050 | 1050 | $invoice = $invoice->get_parent_payment(); |
1051 | 1051 | } |
1052 | 1052 | |
1053 | - if ( !empty( $invoice ) ) { |
|
1054 | - wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() ); |
|
1053 | + if (!empty($invoice)) { |
|
1054 | + wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status()); |
|
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | } |
1058 | -add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 ); |
|
1059 | 1058 | \ No newline at end of file |
1059 | +add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2); |
|
1060 | 1060 | \ No newline at end of file |