1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Contains functions related to Invoicing plugin. |
4
|
|
|
* |
5
|
|
|
* @since 1.0.0 |
6
|
|
|
* @package Invoicing |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
// MUST have WordPress. |
10
|
|
|
if ( !defined( 'WPINC' ) ) { |
11
|
|
|
exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
function wpinv_get_default_country() { |
16
|
|
|
$country = wpinv_get_option( 'default_country', 'UK' ); |
17
|
|
|
|
18
|
|
|
return apply_filters( 'wpinv_default_country', $country ); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Sanitizes a country code. |
23
|
|
|
* |
24
|
|
|
* @param string $country The country code to sanitize |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
function wpinv_sanitize_country( $country ) { |
28
|
|
|
|
29
|
|
|
// Enure the country is specified |
30
|
|
|
if ( empty( $country ) ) { |
31
|
|
|
$country = wpinv_get_default_country(); |
32
|
|
|
} |
33
|
|
|
return trim( wpinv_utf8_strtoupper( $country ) ); |
|
|
|
|
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function wpinv_is_base_country( $country ) { |
38
|
|
|
$base_country = wpinv_get_default_country(); |
39
|
|
|
|
40
|
|
|
if ( $base_country === 'UK' ) { |
41
|
|
|
$base_country = 'GB'; |
42
|
|
|
} |
43
|
|
|
if ( $country == 'UK' ) { |
44
|
|
|
$country = 'GB'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return ( $country && $country === $base_country ) ? true : false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function wpinv_country_name( $country_code = '' ) { |
51
|
|
|
$countries = wpinv_get_country_list(); |
52
|
|
|
$country_code = $country_code == 'UK' ? 'GB' : $country_code; |
53
|
|
|
$country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code; |
54
|
|
|
|
55
|
|
|
return apply_filters( 'wpinv_country_name', $country, $country_code ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function wpinv_get_default_state() { |
59
|
|
|
$state = wpinv_get_option( 'default_state', false ); |
60
|
|
|
|
61
|
|
|
return apply_filters( 'wpinv_default_state', $state ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function wpinv_state_name( $state_code = '', $country_code = '' ) { |
65
|
|
|
$state = $state_code; |
66
|
|
|
|
67
|
|
|
if ( !empty( $country_code ) ) { |
68
|
|
|
$states = wpinv_get_country_states( $country_code ); |
69
|
|
|
|
70
|
|
|
$state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function wpinv_store_address() { |
77
|
|
|
$address = wpinv_get_option( 'store_address', '' ); |
78
|
|
|
|
79
|
|
|
return apply_filters( 'wpinv_store_address', $address ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
83
|
|
|
global $wpi_userID; |
84
|
|
|
|
85
|
|
|
if( empty( $user_id ) ) { |
86
|
|
|
$user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$address_fields = array( |
90
|
|
|
///'user_id', |
91
|
|
|
'first_name', |
92
|
|
|
'last_name', |
93
|
|
|
'company', |
94
|
|
|
'vat_number', |
95
|
|
|
///'email', |
96
|
|
|
'phone', |
97
|
|
|
'address', |
98
|
|
|
'city', |
99
|
|
|
'state', |
100
|
|
|
'country', |
101
|
|
|
'zip', |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$user_info = get_userdata( $user_id ); |
105
|
|
|
|
106
|
|
|
$address = array(); |
107
|
|
|
$address['user_id'] = $user_id; |
108
|
|
|
$address['email'] = !empty( $user_info ) ? $user_info->user_email : ''; |
109
|
|
|
foreach ( $address_fields as $field ) { |
110
|
|
|
$address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ( !empty( $user_info ) ) { |
114
|
|
|
if( empty( $address['first_name'] ) ) |
115
|
|
|
$address['first_name'] = $user_info->first_name; |
116
|
|
|
|
117
|
|
|
if( empty( $address['last_name'] ) ) |
118
|
|
|
$address['last_name'] = $user_info->last_name; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," ); |
122
|
|
|
|
123
|
|
|
if( empty( $address['state'] ) && $with_default ) |
124
|
|
|
$address['state'] = wpinv_get_default_state(); |
125
|
|
|
|
126
|
|
|
if( empty( $address['country'] ) && $with_default ) |
127
|
|
|
$address['country'] = wpinv_get_default_country(); |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
return $address; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get all continents. |
135
|
|
|
* |
136
|
|
|
* @since 1.0.14 |
137
|
|
|
* @param string $return What to return. |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
function wpinv_get_continents( $return = 'all' ) { |
141
|
|
|
|
142
|
|
|
$continents = wpinv_get_data( 'continents' ); |
143
|
|
|
|
144
|
|
|
switch( $return ) { |
145
|
|
|
case 'name' : |
146
|
|
|
return wp_list_pluck( $continents, 'name' ); |
|
|
|
|
147
|
|
|
break; |
|
|
|
|
148
|
|
|
case 'countries' : |
149
|
|
|
return wp_list_pluck( $continents, 'countries' ); |
150
|
|
|
break; |
151
|
|
|
default : |
152
|
|
|
return $continents; |
|
|
|
|
153
|
|
|
break; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get continent code for a country code. |
160
|
|
|
* |
161
|
|
|
* @since 1.0.14 |
162
|
|
|
* @param string $country Country code. If no code is specified, defaults to the default country. |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
function wpinv_get_continent_code_for_country( $country = false ) { |
166
|
|
|
|
167
|
|
|
$country = wpinv_sanitize_country( $country ); |
|
|
|
|
168
|
|
|
|
169
|
|
|
foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
170
|
|
|
if ( false !== array_search( $country, $countries, true ) ) { |
171
|
|
|
return $continent_code; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
return ''; |
176
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get all calling codes. |
181
|
|
|
* |
182
|
|
|
* @since 1.0.14 |
183
|
|
|
* @param string $country Country code. If no code is specified, defaults to the default country. |
184
|
|
|
* @return array |
185
|
|
|
*/ |
186
|
|
|
function wpinv_get_country_calling_code( $country = null) { |
187
|
|
|
|
188
|
|
|
$country = wpinv_sanitize_country( $country ); |
189
|
|
|
$codes = wpinv_get_data( 'phone-codes' ); |
190
|
|
|
$code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
191
|
|
|
|
192
|
|
|
if ( is_array( $code ) ) { |
193
|
|
|
return $code[0]; |
194
|
|
|
} |
195
|
|
|
return $code; |
|
|
|
|
196
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Get all countries. |
201
|
|
|
* |
202
|
|
|
* @param bool $first_empty Whether or not the first item in the list should be empty |
203
|
|
|
* @return array |
204
|
|
|
*/ |
205
|
|
|
function wpinv_get_country_list( $first_empty = false ) { |
206
|
|
|
return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Retrieves a given country's states. |
211
|
|
|
* |
212
|
|
|
* @param string $country Country code. If no code is specified, defaults to the default country. |
213
|
|
|
* @param bool $first_empty Whether or not the first item in the list should be empty |
214
|
|
|
* @return array |
215
|
|
|
*/ |
216
|
|
|
function wpinv_get_country_states( $country = null, $first_empty = false ) { |
217
|
|
|
|
218
|
|
|
// Prepare the country. |
219
|
|
|
$country = wpinv_sanitize_country( $country ); |
220
|
|
|
|
221
|
|
|
// Fetch all states. |
222
|
|
|
$all_states = wpinv_get_data( 'states' ); |
223
|
|
|
|
224
|
|
|
// Fetch the specified country's states. |
225
|
|
|
$states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
226
|
|
|
$states = apply_filters( "wpinv_{$country}_states", $states ); |
227
|
|
|
$states = apply_filters( 'wpinv_country_states', $states, $country ); |
228
|
|
|
|
229
|
|
|
asort( $states ); |
230
|
|
|
|
231
|
|
|
return wpinv_maybe_add_empty_option( $states, $first_empty ); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Returns US states. |
236
|
|
|
* |
237
|
|
|
* @deprecated 1.0.14 |
238
|
|
|
* @return array |
239
|
|
|
*/ |
240
|
|
|
function wpinv_get_us_states_list() { |
241
|
|
|
return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Returns Canada states. |
246
|
|
|
* |
247
|
|
|
* @deprecated 1.0.14 |
248
|
|
|
* @return array |
249
|
|
|
*/ |
250
|
|
|
function wpinv_get_canada_states_list() { |
251
|
|
|
return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Returns australian states. |
256
|
|
|
* |
257
|
|
|
* @deprecated 1.0.14 |
258
|
|
|
* @return array |
259
|
|
|
*/ |
260
|
|
|
function wpinv_get_australia_states_list() { |
261
|
|
|
return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Returns bangladeshi states. |
266
|
|
|
* |
267
|
|
|
* @deprecated 1.0.14 |
268
|
|
|
* @return array |
269
|
|
|
*/ |
270
|
|
|
function wpinv_get_bangladesh_states_list() { |
271
|
|
|
return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Returns brazilianUS states. |
276
|
|
|
* |
277
|
|
|
* @deprecated 1.0.14 |
278
|
|
|
* @return array |
279
|
|
|
*/ |
280
|
|
|
function wpinv_get_brazil_states_list() { |
281
|
|
|
return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Returns bulgarian states. |
286
|
|
|
* |
287
|
|
|
* @deprecated 1.0.14 |
288
|
|
|
* @return array |
289
|
|
|
*/ |
290
|
|
|
function wpinv_get_bulgaria_states_list() { |
291
|
|
|
return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Returns hong kon states. |
296
|
|
|
* |
297
|
|
|
* @deprecated 1.0.14 |
298
|
|
|
* @return array |
299
|
|
|
*/ |
300
|
|
|
function wpinv_get_hong_kong_states_list() { |
301
|
|
|
return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Returns hungarian states. |
306
|
|
|
* |
307
|
|
|
* @deprecated 1.0.14 |
308
|
|
|
* @return array |
309
|
|
|
*/ |
310
|
|
|
function wpinv_get_hungary_states_list() { |
311
|
|
|
return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Returns japanese states. |
316
|
|
|
* |
317
|
|
|
* @deprecated 1.0.14 |
318
|
|
|
* @return array |
319
|
|
|
*/ |
320
|
|
|
function wpinv_get_japan_states_list() { |
321
|
|
|
return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Returns chinese states. |
326
|
|
|
* |
327
|
|
|
* @deprecated 1.0.14 |
328
|
|
|
* @return array |
329
|
|
|
*/ |
330
|
|
|
function wpinv_get_china_states_list() { |
331
|
|
|
return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Returns new zealand states. |
336
|
|
|
* |
337
|
|
|
* @deprecated 1.0.14 |
338
|
|
|
* @return array |
339
|
|
|
*/ |
340
|
|
|
function wpinv_get_new_zealand_states_list() { |
341
|
|
|
return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Returns perusian states. |
346
|
|
|
* |
347
|
|
|
* @deprecated 1.0.14 |
348
|
|
|
* @return array |
349
|
|
|
*/ |
350
|
|
|
function wpinv_get_peru_states_list() { |
351
|
|
|
return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Returns indonesian states. |
356
|
|
|
* |
357
|
|
|
* @deprecated 1.0.14 |
358
|
|
|
* @return array |
359
|
|
|
*/ |
360
|
|
|
function wpinv_get_indonesia_states_list() { |
361
|
|
|
return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Returns indian states. |
366
|
|
|
* |
367
|
|
|
* @deprecated 1.0.14 |
368
|
|
|
* @return array |
369
|
|
|
*/ |
370
|
|
|
function wpinv_get_india_states_list() { |
371
|
|
|
return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Returns iranian states. |
376
|
|
|
* |
377
|
|
|
* @deprecated 1.0.14 |
378
|
|
|
* @return array |
379
|
|
|
*/ |
380
|
|
|
function wpinv_get_iran_states_list() { |
381
|
|
|
return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Returns italian states. |
386
|
|
|
* |
387
|
|
|
* @deprecated 1.0.14 |
388
|
|
|
* @return array |
389
|
|
|
*/ |
390
|
|
|
function wpinv_get_italy_states_list() { |
391
|
|
|
return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Returns malaysian states. |
396
|
|
|
* |
397
|
|
|
* @deprecated 1.0.14 |
398
|
|
|
* @return array |
399
|
|
|
*/ |
400
|
|
|
function wpinv_get_malaysia_states_list() { |
401
|
|
|
return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Returns mexican states. |
406
|
|
|
* |
407
|
|
|
* @deprecated 1.0.14 |
408
|
|
|
* @return array |
409
|
|
|
*/ |
410
|
|
|
function wpinv_get_mexico_states_list() { |
411
|
|
|
return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Returns nepal states. |
416
|
|
|
* |
417
|
|
|
* @deprecated 1.0.14 |
418
|
|
|
* @return array |
419
|
|
|
*/ |
420
|
|
|
function wpinv_get_nepal_states_list() { |
421
|
|
|
return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Returns south african states. |
426
|
|
|
* |
427
|
|
|
* @deprecated 1.0.14 |
428
|
|
|
* @return array |
429
|
|
|
*/ |
430
|
|
|
function wpinv_get_south_africa_states_list() { |
431
|
|
|
return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Returns thailandese states. |
436
|
|
|
* |
437
|
|
|
* @deprecated 1.0.14 |
438
|
|
|
* @return array |
439
|
|
|
*/ |
440
|
|
|
function wpinv_get_thailand_states_list() { |
441
|
|
|
return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Returns turkish states. |
446
|
|
|
* |
447
|
|
|
* @deprecated 1.0.14 |
448
|
|
|
* @return array |
449
|
|
|
*/ |
450
|
|
|
function wpinv_get_turkey_states_list() { |
451
|
|
|
return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Returns spanish states. |
456
|
|
|
* |
457
|
|
|
* @deprecated 1.0.14 |
458
|
|
|
* @return array |
459
|
|
|
*/ |
460
|
|
|
function wpinv_get_spain_states_list() { |
461
|
|
|
return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
function wpinv_get_states_field() { |
465
|
|
|
if( empty( $_POST['country'] ) ) { |
466
|
|
|
$_POST['country'] = wpinv_get_default_country(); |
467
|
|
|
} |
468
|
|
|
$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
469
|
|
|
|
470
|
|
|
if( !empty( $states ) ) { |
471
|
|
|
$sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
472
|
|
|
|
473
|
|
|
$args = array( |
474
|
|
|
'name' => $sanitized_field_name, |
475
|
|
|
'id' => $sanitized_field_name, |
476
|
|
|
'class' => $sanitized_field_name . ' wpinv-select wpi_select2', |
477
|
|
|
'options' => array_merge( array( '' => '' ), $states ), |
478
|
|
|
'show_option_all' => false, |
479
|
|
|
'show_option_none' => false |
480
|
|
|
); |
481
|
|
|
|
482
|
|
|
$response = wpinv_html_select( $args ); |
483
|
|
|
|
484
|
|
|
} else { |
485
|
|
|
$response = 'nostates'; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
return $response; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
492
|
|
|
$country = !empty( $country ) ? $country : wpinv_get_default_country(); |
493
|
|
|
|
494
|
|
|
return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Returns country address formats. |
499
|
|
|
* |
500
|
|
|
* These define how addresses are formatted for display in various countries. |
501
|
|
|
* |
502
|
|
|
* @return array |
503
|
|
|
*/ |
504
|
|
|
function wpinv_get_address_formats() { |
505
|
|
|
|
506
|
|
|
return apply_filters( 'wpinv_localisation_address_formats', |
507
|
|
|
array( |
508
|
|
|
'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
509
|
|
|
'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
510
|
|
|
'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
511
|
|
|
'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
512
|
|
|
'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
513
|
|
|
'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
514
|
|
|
'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
515
|
|
|
'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
516
|
|
|
'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
517
|
|
|
'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
518
|
|
|
'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
519
|
|
|
'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
520
|
|
|
'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
521
|
|
|
'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
522
|
|
|
'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
523
|
|
|
'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
524
|
|
|
'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
525
|
|
|
'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
526
|
|
|
'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
527
|
|
|
'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
528
|
|
|
'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
529
|
|
|
'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
530
|
|
|
'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
531
|
|
|
'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
532
|
|
|
'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
533
|
|
|
'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
534
|
|
|
'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
535
|
|
|
'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
536
|
|
|
'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
537
|
|
|
'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
538
|
|
|
'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
539
|
|
|
'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
540
|
|
|
'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
541
|
|
|
'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
542
|
|
|
'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
543
|
|
|
'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
544
|
|
|
) |
545
|
|
|
); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Retrieves the address format to use on Invoices. |
550
|
|
|
* |
551
|
|
|
* @since 1.0.13 |
552
|
|
|
* @see `wpinv_get_invoice_address_replacements` |
553
|
|
|
* @return string |
554
|
|
|
*/ |
555
|
|
|
function wpinv_get_full_address_format( $country = false) { |
556
|
|
|
|
557
|
|
|
if( empty( $country ) ) { |
558
|
|
|
$country = wpinv_get_default_country(); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
// Get all formats. |
562
|
|
|
$formats = wpinv_get_address_formats(); |
563
|
|
|
|
564
|
|
|
// Get format for the specified country. |
565
|
|
|
$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Filters the address format to use on Invoices. |
569
|
|
|
* |
570
|
|
|
* New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
571
|
|
|
* |
572
|
|
|
* @since 1.0.13 |
573
|
|
|
* |
574
|
|
|
* @param string $format The address format to use. |
575
|
|
|
* @param string $country The country who's address format is being retrieved. |
576
|
|
|
*/ |
577
|
|
|
return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Retrieves the address format replacements to use on Invoices. |
582
|
|
|
* |
583
|
|
|
* @since 1.0.13 |
584
|
|
|
* @see `wpinv_get_full_address_format` |
585
|
|
|
* @param array $billing_details customer's billing details |
586
|
|
|
* @return array |
587
|
|
|
*/ |
588
|
|
|
function wpinv_get_invoice_address_replacements( $billing_details ) { |
589
|
|
|
|
590
|
|
|
$default_args = array( |
591
|
|
|
'address' => '', |
592
|
|
|
'city' => '', |
593
|
|
|
'state' => '', |
594
|
|
|
'country' => '', |
595
|
|
|
'zip' => '', |
596
|
|
|
'first_name' => '', |
597
|
|
|
'last_name' => '', |
598
|
|
|
'company' => '', |
599
|
|
|
); |
600
|
|
|
|
601
|
|
|
$args = array_map( 'trim', wp_parse_args( $billing_details, $default_args ) ); |
602
|
|
|
$state = $args['state']; |
603
|
|
|
$country = $args['country']; |
604
|
|
|
|
605
|
|
|
// Handle full country name. |
606
|
|
|
$full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
607
|
|
|
|
608
|
|
|
// Handle full state name. |
609
|
|
|
$full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
610
|
|
|
|
611
|
|
|
$args['postcode'] = $args['zip']; |
612
|
|
|
$args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
613
|
|
|
$args['state'] = $full_state; |
614
|
|
|
$args['state_code'] = $state; |
615
|
|
|
$args['country'] = $full_country; |
616
|
|
|
$args['country_code']= $country; |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* Filters the address format replacements to use on Invoices. |
620
|
|
|
* |
621
|
|
|
* |
622
|
|
|
* @since 1.0.13 |
623
|
|
|
* |
624
|
|
|
* @param array $replacements The address replacements to use. |
625
|
|
|
* @param array $billing_details The billing details to use. |
626
|
|
|
*/ |
627
|
|
|
$replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
628
|
|
|
|
629
|
|
|
$return = array(); |
630
|
|
|
|
631
|
|
|
foreach( $replacements as $key => $value ) { |
632
|
|
|
$value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
633
|
|
|
$return['{{' . $key . '}}'] = $value; |
634
|
|
|
$return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
return $return; |
638
|
|
|
|
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* Trim white space and commas off a line. |
643
|
|
|
* |
644
|
|
|
* @param string $line Line. |
645
|
|
|
* @since 1.0.14 |
646
|
|
|
* @return string |
647
|
|
|
*/ |
648
|
|
|
function wpinv_trim_formatted_address_line( $line ) { |
649
|
|
|
return trim( $line, ', ' ); |
650
|
|
|
} |