|
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
|
|
|
if ( !is_admin() ) { |
|
15
|
|
|
add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16
|
|
|
add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17
|
|
|
add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18
|
|
|
add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
function wpinv_template_path() { |
|
22
|
|
|
return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function wpinv_post_class( $classes, $class, $post_id ) { |
|
|
|
|
|
|
26
|
|
|
global $pagenow, $typenow; |
|
27
|
|
|
|
|
28
|
|
|
if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
29
|
|
|
$classes[] = 'wpi-gd-package'; |
|
30
|
|
|
} |
|
31
|
|
|
return $classes; |
|
32
|
|
|
} |
|
33
|
|
|
add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
34
|
|
|
|
|
35
|
|
|
function wpinv_display_invoice_top_bar( $invoice ) { |
|
36
|
|
|
if ( empty( $invoice ) ) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
?> |
|
40
|
|
|
<div class="row wpinv-top-bar no-print"> |
|
41
|
|
|
<div class="container"> |
|
42
|
|
|
<div class="col-xs-6"> |
|
43
|
|
|
<?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
44
|
|
|
</div> |
|
45
|
|
|
<div class="col-xs-6 text-right"> |
|
46
|
|
|
<?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
47
|
|
|
</div> |
|
48
|
|
|
</div> |
|
49
|
|
|
</div> |
|
50
|
|
|
<?php |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function wpinv_invoice_display_left_actions( $invoice ) { |
|
54
|
|
|
if ( empty( $invoice ) ) { |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if($invoice->post_type == 'wpi_invoice'){ |
|
59
|
|
|
|
|
60
|
|
|
$user_id = (int)$invoice->get_user_id(); |
|
61
|
|
|
$current_user_id = (int)get_current_user_id(); |
|
62
|
|
|
|
|
63
|
|
View Code Duplication |
if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
64
|
|
|
?> |
|
65
|
|
|
<a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
66
|
|
|
<?php |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
do_action('wpinv_invoice_display_left_actions', $invoice); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function wpinv_invoice_display_right_actions( $invoice ) { |
|
73
|
|
|
if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
74
|
|
|
|
|
75
|
|
|
if($invoice->post_type == 'wpi_invoice'){ |
|
76
|
|
|
$user_id = (int)$invoice->get_user_id(); |
|
77
|
|
|
$current_user_id = (int)get_current_user_id(); |
|
78
|
|
|
|
|
79
|
|
|
if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
80
|
|
|
?> |
|
81
|
|
|
<a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
82
|
|
|
<a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
83
|
|
|
<?php } |
|
84
|
|
|
} |
|
85
|
|
|
do_action('wpinv_invoice_display_right_actions', $invoice); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
View Code Duplication |
function wpinv_before_invoice_content( $content ) { |
|
|
|
|
|
|
89
|
|
|
global $post; |
|
90
|
|
|
|
|
91
|
|
|
if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
92
|
|
|
ob_start(); |
|
93
|
|
|
do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
94
|
|
|
$content = ob_get_clean() . $content; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $content; |
|
98
|
|
|
} |
|
99
|
|
|
add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
100
|
|
|
|
|
101
|
|
View Code Duplication |
function wpinv_after_invoice_content( $content ) { |
|
|
|
|
|
|
102
|
|
|
global $post; |
|
103
|
|
|
|
|
104
|
|
|
if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
105
|
|
|
ob_start(); |
|
106
|
|
|
do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
107
|
|
|
$content .= ob_get_clean(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return $content; |
|
111
|
|
|
} |
|
112
|
|
|
add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
113
|
|
|
|
|
114
|
|
|
function wpinv_get_templates_dir() { |
|
115
|
|
|
return WPINV_PLUGIN_DIR . 'templates'; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
function wpinv_get_templates_url() { |
|
119
|
|
|
return WPINV_PLUGIN_URL . 'templates'; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
123
|
|
|
if ( ! empty( $args ) && is_array( $args ) ) { |
|
124
|
|
|
extract( $args ); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
128
|
|
|
if ( ! file_exists( $located ) ) { |
|
129
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
130
|
|
|
return; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
// Allow 3rd party plugin filter template file from their plugin. |
|
134
|
|
|
$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
135
|
|
|
|
|
136
|
|
|
do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
137
|
|
|
|
|
138
|
|
|
include( $located ); |
|
139
|
|
|
|
|
140
|
|
|
do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
144
|
|
|
ob_start(); |
|
145
|
|
|
wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
146
|
|
|
return ob_get_clean(); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
150
|
|
|
if ( ! $template_path ) { |
|
151
|
|
|
$template_path = wpinv_template_path(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
if ( ! $default_path ) { |
|
155
|
|
|
$default_path = WPINV_PLUGIN_DIR . 'templates/'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
// Look within passed path within the theme - this is priority. |
|
159
|
|
|
$template = locate_template( |
|
160
|
|
|
array( |
|
161
|
|
|
trailingslashit( $template_path ) . $template_name, |
|
162
|
|
|
$template_name |
|
163
|
|
|
) |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
|
|
// Get default templates/ |
|
167
|
|
|
if ( !$template && $default_path ) { |
|
168
|
|
|
$template = trailingslashit( $default_path ) . $template_name; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
// Return what we found. |
|
172
|
|
|
return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
176
|
|
|
do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177
|
|
|
|
|
178
|
|
|
// Setup possible parts |
|
179
|
|
|
$templates = array(); |
|
180
|
|
|
if ( isset( $name ) ) |
|
181
|
|
|
$templates[] = $slug . '-' . $name . '.php'; |
|
182
|
|
|
$templates[] = $slug . '.php'; |
|
183
|
|
|
|
|
184
|
|
|
// Allow template parts to be filtered |
|
185
|
|
|
$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
186
|
|
|
|
|
187
|
|
|
// Return the part that is found |
|
188
|
|
|
return wpinv_locate_tmpl( $templates, $load, false ); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
192
|
|
|
// No file found yet |
|
193
|
|
|
$located = false; |
|
194
|
|
|
|
|
195
|
|
|
// Try to find a template file |
|
196
|
|
|
foreach ( (array)$template_names as $template_name ) { |
|
197
|
|
|
|
|
198
|
|
|
// Continue if template is empty |
|
199
|
|
|
if ( empty( $template_name ) ) |
|
200
|
|
|
continue; |
|
201
|
|
|
|
|
202
|
|
|
// Trim off any slashes from the template name |
|
203
|
|
|
$template_name = ltrim( $template_name, '/' ); |
|
204
|
|
|
|
|
205
|
|
|
// try locating this template file by looping through the template paths |
|
206
|
|
|
foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
207
|
|
|
|
|
208
|
|
|
if( file_exists( $template_path . $template_name ) ) { |
|
209
|
|
|
$located = $template_path . $template_name; |
|
210
|
|
|
break; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
if( !empty( $located ) ) { |
|
215
|
|
|
break; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
if ( ( true == $load ) && ! empty( $located ) ) |
|
|
|
|
|
|
220
|
|
|
load_template( $located, $require_once ); |
|
221
|
|
|
|
|
222
|
|
|
return $located; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
function wpinv_get_theme_template_paths() { |
|
226
|
|
|
$template_dir = wpinv_get_theme_template_dir_name(); |
|
227
|
|
|
|
|
228
|
|
|
$file_paths = array( |
|
229
|
|
|
1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
230
|
|
|
10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231
|
|
|
100 => wpinv_get_templates_dir() |
|
232
|
|
|
); |
|
233
|
|
|
|
|
234
|
|
|
$file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
235
|
|
|
|
|
236
|
|
|
// sort the file paths based on priority |
|
237
|
|
|
ksort( $file_paths, SORT_NUMERIC ); |
|
238
|
|
|
|
|
239
|
|
|
return array_map( 'trailingslashit', $file_paths ); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
function wpinv_get_theme_template_dir_name() { |
|
243
|
|
|
return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
function wpinv_checkout_meta_tags() { |
|
247
|
|
|
|
|
248
|
|
|
$pages = array(); |
|
249
|
|
|
$pages[] = wpinv_get_option( 'success_page' ); |
|
250
|
|
|
$pages[] = wpinv_get_option( 'failure_page' ); |
|
251
|
|
|
$pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
252
|
|
|
|
|
253
|
|
|
if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
254
|
|
|
return; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
258
|
|
|
} |
|
259
|
|
|
add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
260
|
|
|
|
|
261
|
|
|
function wpinv_add_body_classes( $class ) { |
|
262
|
|
|
$classes = (array)$class; |
|
263
|
|
|
|
|
264
|
|
|
if( wpinv_is_checkout() ) { |
|
265
|
|
|
$classes[] = 'wpinv-checkout'; |
|
266
|
|
|
$classes[] = 'wpinv-page'; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
if( wpinv_is_success_page() ) { |
|
270
|
|
|
$classes[] = 'wpinv-success'; |
|
271
|
|
|
$classes[] = 'wpinv-page'; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
if( wpinv_is_failed_transaction_page() ) { |
|
275
|
|
|
$classes[] = 'wpinv-failed-transaction'; |
|
276
|
|
|
$classes[] = 'wpinv-page'; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
if( wpinv_is_invoice_history_page() ) { |
|
280
|
|
|
$classes[] = 'wpinv-history'; |
|
281
|
|
|
$classes[] = 'wpinv-page'; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
if( wpinv_is_test_mode() ) { |
|
285
|
|
|
$classes[] = 'wpinv-test-mode'; |
|
286
|
|
|
$classes[] = 'wpinv-page'; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
return array_unique( $classes ); |
|
290
|
|
|
} |
|
291
|
|
|
add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
292
|
|
|
|
|
293
|
|
|
function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
294
|
|
|
$args = array( 'nopaging' => true ); |
|
295
|
|
|
|
|
296
|
|
|
if ( ! empty( $status ) ) |
|
297
|
|
|
$args['post_status'] = $status; |
|
298
|
|
|
|
|
299
|
|
|
$discounts = wpinv_get_discounts( $args ); |
|
300
|
|
|
$options = array(); |
|
301
|
|
|
|
|
302
|
|
|
if ( $discounts ) { |
|
303
|
|
|
foreach ( $discounts as $discount ) { |
|
304
|
|
|
$options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
305
|
|
|
} |
|
306
|
|
|
} else { |
|
307
|
|
|
$options[0] = __( 'No discounts found', 'invoicing' ); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
$output = wpinv_html_select( array( |
|
311
|
|
|
'name' => $name, |
|
312
|
|
|
'selected' => $selected, |
|
313
|
|
|
'options' => $options, |
|
314
|
|
|
'show_option_all' => false, |
|
315
|
|
|
'show_option_none' => false, |
|
316
|
|
|
) ); |
|
317
|
|
|
|
|
318
|
|
|
return $output; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
322
|
|
|
$current = date( 'Y' ); |
|
323
|
|
|
$start_year = $current - absint( $years_before ); |
|
324
|
|
|
$end_year = $current + absint( $years_after ); |
|
325
|
|
|
$selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
326
|
|
|
$options = array(); |
|
327
|
|
|
|
|
328
|
|
|
while ( $start_year <= $end_year ) { |
|
329
|
|
|
$options[ absint( $start_year ) ] = $start_year; |
|
330
|
|
|
$start_year++; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
$output = wpinv_html_select( array( |
|
334
|
|
|
'name' => $name, |
|
335
|
|
|
'selected' => $selected, |
|
336
|
|
|
'options' => $options, |
|
337
|
|
|
'show_option_all' => false, |
|
338
|
|
|
'show_option_none' => false |
|
339
|
|
|
) ); |
|
340
|
|
|
|
|
341
|
|
|
return $output; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
345
|
|
|
$month = 1; |
|
346
|
|
|
$options = array(); |
|
347
|
|
|
$selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
348
|
|
|
|
|
349
|
|
|
while ( $month <= 12 ) { |
|
350
|
|
|
$options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
351
|
|
|
$month++; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
$output = wpinv_html_select( array( |
|
355
|
|
|
'name' => $name, |
|
356
|
|
|
'selected' => $selected, |
|
357
|
|
|
'options' => $options, |
|
358
|
|
|
'show_option_all' => false, |
|
359
|
|
|
'show_option_none' => false |
|
360
|
|
|
) ); |
|
361
|
|
|
|
|
362
|
|
|
return $output; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
function wpinv_html_select( $args = array() ) { |
|
366
|
|
|
$defaults = array( |
|
367
|
|
|
'options' => array(), |
|
368
|
|
|
'name' => null, |
|
369
|
|
|
'class' => '', |
|
370
|
|
|
'id' => '', |
|
371
|
|
|
'selected' => 0, |
|
372
|
|
|
'chosen' => false, |
|
373
|
|
|
'placeholder' => null, |
|
374
|
|
|
'multiple' => false, |
|
375
|
|
|
'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
376
|
|
|
'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
377
|
|
|
'data' => array(), |
|
378
|
|
|
'onchange' => null, |
|
379
|
|
|
'required' => false, |
|
380
|
|
|
'disabled' => false, |
|
381
|
|
|
'readonly' => false, |
|
382
|
|
|
); |
|
383
|
|
|
|
|
384
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
385
|
|
|
|
|
386
|
|
|
$data_elements = ''; |
|
387
|
|
|
foreach ( $args['data'] as $key => $value ) { |
|
388
|
|
|
$data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
if( $args['multiple'] ) { |
|
392
|
|
|
$multiple = ' MULTIPLE'; |
|
393
|
|
|
} else { |
|
394
|
|
|
$multiple = ''; |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
if( $args['chosen'] ) { |
|
398
|
|
|
$args['class'] .= ' wpinv-select-chosen'; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
if( $args['placeholder'] ) { |
|
402
|
|
|
$placeholder = $args['placeholder']; |
|
403
|
|
|
} else { |
|
404
|
|
|
$placeholder = ''; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
$options = ''; |
|
408
|
|
View Code Duplication |
if( !empty( $args['onchange'] ) ) { |
|
409
|
|
|
$options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
if( !empty( $args['required'] ) ) { |
|
413
|
|
|
$options .= ' required="required"'; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
if( !empty( $args['disabled'] ) ) { |
|
417
|
|
|
$options .= ' disabled'; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
if( !empty( $args['readonly'] ) ) { |
|
421
|
|
|
$options .= ' readonly'; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
$class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
425
|
|
|
$output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
426
|
|
|
|
|
427
|
|
View Code Duplication |
if ( $args['show_option_all'] ) { |
|
428
|
|
|
if( $args['multiple'] ) { |
|
429
|
|
|
$selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
430
|
|
|
} else { |
|
431
|
|
|
$selected = selected( $args['selected'], 0, false ); |
|
432
|
|
|
} |
|
433
|
|
|
$output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
if ( !empty( $args['options'] ) ) { |
|
437
|
|
|
|
|
438
|
|
View Code Duplication |
if ( $args['show_option_none'] ) { |
|
439
|
|
|
if( $args['multiple'] ) { |
|
440
|
|
|
$selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
441
|
|
|
} else { |
|
442
|
|
|
$selected = selected( $args['selected'] === "", true, false ); |
|
443
|
|
|
} |
|
444
|
|
|
$output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
foreach( $args['options'] as $key => $option ) { |
|
448
|
|
|
|
|
449
|
|
|
if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
450
|
|
|
$selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
451
|
|
|
} else { |
|
452
|
|
|
$selected = selected( $args['selected'], $key, false ); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
$output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
456
|
|
|
} |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
$output .= '</select>'; |
|
460
|
|
|
|
|
461
|
|
|
return $output; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
function wpinv_item_dropdown( $args = array() ) { |
|
465
|
|
|
$defaults = array( |
|
466
|
|
|
'name' => 'wpi_item', |
|
467
|
|
|
'id' => 'wpi_item', |
|
468
|
|
|
'class' => '', |
|
469
|
|
|
'multiple' => false, |
|
470
|
|
|
'selected' => 0, |
|
471
|
|
|
'chosen' => false, |
|
472
|
|
|
'number' => 100, |
|
473
|
|
|
'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
474
|
|
|
'data' => array( 'search-type' => 'item' ), |
|
475
|
|
|
'show_option_all' => false, |
|
476
|
|
|
'show_option_none' => false, |
|
477
|
|
|
'with_packages' => true, |
|
478
|
|
|
'show_recurring' => false, |
|
479
|
|
|
); |
|
480
|
|
|
|
|
481
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
482
|
|
|
|
|
483
|
|
|
$item_args = array( |
|
484
|
|
|
'post_type' => 'wpi_item', |
|
485
|
|
|
'orderby' => 'title', |
|
486
|
|
|
'order' => 'ASC', |
|
487
|
|
|
'posts_per_page' => $args['number'] |
|
488
|
|
|
); |
|
489
|
|
|
|
|
490
|
|
|
if ( !$args['with_packages'] ) { |
|
491
|
|
|
$item_args['meta_query'] = array( |
|
492
|
|
|
array( |
|
493
|
|
|
'key' => '_wpinv_type', |
|
494
|
|
|
'compare' => '!=', |
|
495
|
|
|
'value' => 'package' |
|
496
|
|
|
), |
|
497
|
|
|
); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
$items = get_posts( $item_args ); |
|
501
|
|
|
$options = array(); |
|
502
|
|
|
if ( $items ) { |
|
503
|
|
|
foreach ( $items as $item ) { |
|
504
|
|
|
$title = esc_html( $item->post_title ); |
|
505
|
|
|
|
|
506
|
|
|
if ( !empty( $args['show_recurring'] ) ) { |
|
507
|
|
|
$title .= wpinv_get_item_suffix( $item->ID, false ); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
$options[ absint( $item->ID ) ] = $title; |
|
511
|
|
|
} |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
// This ensures that any selected items are included in the drop down |
|
515
|
|
|
if( is_array( $args['selected'] ) ) { |
|
516
|
|
|
foreach( $args['selected'] as $item ) { |
|
517
|
|
|
if( ! in_array( $item, $options ) ) { |
|
518
|
|
|
$title = get_the_title( $item ); |
|
519
|
|
|
if ( !empty( $args['show_recurring'] ) ) { |
|
520
|
|
|
$title .= wpinv_get_item_suffix( $item, false ); |
|
521
|
|
|
} |
|
522
|
|
|
$options[$item] = $title; |
|
523
|
|
|
} |
|
524
|
|
|
} |
|
525
|
|
|
} elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
526
|
|
|
if ( ! in_array( $args['selected'], $options ) ) { |
|
527
|
|
|
$title = get_the_title( $args['selected'] ); |
|
528
|
|
|
if ( !empty( $args['show_recurring'] ) ) { |
|
529
|
|
|
$title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
530
|
|
|
} |
|
531
|
|
|
$options[$args['selected']] = get_the_title( $args['selected'] ); |
|
532
|
|
|
} |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
|
$output = wpinv_html_select( array( |
|
536
|
|
|
'name' => $args['name'], |
|
537
|
|
|
'selected' => $args['selected'], |
|
538
|
|
|
'id' => $args['id'], |
|
539
|
|
|
'class' => $args['class'], |
|
540
|
|
|
'options' => $options, |
|
541
|
|
|
'chosen' => $args['chosen'], |
|
542
|
|
|
'multiple' => $args['multiple'], |
|
543
|
|
|
'placeholder' => $args['placeholder'], |
|
544
|
|
|
'show_option_all' => $args['show_option_all'], |
|
545
|
|
|
'show_option_none' => $args['show_option_none'], |
|
546
|
|
|
'data' => $args['data'], |
|
547
|
|
|
) ); |
|
548
|
|
|
|
|
549
|
|
|
return $output; |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
function wpinv_html_checkbox( $args = array() ) { |
|
553
|
|
|
$defaults = array( |
|
554
|
|
|
'name' => null, |
|
555
|
|
|
'current' => null, |
|
556
|
|
|
'class' => 'wpinv-checkbox', |
|
557
|
|
|
'options' => array( |
|
558
|
|
|
'disabled' => false, |
|
559
|
|
|
'readonly' => false |
|
560
|
|
|
) |
|
561
|
|
|
); |
|
562
|
|
|
|
|
563
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
564
|
|
|
|
|
565
|
|
|
$class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
566
|
|
|
$options = ''; |
|
567
|
|
|
if ( ! empty( $args['options']['disabled'] ) ) { |
|
568
|
|
|
$options .= ' disabled="disabled"'; |
|
569
|
|
|
} elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
570
|
|
|
$options .= ' readonly'; |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
$output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
574
|
|
|
|
|
575
|
|
|
return $output; |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
function wpinv_html_text( $args = array() ) { |
|
579
|
|
|
// Backwards compatibility |
|
580
|
|
|
if ( func_num_args() > 1 ) { |
|
581
|
|
|
$args = func_get_args(); |
|
582
|
|
|
|
|
583
|
|
|
$name = $args[0]; |
|
584
|
|
|
$value = isset( $args[1] ) ? $args[1] : ''; |
|
585
|
|
|
$label = isset( $args[2] ) ? $args[2] : ''; |
|
586
|
|
|
$desc = isset( $args[3] ) ? $args[3] : ''; |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
$defaults = array( |
|
590
|
|
|
'id' => '', |
|
591
|
|
|
'name' => isset( $name ) ? $name : 'text', |
|
592
|
|
|
'value' => isset( $value ) ? $value : null, |
|
593
|
|
|
'label' => isset( $label ) ? $label : null, |
|
594
|
|
|
'desc' => isset( $desc ) ? $desc : null, |
|
595
|
|
|
'placeholder' => '', |
|
596
|
|
|
'class' => 'regular-text', |
|
597
|
|
|
'disabled' => false, |
|
598
|
|
|
'readonly' => false, |
|
599
|
|
|
'required' => false, |
|
600
|
|
|
'autocomplete' => '', |
|
601
|
|
|
'data' => false |
|
602
|
|
|
); |
|
603
|
|
|
|
|
604
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
605
|
|
|
|
|
606
|
|
|
$class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
607
|
|
|
$options = ''; |
|
608
|
|
|
if( $args['required'] ) { |
|
609
|
|
|
$options .= ' required="required"'; |
|
610
|
|
|
} |
|
611
|
|
|
if( $args['readonly'] ) { |
|
612
|
|
|
$options .= ' readonly'; |
|
613
|
|
|
} |
|
614
|
|
|
if( $args['readonly'] ) { |
|
615
|
|
|
$options .= ' readonly'; |
|
616
|
|
|
} |
|
617
|
|
|
|
|
618
|
|
|
$data = ''; |
|
619
|
|
|
if ( !empty( $args['data'] ) ) { |
|
620
|
|
|
foreach ( $args['data'] as $key => $value ) { |
|
621
|
|
|
$data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
622
|
|
|
} |
|
623
|
|
|
} |
|
624
|
|
|
|
|
625
|
|
|
$output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
626
|
|
|
$output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
627
|
|
View Code Duplication |
if ( ! empty( $args['desc'] ) ) { |
|
628
|
|
|
$output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
$output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
632
|
|
|
|
|
633
|
|
|
$output .= '</span>'; |
|
634
|
|
|
|
|
635
|
|
|
return $output; |
|
636
|
|
|
} |
|
637
|
|
|
|
|
638
|
|
|
function wpinv_html_date_field( $args = array() ) { |
|
639
|
|
|
if( empty( $args['class'] ) ) { |
|
640
|
|
|
$args['class'] = 'wpiDatepicker'; |
|
641
|
|
|
} elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
642
|
|
|
$args['class'] .= ' wpiDatepicker'; |
|
643
|
|
|
} |
|
644
|
|
|
|
|
645
|
|
|
return wpinv_html_text( $args ); |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
function wpinv_html_textarea( $args = array() ) { |
|
649
|
|
|
$defaults = array( |
|
650
|
|
|
'name' => 'textarea', |
|
651
|
|
|
'value' => null, |
|
652
|
|
|
'label' => null, |
|
653
|
|
|
'desc' => null, |
|
654
|
|
|
'class' => 'large-text', |
|
655
|
|
|
'disabled' => false |
|
656
|
|
|
); |
|
657
|
|
|
|
|
658
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
659
|
|
|
|
|
660
|
|
|
$class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
661
|
|
|
$disabled = ''; |
|
662
|
|
|
if( $args['disabled'] ) { |
|
663
|
|
|
$disabled = ' disabled="disabled"'; |
|
664
|
|
|
} |
|
665
|
|
|
|
|
666
|
|
|
$output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
667
|
|
|
$output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
668
|
|
|
$output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
669
|
|
|
|
|
670
|
|
View Code Duplication |
if ( ! empty( $args['desc'] ) ) { |
|
671
|
|
|
$output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
672
|
|
|
} |
|
673
|
|
|
$output .= '</span>'; |
|
674
|
|
|
|
|
675
|
|
|
return $output; |
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
function wpinv_html_ajax_user_search( $args = array() ) { |
|
679
|
|
|
$defaults = array( |
|
680
|
|
|
'name' => 'user_id', |
|
681
|
|
|
'value' => null, |
|
682
|
|
|
'placeholder' => __( 'Enter username', 'invoicing' ), |
|
683
|
|
|
'label' => null, |
|
684
|
|
|
'desc' => null, |
|
685
|
|
|
'class' => '', |
|
686
|
|
|
'disabled' => false, |
|
687
|
|
|
'autocomplete'=> 'off', |
|
688
|
|
|
'data' => false |
|
689
|
|
|
); |
|
690
|
|
|
|
|
691
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
692
|
|
|
|
|
693
|
|
|
$args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
|
694
|
|
|
|
|
695
|
|
|
$output = '<span class="wpinv_user_search_wrap">'; |
|
696
|
|
|
$output .= wpinv_html_text( $args ); |
|
697
|
|
|
$output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
698
|
|
|
$output .= '</span>'; |
|
699
|
|
|
|
|
700
|
|
|
return $output; |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
function wpinv_ip_geolocation() { |
|
704
|
|
|
global $wpinv_euvat; |
|
705
|
|
|
|
|
706
|
|
|
$ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
707
|
|
|
$content = ''; |
|
|
|
|
|
|
708
|
|
|
$iso = ''; |
|
709
|
|
|
$country = ''; |
|
710
|
|
|
$region = ''; |
|
711
|
|
|
$city = ''; |
|
712
|
|
|
$longitude = ''; |
|
713
|
|
|
$latitude = ''; |
|
714
|
|
|
$credit = ''; |
|
715
|
|
|
$address = ''; |
|
716
|
|
|
|
|
717
|
|
|
if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
718
|
|
|
try { |
|
719
|
|
|
$iso = $geoip2_city->country->isoCode; |
|
720
|
|
|
$country = $geoip2_city->country->name; |
|
721
|
|
|
$region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
722
|
|
|
$city = $geoip2_city->city->name; |
|
723
|
|
|
$longitude = $geoip2_city->location->longitude; |
|
724
|
|
|
$latitude = $geoip2_city->location->latitude; |
|
725
|
|
|
$credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
726
|
|
|
} catch( Exception $e ) { } |
|
|
|
|
|
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
730
|
|
|
try { |
|
731
|
|
|
$load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
732
|
|
|
|
|
733
|
|
|
if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
734
|
|
|
$iso = $load_xml->geoplugin_countryCode; |
|
|
|
|
|
|
735
|
|
|
$country = $load_xml->geoplugin_countryName; |
|
|
|
|
|
|
736
|
|
|
$region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
737
|
|
|
$city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
738
|
|
|
$longitude = $load_xml->geoplugin_longitude; |
|
|
|
|
|
|
739
|
|
|
$latitude = $load_xml->geoplugin_latitude; |
|
|
|
|
|
|
740
|
|
|
$credit = $load_xml->geoplugin_credit; |
|
|
|
|
|
|
741
|
|
|
$credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
742
|
|
|
} |
|
743
|
|
|
} catch( Exception $e ) { } |
|
|
|
|
|
|
744
|
|
|
} |
|
745
|
|
|
|
|
746
|
|
|
if ( $iso && $longitude && $latitude ) { |
|
747
|
|
|
if ( $city ) { |
|
748
|
|
|
$address .= $city . ', '; |
|
749
|
|
|
} |
|
750
|
|
|
|
|
751
|
|
|
if ( $region ) { |
|
752
|
|
|
$address .= $region . ', '; |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
$address .= $country . ' (' . $iso . ')'; |
|
756
|
|
|
$content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
757
|
|
|
$content .= '<p>'. $credit . '</p>'; |
|
758
|
|
|
} else { |
|
759
|
|
|
$content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
760
|
|
|
} |
|
761
|
|
|
?> |
|
762
|
|
|
<!DOCTYPE html> |
|
763
|
|
|
<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
764
|
|
|
<body> |
|
765
|
|
|
<?php if ( $latitude && $latitude ) { ?> |
|
766
|
|
|
<div id="map"></div> |
|
767
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
|
768
|
|
|
<script type="text/javascript"> |
|
769
|
|
|
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
|
770
|
|
|
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
|
771
|
|
|
osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
|
772
|
|
|
latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
773
|
|
|
|
|
774
|
|
|
var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
|
775
|
|
|
|
|
776
|
|
|
var marker = new L.Marker(latlng); |
|
777
|
|
|
map.addLayer(marker); |
|
778
|
|
|
|
|
779
|
|
|
marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
780
|
|
|
</script> |
|
781
|
|
|
<?php } ?> |
|
782
|
|
|
<div style="height:100px"><?php echo $content; ?></div> |
|
783
|
|
|
</body></html> |
|
784
|
|
|
<?php |
|
785
|
|
|
exit; |
|
786
|
|
|
} |
|
787
|
|
|
add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
788
|
|
|
add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
789
|
|
|
|
|
790
|
|
|
// Set up the template for the invoice. |
|
791
|
|
|
function wpinv_template( $template ) { |
|
792
|
|
|
global $post, $wp_query; |
|
793
|
|
|
|
|
794
|
|
|
if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
795
|
|
|
if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
796
|
|
|
$template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
797
|
|
|
} else { |
|
798
|
|
|
if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
799
|
|
|
$user_id = $invoice->get_user_id(); |
|
800
|
|
|
$secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
801
|
|
|
|
|
802
|
|
View Code Duplication |
if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
803
|
|
|
$redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
804
|
|
|
|
|
805
|
|
|
wpinv_guest_redirect( $redirect_to, $user_id ); |
|
806
|
|
|
wpinv_die(); |
|
807
|
|
|
} |
|
808
|
|
|
} |
|
809
|
|
|
$redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
810
|
|
|
|
|
811
|
|
|
wp_redirect( $redirect_to ); |
|
812
|
|
|
wpinv_die(); |
|
813
|
|
|
} |
|
814
|
|
|
} |
|
815
|
|
|
|
|
816
|
|
|
return $template; |
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
function wpinv_get_business_address() { |
|
820
|
|
|
$business_address = wpinv_store_address(); |
|
821
|
|
|
$business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
822
|
|
|
|
|
823
|
|
|
/* |
|
|
|
|
|
|
824
|
|
|
$default_country = wpinv_get_default_country(); |
|
825
|
|
|
$default_state = wpinv_get_default_state(); |
|
826
|
|
|
|
|
827
|
|
|
$address_fields = array(); |
|
828
|
|
|
if ( !empty( $default_state ) ) { |
|
829
|
|
|
$address_fields[] = wpinv_state_name( $default_state, $default_country ); |
|
830
|
|
|
} |
|
831
|
|
|
|
|
832
|
|
|
if ( !empty( $default_country ) ) { |
|
833
|
|
|
$address_fields[] = wpinv_country_name( $default_country ); |
|
834
|
|
|
} |
|
835
|
|
|
|
|
836
|
|
|
if ( !empty( $address_fields ) ) { |
|
837
|
|
|
$address_fields = implode( ", ", $address_fields ); |
|
838
|
|
|
|
|
839
|
|
|
$business_address .= wpautop( wp_kses_post( $address_fields ) ); |
|
840
|
|
|
} |
|
841
|
|
|
*/ |
|
842
|
|
|
|
|
843
|
|
|
$business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
|
844
|
|
|
|
|
845
|
|
|
return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
846
|
|
|
} |
|
847
|
|
|
|
|
848
|
|
|
function wpinv_display_from_address() { |
|
849
|
|
|
global $wpinv_euvat; |
|
850
|
|
|
|
|
851
|
|
|
$from_name = $wpinv_euvat->get_company_name(); |
|
852
|
|
|
if (empty($from_name)) { |
|
853
|
|
|
$from_name = wpinv_get_business_name(); |
|
854
|
|
|
} |
|
855
|
|
|
?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
856
|
|
|
<div class="wrapper col-xs-10"> |
|
857
|
|
|
<div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
858
|
|
|
<?php if ( $address = wpinv_get_business_address() ) { ?> |
|
859
|
|
|
<div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
860
|
|
|
<?php } ?> |
|
861
|
|
|
<?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
862
|
|
|
<div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
863
|
|
|
<?php } ?> |
|
864
|
|
|
</div> |
|
865
|
|
|
<?php |
|
866
|
|
|
} |
|
867
|
|
|
|
|
868
|
|
|
function wpinv_watermark( $id = 0 ) { |
|
869
|
|
|
$output = wpinv_get_watermark( $id ); |
|
870
|
|
|
|
|
871
|
|
|
return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
872
|
|
|
} |
|
873
|
|
|
|
|
874
|
|
|
function wpinv_get_watermark( $id ) { |
|
875
|
|
|
if ( !$id > 0 ) { |
|
876
|
|
|
return NULL; |
|
877
|
|
|
} |
|
878
|
|
|
$invoice = wpinv_get_invoice( $id ); |
|
879
|
|
|
|
|
880
|
|
|
if ( !empty( $invoice ) ) { |
|
881
|
|
|
if ( $invoice->is_paid() ) { |
|
882
|
|
|
return __( 'Paid', 'invoicing' ); |
|
883
|
|
|
} |
|
884
|
|
|
if ( $invoice->has_status( array( 'cancelled' ) ) ) { |
|
885
|
|
|
return __( 'Cancelled', 'invoicing' ); |
|
886
|
|
|
} |
|
887
|
|
|
} |
|
888
|
|
|
|
|
889
|
|
|
return NULL; |
|
890
|
|
|
} |
|
891
|
|
|
|
|
892
|
|
|
function wpinv_display_invoice_details( $invoice ) { |
|
893
|
|
|
global $wpinv_euvat; |
|
894
|
|
|
|
|
895
|
|
|
$invoice_id = $invoice->ID; |
|
896
|
|
|
$vat_name = $wpinv_euvat->get_vat_name(); |
|
897
|
|
|
$use_taxes = wpinv_use_taxes(); |
|
898
|
|
|
|
|
899
|
|
|
$invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
900
|
|
|
|
|
901
|
|
|
if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902
|
|
|
elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
903
|
|
|
?> |
|
904
|
|
|
<table class="table table-bordered table-sm"> |
|
905
|
|
|
<?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
906
|
|
|
<tr class="wpi-row-number"> |
|
907
|
|
|
<th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th> |
|
|
|
|
|
|
908
|
|
|
<td><?php echo esc_html( $invoice_number ); ?></td> |
|
909
|
|
|
</tr> |
|
910
|
|
|
<?php } ?> |
|
911
|
|
|
<tr class="wpi-row-status"> |
|
912
|
|
|
<th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th> |
|
913
|
|
|
<td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
914
|
|
|
</tr> |
|
915
|
|
|
<?php if ( $invoice->is_renewal() ) { ?> |
|
916
|
|
|
<tr class="wpi-row-parent"> |
|
917
|
|
|
<th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th> |
|
918
|
|
|
<td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
919
|
|
|
</tr> |
|
920
|
|
|
<?php } ?> |
|
921
|
|
|
<tr class="wpi-row-gateway"> |
|
922
|
|
|
<th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
923
|
|
|
<td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
924
|
|
|
</tr> |
|
925
|
|
|
<?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
926
|
|
|
<tr class="wpi-row-date"> |
|
927
|
|
|
<th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th> |
|
928
|
|
|
<td><?php echo $invoice_date; ?></td> |
|
929
|
|
|
</tr> |
|
930
|
|
|
<?php } ?> |
|
931
|
|
|
<?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
932
|
|
|
<tr class="wpi-row-date"> |
|
933
|
|
|
<th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
934
|
|
|
<td><?php echo $due_date; ?></td> |
|
935
|
|
|
</tr> |
|
936
|
|
|
<?php } ?> |
|
937
|
|
|
<?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
938
|
|
|
<tr class="wpi-row-ovatno"> |
|
939
|
|
|
<th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
940
|
|
|
<td><?php echo $owner_vat_number; ?></td> |
|
941
|
|
|
</tr> |
|
942
|
|
|
<?php } ?> |
|
943
|
|
|
<?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
944
|
|
|
<tr class="wpi-row-uvatno"> |
|
945
|
|
|
<th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
946
|
|
|
<td><?php echo $user_vat_number; ?></td> |
|
947
|
|
|
</tr> |
|
948
|
|
|
<?php } ?> |
|
949
|
|
|
<tr class="table-active tr-total wpi-row-total"> |
|
950
|
|
|
<th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
951
|
|
|
<td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
952
|
|
|
</tr> |
|
953
|
|
|
</table> |
|
954
|
|
|
<?php |
|
955
|
|
|
} |
|
956
|
|
|
|
|
957
|
|
|
function wpinv_display_to_address( $invoice_id = 0 ) { |
|
958
|
|
|
$invoice = wpinv_get_invoice( $invoice_id ); |
|
959
|
|
|
|
|
960
|
|
|
if ( empty( $invoice ) ) { |
|
961
|
|
|
return NULL; |
|
962
|
|
|
} |
|
963
|
|
|
|
|
964
|
|
|
$billing_details = $invoice->get_user_info(); |
|
965
|
|
|
$output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
966
|
|
|
$output .= '<div class="wrapper col-xs-10">'; |
|
967
|
|
|
|
|
968
|
|
|
ob_start(); |
|
969
|
|
|
do_action( 'wpinv_display_to_address_top', $invoice ); |
|
970
|
|
|
$output .= ob_get_clean(); |
|
971
|
|
|
|
|
972
|
|
|
$output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
973
|
|
|
if ( $company = $billing_details['company'] ) { |
|
974
|
|
|
$output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
975
|
|
|
} |
|
976
|
|
|
$address_row = ''; |
|
977
|
|
|
if ( $address = $billing_details['address'] ) { |
|
978
|
|
|
$address_row .= wpautop( wp_kses_post( $address ) ); |
|
979
|
|
|
} |
|
980
|
|
|
|
|
981
|
|
|
$address_fields = array(); |
|
982
|
|
|
if ( !empty( $billing_details['city'] ) ) { |
|
983
|
|
|
$address_fields[] = $billing_details['city']; |
|
984
|
|
|
} |
|
985
|
|
|
|
|
986
|
|
|
$billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
987
|
|
|
if ( !empty( $billing_details['state'] ) ) { |
|
988
|
|
|
$address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
989
|
|
|
} |
|
990
|
|
|
|
|
991
|
|
|
if ( !empty( $billing_country ) ) { |
|
992
|
|
|
$address_fields[] = wpinv_country_name( $billing_country ); |
|
993
|
|
|
} |
|
994
|
|
|
|
|
995
|
|
View Code Duplication |
if ( !empty( $address_fields ) ) { |
|
996
|
|
|
$address_fields = implode( ", ", $address_fields ); |
|
997
|
|
|
|
|
998
|
|
|
if ( !empty( $billing_details['zip'] ) ) { |
|
999
|
|
|
$address_fields .= ' ' . $billing_details['zip']; |
|
1000
|
|
|
} |
|
1001
|
|
|
|
|
1002
|
|
|
$address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1003
|
|
|
} |
|
1004
|
|
|
|
|
1005
|
|
|
if ( $address_row ) { |
|
1006
|
|
|
$output .= '<div class="address">' . $address_row . '</div>'; |
|
1007
|
|
|
} |
|
1008
|
|
|
|
|
1009
|
|
|
if ( $phone = $invoice->get_phone() ) { |
|
1010
|
|
|
$output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
1011
|
|
|
} |
|
1012
|
|
|
if ( $email = $invoice->get_email() ) { |
|
1013
|
|
|
$output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
1014
|
|
|
} |
|
1015
|
|
|
|
|
1016
|
|
|
ob_start(); |
|
1017
|
|
|
do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1018
|
|
|
$output .= ob_get_clean(); |
|
1019
|
|
|
|
|
1020
|
|
|
$output .= '</div>'; |
|
1021
|
|
|
$output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1022
|
|
|
|
|
1023
|
|
|
echo $output; |
|
1024
|
|
|
} |
|
1025
|
|
|
|
|
1026
|
|
|
function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1027
|
|
|
global $wpinv_euvat, $ajax_cart_details; |
|
1028
|
|
|
$invoice = wpinv_get_invoice( $invoice_id ); |
|
1029
|
|
|
$quantities_enabled = wpinv_item_quantities_enabled(); |
|
1030
|
|
|
$use_taxes = wpinv_use_taxes(); |
|
1031
|
|
|
$zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
|
1032
|
|
|
$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1033
|
|
|
$tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1034
|
|
|
|
|
1035
|
|
|
$cart_details = $invoice->get_cart_details(); |
|
1036
|
|
|
$ajax_cart_details = $cart_details; |
|
1037
|
|
|
ob_start(); |
|
1038
|
|
|
?> |
|
1039
|
|
|
<table class="table table-sm table-bordered table-responsive"> |
|
1040
|
|
|
<thead> |
|
1041
|
|
|
<tr> |
|
1042
|
|
|
<th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1043
|
|
|
<th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1044
|
|
|
<?php if ($quantities_enabled) { ?> |
|
1045
|
|
|
<th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1046
|
|
|
<?php } ?> |
|
1047
|
|
|
<?php if ($use_taxes && !$zero_tax) { ?> |
|
1048
|
|
|
<th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
|
1049
|
|
|
<?php } ?> |
|
1050
|
|
|
<th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1051
|
|
|
</tr> |
|
1052
|
|
|
</thead> |
|
1053
|
|
|
<tbody> |
|
1054
|
|
|
<?php |
|
1055
|
|
|
if ( !empty( $cart_details ) ) { |
|
1056
|
|
|
do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1057
|
|
|
|
|
1058
|
|
|
$count = 0; |
|
1059
|
|
|
$cols = 3; |
|
1060
|
|
|
foreach ( $cart_details as $key => $cart_item ) { |
|
1061
|
|
|
$item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1062
|
|
|
$item_price = isset($cart_item["item_price"]) ? wpinv_format_amount( $cart_item["item_price"] ) : 0; |
|
1063
|
|
|
$line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount( $cart_item["subtotal"] ) : 0; |
|
1064
|
|
|
$quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1065
|
|
|
|
|
1066
|
|
|
$item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1067
|
|
|
$summary = ''; |
|
1068
|
|
|
$cols = 3; |
|
1069
|
|
|
if ( !empty($item) ) { |
|
1070
|
|
|
$item_name = $item->get_name(); |
|
1071
|
|
|
$summary = $item->get_summary(); |
|
1072
|
|
|
} |
|
1073
|
|
|
$item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
|
|
|
|
|
1074
|
|
|
|
|
1075
|
|
View Code Duplication |
if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
|
1076
|
|
|
$post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1077
|
|
|
$summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link ); |
|
1078
|
|
|
} |
|
1079
|
|
|
$summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1080
|
|
|
|
|
1081
|
|
|
$item_tax = ''; |
|
1082
|
|
|
$tax_rate = ''; |
|
1083
|
|
View Code Duplication |
if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1084
|
|
|
$item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1085
|
|
|
$tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1086
|
|
|
$tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1087
|
|
|
$tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
|
1088
|
|
|
} |
|
1089
|
|
|
|
|
1090
|
|
|
$line_item_tax = $item_tax . $tax_rate; |
|
1091
|
|
|
|
|
1092
|
|
|
if ( $line_item_tax === '' ) { |
|
1093
|
|
|
$line_item_tax = 0; // Zero tax |
|
1094
|
|
|
} |
|
1095
|
|
|
|
|
1096
|
|
|
$line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1097
|
|
|
$line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1098
|
|
|
if ( $summary !== '' ) { |
|
1099
|
|
|
$line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1100
|
|
|
} |
|
1101
|
|
|
$line_item .= '</td>'; |
|
1102
|
|
|
|
|
1103
|
|
|
$line_item .= '<td class="rate">' . esc_html__( wpinv_price( $item_price, $invoice->get_currency() ) ) . '</td>'; |
|
1104
|
|
|
if ($quantities_enabled) { |
|
1105
|
|
|
$cols++; |
|
1106
|
|
|
$line_item .= '<td class="qty">' . $quantity . '</td>'; |
|
1107
|
|
|
} |
|
1108
|
|
|
if ($use_taxes && !$zero_tax) { |
|
1109
|
|
|
$cols++; |
|
1110
|
|
|
$line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
|
1111
|
|
|
} |
|
1112
|
|
|
$line_item .= '<td class="total">' . esc_html__( wpinv_price( $line_total, $invoice->get_currency() ) ) . '</td>'; |
|
1113
|
|
|
$line_item .= '</tr>'; |
|
1114
|
|
|
|
|
1115
|
|
|
echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1116
|
|
|
|
|
1117
|
|
|
$count++; |
|
1118
|
|
|
} |
|
1119
|
|
|
|
|
1120
|
|
|
do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1121
|
|
|
?> |
|
1122
|
|
|
<tr class="row-sub-total row_odd"> |
|
1123
|
|
|
<td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1124
|
|
|
<td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1125
|
|
|
</tr> |
|
1126
|
|
|
<?php |
|
1127
|
|
|
do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1128
|
|
|
|
|
1129
|
|
View Code Duplication |
if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1130
|
|
|
do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1131
|
|
|
?> |
|
1132
|
|
|
<tr class="row-discount"> |
|
1133
|
|
|
<td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1134
|
|
|
<td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1135
|
|
|
</tr> |
|
1136
|
|
|
<?php |
|
1137
|
|
|
do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1138
|
|
|
} |
|
1139
|
|
|
|
|
1140
|
|
|
if ( $use_taxes ) { |
|
1141
|
|
|
do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1142
|
|
|
?> |
|
1143
|
|
|
<tr class="row-tax"> |
|
1144
|
|
|
<td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1145
|
|
|
<td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1146
|
|
|
</tr> |
|
1147
|
|
|
<?php |
|
1148
|
|
|
do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1149
|
|
|
} |
|
1150
|
|
|
|
|
1151
|
|
|
do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1152
|
|
|
?> |
|
1153
|
|
|
<tr class="table-active row-total"> |
|
1154
|
|
|
<td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1155
|
|
|
<td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1156
|
|
|
</tr> |
|
1157
|
|
|
<?php |
|
1158
|
|
|
do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1159
|
|
|
|
|
1160
|
|
|
do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1161
|
|
|
} |
|
1162
|
|
|
?> |
|
1163
|
|
|
</tbody> |
|
1164
|
|
|
</table> |
|
1165
|
|
|
<?php |
|
1166
|
|
|
echo ob_get_clean(); |
|
1167
|
|
|
} |
|
1168
|
|
|
|
|
1169
|
|
|
function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1170
|
|
|
$use_taxes = wpinv_use_taxes(); |
|
1171
|
|
|
|
|
1172
|
|
|
do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1173
|
|
|
?> |
|
1174
|
|
|
<table class="table table-sm table-bordered table-responsive"> |
|
1175
|
|
|
<tbody> |
|
1176
|
|
|
<?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1177
|
|
|
<tr class="row-sub-total"> |
|
1178
|
|
|
<td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1179
|
|
|
<td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1180
|
|
|
</tr> |
|
1181
|
|
|
<?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1182
|
|
|
<?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1183
|
|
|
<tr class="row-discount"> |
|
1184
|
|
|
<td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1185
|
|
|
<td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1186
|
|
|
</tr> |
|
1187
|
|
|
<?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1188
|
|
|
<?php } ?> |
|
1189
|
|
|
<?php if ( $use_taxes ) { ?> |
|
1190
|
|
|
<tr class="row-tax"> |
|
1191
|
|
|
<td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1192
|
|
|
<td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1193
|
|
|
</tr> |
|
1194
|
|
|
<?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1195
|
|
|
<?php } ?> |
|
1196
|
|
|
<?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1197
|
|
|
<?php foreach ( $fees as $fee ) { ?> |
|
1198
|
|
|
<tr class="row-fee"> |
|
1199
|
|
|
<td class="rate"><?php echo $fee['label']; ?></td> |
|
1200
|
|
|
<td class="total"><?php echo $fee['amount_display']; ?></td> |
|
1201
|
|
|
</tr> |
|
1202
|
|
|
<?php } ?> |
|
1203
|
|
|
<?php } ?> |
|
1204
|
|
|
<tr class="table-active row-total"> |
|
1205
|
|
|
<td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1206
|
|
|
<td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1207
|
|
|
</tr> |
|
1208
|
|
|
<?php do_action( 'wpinv_after_totals' ); ?> |
|
1209
|
|
|
</tbody> |
|
1210
|
|
|
|
|
1211
|
|
|
</table> |
|
1212
|
|
|
|
|
1213
|
|
|
<?php do_action( 'wpinv_after_totals_table' ); |
|
1214
|
|
|
} |
|
1215
|
|
|
|
|
1216
|
|
|
function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1217
|
|
|
$invoice = wpinv_get_invoice( $invoice_id ); |
|
1218
|
|
|
|
|
1219
|
|
|
ob_start(); |
|
1220
|
|
|
do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1221
|
|
|
if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
1222
|
|
|
?> |
|
1223
|
|
|
<div class="wpi-payment-info"> |
|
1224
|
|
|
<p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1225
|
|
|
<?php if ( $gateway_title ) { ?> |
|
1226
|
|
|
<p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1227
|
|
|
<?php } ?> |
|
1228
|
|
|
</div> |
|
1229
|
|
|
<?php |
|
1230
|
|
|
} |
|
1231
|
|
|
do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1232
|
|
|
$outout = ob_get_clean(); |
|
1233
|
|
|
|
|
1234
|
|
|
if ( $echo ) { |
|
1235
|
|
|
echo $outout; |
|
1236
|
|
|
} else { |
|
1237
|
|
|
return $outout; |
|
1238
|
|
|
} |
|
1239
|
|
|
} |
|
1240
|
|
|
|
|
1241
|
|
|
function wpinv_display_style( $invoice ) { |
|
|
|
|
|
|
1242
|
|
|
wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1243
|
|
|
|
|
1244
|
|
|
wp_print_styles( 'open-sans' ); |
|
1245
|
|
|
wp_print_styles( 'wpinv-single-style' ); |
|
1246
|
|
|
} |
|
1247
|
|
|
add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1248
|
|
|
|
|
1249
|
|
|
function wpinv_checkout_billing_details() { |
|
1250
|
|
|
$invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
1251
|
|
|
if (empty($invoice_id)) { |
|
1252
|
|
|
wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1253
|
|
|
return null; |
|
1254
|
|
|
} |
|
1255
|
|
|
|
|
1256
|
|
|
$invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1257
|
|
|
if (empty($invoice)) { |
|
1258
|
|
|
wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1259
|
|
|
return null; |
|
1260
|
|
|
} |
|
1261
|
|
|
$user_id = $invoice->get_user_id(); |
|
1262
|
|
|
$user_info = $invoice->get_user_info(); |
|
1263
|
|
|
$address_info = wpinv_get_user_address( $user_id ); |
|
1264
|
|
|
|
|
1265
|
|
|
if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1266
|
|
|
$user_info['first_name'] = $user_info['first_name']; |
|
1267
|
|
|
$user_info['last_name'] = $user_info['last_name']; |
|
1268
|
|
|
} |
|
1269
|
|
|
|
|
1270
|
|
|
if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1271
|
|
|
$user_info['country'] = $address_info['country']; |
|
1272
|
|
|
$user_info['state'] = $address_info['state']; |
|
1273
|
|
|
$user_info['city'] = $address_info['city']; |
|
1274
|
|
|
$user_info['zip'] = $address_info['zip']; |
|
1275
|
|
|
} |
|
1276
|
|
|
|
|
1277
|
|
|
$address_fields = array( |
|
1278
|
|
|
'user_id', |
|
1279
|
|
|
'company', |
|
1280
|
|
|
'vat_number', |
|
1281
|
|
|
'email', |
|
1282
|
|
|
'phone', |
|
1283
|
|
|
'address' |
|
1284
|
|
|
); |
|
1285
|
|
|
|
|
1286
|
|
|
foreach ( $address_fields as $field ) { |
|
1287
|
|
|
if ( empty( $user_info[$field] ) ) { |
|
1288
|
|
|
$user_info[$field] = $address_info[$field]; |
|
1289
|
|
|
} |
|
1290
|
|
|
} |
|
1291
|
|
|
|
|
1292
|
|
|
return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1293
|
|
|
} |
|
1294
|
|
|
|
|
1295
|
|
|
function wpinv_admin_get_line_items($invoice = array()) { |
|
1296
|
|
|
$item_quantities = wpinv_item_quantities_enabled(); |
|
1297
|
|
|
$use_taxes = wpinv_use_taxes(); |
|
1298
|
|
|
|
|
1299
|
|
|
if ( empty( $invoice ) ) { |
|
1300
|
|
|
return NULL; |
|
1301
|
|
|
} |
|
1302
|
|
|
|
|
1303
|
|
|
$cart_items = $invoice->get_cart_details(); |
|
|
|
|
|
|
1304
|
|
|
if ( empty( $cart_items ) ) { |
|
1305
|
|
|
return NULL; |
|
1306
|
|
|
} |
|
1307
|
|
|
ob_start(); |
|
1308
|
|
|
|
|
1309
|
|
|
do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1310
|
|
|
|
|
1311
|
|
|
$count = 0; |
|
1312
|
|
|
foreach ( $cart_items as $key => $cart_item ) { |
|
1313
|
|
|
$item_id = $cart_item['id']; |
|
1314
|
|
|
$wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1315
|
|
|
|
|
1316
|
|
|
if (empty($wpi_item)) { |
|
1317
|
|
|
continue; |
|
1318
|
|
|
} |
|
1319
|
|
|
|
|
1320
|
|
|
$item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
1321
|
|
|
$quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322
|
|
|
$item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
1323
|
|
|
$can_remove = true; |
|
1324
|
|
|
|
|
1325
|
|
|
$summary = ''; |
|
1326
|
|
View Code Duplication |
if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
|
1327
|
|
|
$post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1328
|
|
|
$summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link ); |
|
1329
|
|
|
} |
|
1330
|
|
|
$summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
1331
|
|
|
|
|
1332
|
|
|
$item_tax = ''; |
|
1333
|
|
|
$tax_rate = ''; |
|
1334
|
|
View Code Duplication |
if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1335
|
|
|
$item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1336
|
|
|
$tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1337
|
|
|
$tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1338
|
|
|
$tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
1339
|
|
|
} |
|
1340
|
|
|
$line_item_tax = $item_tax . $tax_rate; |
|
1341
|
|
|
|
|
1342
|
|
|
if ( $line_item_tax === '' ) { |
|
1343
|
|
|
$line_item_tax = 0; // Zero tax |
|
1344
|
|
|
} |
|
1345
|
|
|
|
|
1346
|
|
|
$line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1347
|
|
|
$line_item .= '<td class="id">' . $item_id . '</td>'; |
|
1348
|
|
|
$line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1349
|
|
|
if ( $summary !== '' ) { |
|
1350
|
|
|
$line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1351
|
|
|
} |
|
1352
|
|
|
$line_item .= '</td>'; |
|
1353
|
|
|
$line_item .= '<td class="price">' . $item_price . '</td>'; |
|
1354
|
|
|
|
|
1355
|
|
|
if ( $item_quantities ) { |
|
1356
|
|
|
if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1357
|
|
|
$can_remove = false; |
|
1358
|
|
|
} |
|
1359
|
|
|
$line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
|
1360
|
|
|
} else { |
|
1361
|
|
|
if ( count( $cart_items ) == 1 ) { |
|
1362
|
|
|
$can_remove = false; |
|
1363
|
|
|
} |
|
1364
|
|
|
} |
|
1365
|
|
|
$line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
|
1366
|
|
|
|
|
1367
|
|
|
if ( $use_taxes ) { |
|
1368
|
|
|
$line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
|
1369
|
|
|
} |
|
1370
|
|
|
$line_item .= '<td class="action">'; |
|
1371
|
|
|
if ( !$invoice->is_paid() && $can_remove ) { |
|
|
|
|
|
|
1372
|
|
|
$line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
|
1373
|
|
|
} |
|
1374
|
|
|
$line_item .= '</td>'; |
|
1375
|
|
|
$line_item .= '</tr>'; |
|
1376
|
|
|
|
|
1377
|
|
|
echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1378
|
|
|
|
|
1379
|
|
|
$count++; |
|
1380
|
|
|
} |
|
1381
|
|
|
|
|
1382
|
|
|
do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1383
|
|
|
|
|
1384
|
|
|
return ob_get_clean(); |
|
1385
|
|
|
} |
|
1386
|
|
|
|
|
1387
|
|
|
function wpinv_checkout_form() { |
|
1388
|
|
|
global $wpi_checkout_id; |
|
1389
|
|
|
|
|
1390
|
|
|
// Set current invoice id. |
|
1391
|
|
|
$wpi_checkout_id = wpinv_get_invoice_cart_id(); |
|
1392
|
|
|
|
|
1393
|
|
|
$form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1394
|
|
|
|
|
1395
|
|
|
ob_start(); |
|
1396
|
|
|
echo '<div id="wpinv_checkout_wrap">'; |
|
1397
|
|
|
|
|
1398
|
|
|
if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1399
|
|
|
?> |
|
1400
|
|
|
<div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
|
1401
|
|
|
<?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1402
|
|
|
<form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
|
1403
|
|
|
<?php |
|
1404
|
|
|
do_action( 'wpinv_checkout_form_top' ); |
|
1405
|
|
|
do_action( 'wpinv_checkout_billing_info' ); |
|
1406
|
|
|
do_action( 'wpinv_checkout_cart' ); |
|
1407
|
|
|
do_action( 'wpinv_payment_mode_select' ); |
|
1408
|
|
|
do_action( 'wpinv_checkout_form_bottom' ) |
|
1409
|
|
|
?> |
|
1410
|
|
|
</form> |
|
1411
|
|
|
<?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1412
|
|
|
</div><!--end #wpinv_checkout_form_wrap--> |
|
1413
|
|
|
<?php |
|
1414
|
|
|
} else { |
|
1415
|
|
|
do_action( 'wpinv_cart_empty' ); |
|
1416
|
|
|
} |
|
1417
|
|
|
echo '</div><!--end #wpinv_checkout_wrap-->'; |
|
1418
|
|
|
return ob_get_clean(); |
|
1419
|
|
|
} |
|
1420
|
|
|
|
|
1421
|
|
|
function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1422
|
|
|
global $ajax_cart_details; |
|
1423
|
|
|
$ajax_cart_details = $cart_details; |
|
1424
|
|
|
/* |
|
1425
|
|
|
// Check if the Update cart button should be shown |
|
1426
|
|
|
if( wpinv_item_quantities_enabled() ) { |
|
1427
|
|
|
add_action( 'wpinv_cart_footer_buttons', 'wpinv_update_cart_button' ); |
|
1428
|
|
|
} |
|
1429
|
|
|
|
|
1430
|
|
|
// Check if the Save Cart button should be shown |
|
1431
|
|
|
if( !wpinv_is_cart_saving_disabled() ) { |
|
1432
|
|
|
add_action( 'wpinv_cart_footer_buttons', 'wpinv_save_cart_button' ); |
|
1433
|
|
|
} |
|
1434
|
|
|
*/ |
|
1435
|
|
|
ob_start(); |
|
1436
|
|
|
do_action( 'wpinv_before_checkout_cart' ); |
|
1437
|
|
|
echo '<div id="wpinv_checkout_cart_form" method="post">'; |
|
1438
|
|
|
echo '<div id="wpinv_checkout_cart_wrap">'; |
|
1439
|
|
|
wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1440
|
|
|
echo '</div>'; |
|
1441
|
|
|
echo '</div>'; |
|
1442
|
|
|
do_action( 'wpinv_after_checkout_cart' ); |
|
1443
|
|
|
$content = ob_get_clean(); |
|
1444
|
|
|
|
|
1445
|
|
|
if ( $echo ) { |
|
1446
|
|
|
echo $content; |
|
1447
|
|
|
} else { |
|
1448
|
|
|
return $content; |
|
1449
|
|
|
} |
|
1450
|
|
|
} |
|
1451
|
|
|
add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1452
|
|
|
|
|
1453
|
|
|
function wpinv_empty_cart_message() { |
|
1454
|
|
|
return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1455
|
|
|
} |
|
1456
|
|
|
|
|
1457
|
|
|
/** |
|
1458
|
|
|
* Echoes the Empty Cart Message |
|
1459
|
|
|
* |
|
1460
|
|
|
* @since 1.0 |
|
1461
|
|
|
* @return void |
|
1462
|
|
|
*/ |
|
1463
|
|
|
function wpinv_empty_checkout_cart() { |
|
1464
|
|
|
echo wpinv_empty_cart_message(); |
|
1465
|
|
|
} |
|
1466
|
|
|
add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1467
|
|
|
|
|
1468
|
|
|
function wpinv_save_cart_button() { |
|
1469
|
|
|
if ( wpinv_is_cart_saving_disabled() ) |
|
1470
|
|
|
return; |
|
1471
|
|
|
?> |
|
1472
|
|
|
<a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1473
|
|
|
<?php |
|
1474
|
|
|
} |
|
1475
|
|
|
|
|
1476
|
|
|
function wpinv_update_cart_button() { |
|
1477
|
|
|
if ( !wpinv_item_quantities_enabled() ) |
|
1478
|
|
|
return; |
|
1479
|
|
|
?> |
|
1480
|
|
|
<input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1481
|
|
|
<input type="hidden" name="wpi_action" value="update_cart"/> |
|
1482
|
|
|
<?php |
|
1483
|
|
|
} |
|
1484
|
|
|
|
|
1485
|
|
|
function wpinv_checkout_cart_columns() { |
|
1486
|
|
|
$default = 3; |
|
1487
|
|
|
if ( wpinv_item_quantities_enabled() ) { |
|
1488
|
|
|
$default++; |
|
1489
|
|
|
} |
|
1490
|
|
|
|
|
1491
|
|
|
if ( wpinv_use_taxes() ) { |
|
1492
|
|
|
$default++; |
|
1493
|
|
|
} |
|
1494
|
|
|
|
|
1495
|
|
|
return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1496
|
|
|
} |
|
1497
|
|
|
|
|
1498
|
|
|
function wpinv_display_cart_messages() { |
|
1499
|
|
|
global $wpi_session; |
|
1500
|
|
|
|
|
1501
|
|
|
$messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1502
|
|
|
|
|
1503
|
|
|
if ( $messages ) { |
|
1504
|
|
|
foreach ( $messages as $message_id => $message ) { |
|
1505
|
|
|
// Try and detect what type of message this is |
|
1506
|
|
|
if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1507
|
|
|
$type = 'error'; |
|
1508
|
|
|
} elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1509
|
|
|
$type = 'success'; |
|
1510
|
|
|
} else { |
|
1511
|
|
|
$type = 'info'; |
|
1512
|
|
|
} |
|
1513
|
|
|
|
|
1514
|
|
|
$classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1515
|
|
|
|
|
1516
|
|
|
echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1517
|
|
|
// Loop message codes and display messages |
|
1518
|
|
|
echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
|
1519
|
|
|
echo '</div>'; |
|
1520
|
|
|
} |
|
1521
|
|
|
|
|
1522
|
|
|
// Remove all of the cart saving messages |
|
1523
|
|
|
$wpi_session->set( 'wpinv_cart_messages', null ); |
|
1524
|
|
|
} |
|
1525
|
|
|
} |
|
1526
|
|
|
add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1527
|
|
|
|
|
1528
|
|
|
function wpinv_discount_field() { |
|
1529
|
|
|
if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1530
|
|
|
return; // Only show before a payment method has been selected if ajax is disabled |
|
1531
|
|
|
} |
|
1532
|
|
|
|
|
1533
|
|
|
if ( !wpinv_is_checkout() ) { |
|
1534
|
|
|
return; |
|
1535
|
|
|
} |
|
1536
|
|
|
|
|
1537
|
|
|
if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1538
|
|
|
?> |
|
1539
|
|
|
<div id="wpinv-discount-field" class="panel panel-default"> |
|
1540
|
|
|
<div class="panel-body"> |
|
1541
|
|
|
<p> |
|
1542
|
|
|
<label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1543
|
|
|
<span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1544
|
|
|
</p> |
|
1545
|
|
|
<div class="form-group row"> |
|
1546
|
|
|
<div class="col-sm-4"> |
|
1547
|
|
|
<input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1548
|
|
|
</div> |
|
1549
|
|
|
<div class="col-sm-3"> |
|
1550
|
|
|
<button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1551
|
|
|
</div> |
|
1552
|
|
|
<div class="col-sm-12 wpinv-discount-msg"> |
|
1553
|
|
|
<div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div> |
|
1554
|
|
|
<div class="alert alert-error"><i class="fa fa-warning"></i><span class="wpi-msg"></span></div> |
|
1555
|
|
|
</div> |
|
1556
|
|
|
</div> |
|
1557
|
|
|
</div> |
|
1558
|
|
|
</div> |
|
1559
|
|
|
<?php |
|
1560
|
|
|
} |
|
1561
|
|
|
} |
|
1562
|
|
|
add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1563
|
|
|
|
|
1564
|
|
|
function wpinv_agree_to_terms_js() { |
|
1565
|
|
|
if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1566
|
|
|
?> |
|
1567
|
|
|
<script type="text/javascript"> |
|
1568
|
|
|
jQuery(document).ready(function($){ |
|
1569
|
|
|
$( document.body ).on('click', '.wpinv_terms_links', function(e) { |
|
1570
|
|
|
//e.preventDefault(); |
|
1571
|
|
|
$('#wpinv_terms').slideToggle(); |
|
1572
|
|
|
$('.wpinv_terms_links').toggle(); |
|
1573
|
|
|
return false; |
|
1574
|
|
|
}); |
|
1575
|
|
|
}); |
|
1576
|
|
|
</script> |
|
1577
|
|
|
<?php |
|
1578
|
|
|
} |
|
1579
|
|
|
} |
|
1580
|
|
|
add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1581
|
|
|
|
|
1582
|
|
|
function wpinv_payment_mode_select() { |
|
1583
|
|
|
$gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1584
|
|
|
$gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1585
|
|
|
$page_URL = wpinv_get_current_page_url(); |
|
|
|
|
|
|
1586
|
|
|
|
|
1587
|
|
|
do_action('wpinv_payment_mode_top'); |
|
1588
|
|
|
$invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
1589
|
|
|
?> |
|
1590
|
|
|
<div id="wpinv_payment_mode_select"> |
|
1591
|
|
|
<?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1592
|
|
|
<div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
|
1593
|
|
|
<div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1594
|
|
|
<div class="panel-body list-group wpi-payment_methods"> |
|
1595
|
|
|
<?php |
|
1596
|
|
|
do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1597
|
|
|
$chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1598
|
|
|
|
|
1599
|
|
|
if(!empty($gateways)){ |
|
1600
|
|
|
foreach ( $gateways as $gateway_id => $gateway ) { |
|
1601
|
|
|
$checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1602
|
|
|
$button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1603
|
|
|
$description = wpinv_get_gateway_description( $gateway_id ); |
|
1604
|
|
|
?> |
|
1605
|
|
|
<div class="list-group-item"> |
|
1606
|
|
|
<div class="radio"> |
|
1607
|
|
|
<label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
1608
|
|
|
</div> |
|
1609
|
|
|
<div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1610
|
|
|
<?php if ( !empty( $description ) ) { ?> |
|
1611
|
|
|
<div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1612
|
|
|
<?php } ?> |
|
1613
|
|
|
<?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1614
|
|
|
</div> |
|
1615
|
|
|
</div> |
|
1616
|
|
|
<?php |
|
1617
|
|
|
} |
|
1618
|
|
|
}else{ |
|
1619
|
|
|
echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
1620
|
|
|
} |
|
1621
|
|
|
|
|
1622
|
|
|
do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1623
|
|
|
?> |
|
1624
|
|
|
</div> |
|
1625
|
|
|
</div> |
|
1626
|
|
|
<?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1627
|
|
|
</div> |
|
1628
|
|
|
<?php |
|
1629
|
|
|
do_action('wpinv_payment_mode_bottom'); |
|
1630
|
|
|
} |
|
1631
|
|
|
add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1632
|
|
|
|
|
1633
|
|
|
function wpinv_checkout_billing_info() { |
|
1634
|
|
|
if ( wpinv_is_checkout() ) { |
|
1635
|
|
|
$logged_in = is_user_logged_in(); |
|
|
|
|
|
|
1636
|
|
|
$billing_details = wpinv_checkout_billing_details(); |
|
1637
|
|
|
$selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1638
|
|
|
?> |
|
1639
|
|
|
<div id="wpinv-fields" class="clearfix"> |
|
1640
|
|
|
<div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
|
1641
|
|
|
<div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1642
|
|
|
<div id="wpinv-fields-box" class="panel-body"> |
|
1643
|
|
|
<?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1644
|
|
|
<p class="wpi-cart-field wpi-col2 wpi-colf"> |
|
1645
|
|
|
<label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1646
|
|
|
<?php |
|
1647
|
|
|
echo wpinv_html_text( array( |
|
1648
|
|
|
'id' => 'wpinv_first_name', |
|
1649
|
|
|
'name' => 'wpinv_first_name', |
|
1650
|
|
|
'value' => $billing_details['first_name'], |
|
1651
|
|
|
'class' => 'wpi-input form-control required', |
|
1652
|
|
|
'placeholder' => __( 'First name', 'invoicing' ), |
|
1653
|
|
|
'required' => true, |
|
1654
|
|
|
) ); |
|
1655
|
|
|
?> |
|
1656
|
|
|
</p> |
|
1657
|
|
|
<p class="wpi-cart-field wpi-col2 wpi-coll"> |
|
1658
|
|
|
<label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label> |
|
1659
|
|
|
<?php |
|
1660
|
|
|
echo wpinv_html_text( array( |
|
1661
|
|
|
'id' => 'wpinv_last_name', |
|
1662
|
|
|
'name' => 'wpinv_last_name', |
|
1663
|
|
|
'value' => $billing_details['last_name'], |
|
1664
|
|
|
'class' => 'wpi-input form-control', |
|
1665
|
|
|
'placeholder' => __( 'Last name', 'invoicing' ), |
|
1666
|
|
|
) ); |
|
1667
|
|
|
?> |
|
1668
|
|
|
</p> |
|
1669
|
|
|
<p class="wpi-cart-field wpi-col2 wpi-colf"> |
|
1670
|
|
|
<label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1671
|
|
|
<?php |
|
1672
|
|
|
echo wpinv_html_text( array( |
|
1673
|
|
|
'id' => 'wpinv_address', |
|
1674
|
|
|
'name' => 'wpinv_address', |
|
1675
|
|
|
'value' => $billing_details['address'], |
|
1676
|
|
|
'class' => 'wpi-input form-control required', |
|
1677
|
|
|
'placeholder' => __( 'Address', 'invoicing' ), |
|
1678
|
|
|
'required' => true, |
|
1679
|
|
|
) ); |
|
1680
|
|
|
?> |
|
1681
|
|
|
</p> |
|
1682
|
|
|
<p class="wpi-cart-field wpi-col2 wpi-coll"> |
|
1683
|
|
|
<label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1684
|
|
|
<?php |
|
1685
|
|
|
echo wpinv_html_text( array( |
|
1686
|
|
|
'id' => 'wpinv_city', |
|
1687
|
|
|
'name' => 'wpinv_city', |
|
1688
|
|
|
'value' => $billing_details['city'], |
|
1689
|
|
|
'class' => 'wpi-input form-control required', |
|
1690
|
|
|
'placeholder' => __( 'City', 'invoicing' ), |
|
1691
|
|
|
'required' => true, |
|
1692
|
|
|
) ); |
|
1693
|
|
|
?> |
|
1694
|
|
|
</p> |
|
1695
|
|
|
<p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
|
1696
|
|
|
<label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1697
|
|
|
<?php echo wpinv_html_select( array( |
|
1698
|
|
|
'options' => wpinv_get_country_list(), |
|
1699
|
|
|
'name' => 'wpinv_country', |
|
1700
|
|
|
'id' => 'wpinv_country', |
|
1701
|
|
|
'selected' => $selected_country, |
|
1702
|
|
|
'show_option_all' => false, |
|
1703
|
|
|
'show_option_none' => false, |
|
1704
|
|
|
'class' => 'wpi-input form-control required', |
|
1705
|
|
|
'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1706
|
|
|
'required' => true, |
|
1707
|
|
|
) ); ?> |
|
1708
|
|
|
</p> |
|
1709
|
|
|
<p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
|
1710
|
|
|
<label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1711
|
|
|
<?php |
|
1712
|
|
|
$states = wpinv_get_country_states( $selected_country ); |
|
1713
|
|
|
if( !empty( $states ) ) { |
|
1714
|
|
|
echo wpinv_html_select( array( |
|
1715
|
|
|
'options' => $states, |
|
1716
|
|
|
'name' => 'wpinv_state', |
|
1717
|
|
|
'id' => 'wpinv_state', |
|
1718
|
|
|
'selected' => $billing_details['state'], |
|
1719
|
|
|
'show_option_all' => false, |
|
1720
|
|
|
'show_option_none' => false, |
|
1721
|
|
|
'class' => 'wpi-input form-control required', |
|
1722
|
|
|
'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1723
|
|
|
'required' => true, |
|
1724
|
|
|
) ); |
|
1725
|
|
|
} else { |
|
1726
|
|
|
echo wpinv_html_text( array( |
|
1727
|
|
|
'name' => 'wpinv_state', |
|
1728
|
|
|
'value' => $billing_details['state'], |
|
1729
|
|
|
'id' => 'wpinv_state', |
|
1730
|
|
|
'class' => 'wpi-input form-control required', |
|
1731
|
|
|
'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1732
|
|
|
'required' => true, |
|
1733
|
|
|
) ); |
|
1734
|
|
|
} |
|
1735
|
|
|
?> |
|
1736
|
|
|
</p> |
|
1737
|
|
|
<p class="wpi-cart-field wpi-col2 wpi-colf"> |
|
1738
|
|
|
<label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label> |
|
1739
|
|
|
<?php |
|
1740
|
|
|
echo wpinv_html_text( array( |
|
1741
|
|
|
'name' => 'wpinv_zip', |
|
1742
|
|
|
'value' => $billing_details['zip'], |
|
1743
|
|
|
'id' => 'wpinv_zip', |
|
1744
|
|
|
'class' => 'wpi-input form-control', |
|
1745
|
|
|
'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1746
|
|
|
) ); |
|
1747
|
|
|
?> |
|
1748
|
|
|
</p> |
|
1749
|
|
|
<p class="wpi-cart-field wpi-col2 wpi-coll"> |
|
1750
|
|
|
<label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1751
|
|
|
<?php |
|
1752
|
|
|
echo wpinv_html_text( array( |
|
1753
|
|
|
'id' => 'wpinv_phone', |
|
1754
|
|
|
'name' => 'wpinv_phone', |
|
1755
|
|
|
'value' => $billing_details['phone'], |
|
1756
|
|
|
'class' => 'wpi-input form-control', |
|
1757
|
|
|
'placeholder' => __( 'Phone', 'invoicing' ), |
|
1758
|
|
|
'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1759
|
|
|
) ); |
|
1760
|
|
|
?> |
|
1761
|
|
|
</p> |
|
1762
|
|
|
<?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1763
|
|
|
<div class="clearfix"></div> |
|
1764
|
|
|
</div> |
|
1765
|
|
|
</div> |
|
1766
|
|
|
<?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1767
|
|
|
</div> |
|
1768
|
|
|
<?php |
|
1769
|
|
|
} |
|
1770
|
|
|
} |
|
1771
|
|
|
add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1772
|
|
|
|
|
1773
|
|
|
function wpinv_checkout_hidden_fields() { |
|
1774
|
|
|
?> |
|
1775
|
|
|
<?php if ( is_user_logged_in() ) { ?> |
|
1776
|
|
|
<input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
|
1777
|
|
|
<?php } ?> |
|
1778
|
|
|
<input type="hidden" name="wpi_action" value="payment" /> |
|
1779
|
|
|
<?php |
|
1780
|
|
|
} |
|
1781
|
|
|
|
|
1782
|
|
|
function wpinv_checkout_button_purchase() { |
|
1783
|
|
|
ob_start(); |
|
1784
|
|
|
?> |
|
1785
|
|
|
<input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1786
|
|
|
<?php |
|
1787
|
|
|
return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1788
|
|
|
} |
|
1789
|
|
|
|
|
1790
|
|
|
function wpinv_checkout_total() { |
|
1791
|
|
|
global $cart_total; |
|
1792
|
|
|
?> |
|
1793
|
|
|
<div id="wpinv_checkout_total" class="panel panel-info"> |
|
1794
|
|
|
<div class="panel-body"> |
|
1795
|
|
|
<?php |
|
1796
|
|
|
do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1797
|
|
|
?> |
|
1798
|
|
|
<strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1799
|
|
|
<?php |
|
1800
|
|
|
do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1801
|
|
|
?> |
|
1802
|
|
|
</div> |
|
1803
|
|
|
</div> |
|
1804
|
|
|
<?php |
|
1805
|
|
|
} |
|
1806
|
|
|
add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1807
|
|
|
|
|
1808
|
|
|
function wpinv_checkout_submit() { |
|
1809
|
|
|
?> |
|
1810
|
|
|
<div id="wpinv_purchase_submit" class="panel panel-success"> |
|
1811
|
|
|
<div class="panel-body text-center"> |
|
1812
|
|
|
<?php |
|
1813
|
|
|
do_action( 'wpinv_purchase_form_before_submit' ); |
|
1814
|
|
|
wpinv_checkout_hidden_fields(); |
|
1815
|
|
|
echo wpinv_checkout_button_purchase(); |
|
1816
|
|
|
do_action( 'wpinv_purchase_form_after_submit' ); |
|
1817
|
|
|
?> |
|
1818
|
|
|
</div> |
|
1819
|
|
|
</div> |
|
1820
|
|
|
<?php |
|
1821
|
|
|
} |
|
1822
|
|
|
add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1823
|
|
|
|
|
1824
|
|
|
function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1825
|
|
|
$invoice = wpinv_get_invoice( $invoice_id ); |
|
1826
|
|
|
|
|
1827
|
|
|
if ( empty( $invoice ) ) { |
|
1828
|
|
|
return NULL; |
|
1829
|
|
|
} |
|
1830
|
|
|
|
|
1831
|
|
|
$billing_details = $invoice->get_user_info(); |
|
1832
|
|
|
$address_row = ''; |
|
1833
|
|
|
if ( $address = $billing_details['address'] ) { |
|
1834
|
|
|
$address_row .= wpautop( wp_kses_post( $address ) ); |
|
1835
|
|
|
} |
|
1836
|
|
|
|
|
1837
|
|
|
$address_fields = array(); |
|
1838
|
|
|
if ( !empty( $billing_details['city'] ) ) { |
|
1839
|
|
|
$address_fields[] = $billing_details['city']; |
|
1840
|
|
|
} |
|
1841
|
|
|
|
|
1842
|
|
|
$billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1843
|
|
|
if ( !empty( $billing_details['state'] ) ) { |
|
1844
|
|
|
$address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1845
|
|
|
} |
|
1846
|
|
|
|
|
1847
|
|
|
if ( !empty( $billing_country ) ) { |
|
1848
|
|
|
$address_fields[] = wpinv_country_name( $billing_country ); |
|
1849
|
|
|
} |
|
1850
|
|
|
|
|
1851
|
|
View Code Duplication |
if ( !empty( $address_fields ) ) { |
|
1852
|
|
|
$address_fields = implode( ", ", $address_fields ); |
|
1853
|
|
|
|
|
1854
|
|
|
if ( !empty( $billing_details['zip'] ) ) { |
|
1855
|
|
|
$address_fields .= ' ' . $billing_details['zip']; |
|
1856
|
|
|
} |
|
1857
|
|
|
|
|
1858
|
|
|
$address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1859
|
|
|
} |
|
1860
|
|
|
ob_start(); |
|
1861
|
|
|
?> |
|
1862
|
|
|
<table class="table table-bordered table-sm wpi-billing-details"> |
|
1863
|
|
|
<tbody> |
|
1864
|
|
|
<tr class="wpi-receipt-name"> |
|
1865
|
|
|
<th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1866
|
|
|
<td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1867
|
|
|
</tr> |
|
1868
|
|
|
<tr class="wpi-receipt-email"> |
|
1869
|
|
|
<th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1870
|
|
|
<td><?php echo $billing_details['email'] ;?></td> |
|
1871
|
|
|
</tr> |
|
1872
|
|
View Code Duplication |
<?php if ( $billing_details['company'] ) { ?> |
|
1873
|
|
|
<tr class="wpi-receipt-company"> |
|
1874
|
|
|
<th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1875
|
|
|
<td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1876
|
|
|
</tr> |
|
1877
|
|
|
<?php } ?> |
|
1878
|
|
|
<tr class="wpi-receipt-address"> |
|
1879
|
|
|
<th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1880
|
|
|
<td><?php echo $address_row ;?></td> |
|
1881
|
|
|
</tr> |
|
1882
|
|
View Code Duplication |
<?php if ( $billing_details['phone'] ) { ?> |
|
1883
|
|
|
<tr class="wpi-receipt-phone"> |
|
1884
|
|
|
<th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1885
|
|
|
<td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1886
|
|
|
</tr> |
|
1887
|
|
|
<?php } ?> |
|
1888
|
|
|
</tbody> |
|
1889
|
|
|
</table> |
|
1890
|
|
|
<?php |
|
1891
|
|
|
$output = ob_get_clean(); |
|
1892
|
|
|
|
|
1893
|
|
|
$output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1894
|
|
|
|
|
1895
|
|
|
echo $output; |
|
1896
|
|
|
} |
|
1897
|
|
|
|
|
1898
|
|
|
function wpinv_filter_success_page_content( $content ) { |
|
1899
|
|
|
if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1900
|
|
|
if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1901
|
|
|
$content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1902
|
|
|
} |
|
1903
|
|
|
} |
|
1904
|
|
|
|
|
1905
|
|
|
return $content; |
|
1906
|
|
|
} |
|
1907
|
|
|
add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1908
|
|
|
|
|
1909
|
|
|
function wpinv_receipt_actions( $invoice ) { |
|
1910
|
|
|
if ( !empty( $invoice ) ) { |
|
1911
|
|
|
$actions = array( |
|
1912
|
|
|
'print' => array( |
|
1913
|
|
|
'url' => $invoice->get_view_url(), |
|
1914
|
|
|
'name' => __( 'Print Invoice', 'invoicing' ), |
|
1915
|
|
|
'class' => 'btn-primary', |
|
1916
|
|
|
), |
|
1917
|
|
|
'history' => array( |
|
1918
|
|
|
'url' => wpinv_get_history_page_uri(), |
|
1919
|
|
|
'name' => __( 'Invoice History', 'invoicing' ), |
|
1920
|
|
|
'class' => 'btn-warning', |
|
1921
|
|
|
) |
|
1922
|
|
|
); |
|
1923
|
|
|
|
|
1924
|
|
|
$actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1925
|
|
|
|
|
1926
|
|
|
if ( !empty( $actions ) ) { |
|
1927
|
|
|
?> |
|
1928
|
|
|
<div class="wpinv-receipt-actions text-right"> |
|
1929
|
|
|
<?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1930
|
|
|
<a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1931
|
|
|
<?php } ?> |
|
1932
|
|
|
</div> |
|
1933
|
|
|
<?php |
|
1934
|
|
|
} |
|
1935
|
|
|
} |
|
1936
|
|
|
} |
|
1937
|
|
|
add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1938
|
|
|
|
|
1939
|
|
|
function wpinv_invoice_link( $invoice_id ) { |
|
1940
|
|
|
$invoice = wpinv_get_invoice( $invoice_id ); |
|
1941
|
|
|
|
|
1942
|
|
|
if ( empty( $invoice ) ) { |
|
1943
|
|
|
return NULL; |
|
1944
|
|
|
} |
|
1945
|
|
|
|
|
1946
|
|
|
$invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1947
|
|
|
|
|
1948
|
|
|
return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1949
|
|
|
} |
|
1950
|
|
|
|
|
1951
|
|
|
function wpinv_invoice_subscription_details( $invoice ) { |
|
1952
|
|
|
if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1953
|
|
|
$total_payments = (int)$invoice->get_total_payments(); |
|
1954
|
|
|
$payments = $invoice->get_child_payments(); |
|
1955
|
|
|
|
|
1956
|
|
|
$subscription = $invoice->get_subscription_data(); |
|
1957
|
|
|
|
|
1958
|
|
|
if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
1959
|
|
|
return; |
|
1960
|
|
|
} |
|
1961
|
|
|
|
|
1962
|
|
|
$billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
1963
|
|
|
$times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
1964
|
|
|
|
|
1965
|
|
|
$subscription_status = $invoice->get_subscription_status(); |
|
1966
|
|
|
|
|
1967
|
|
|
$status_desc = ''; |
|
1968
|
|
|
if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
1969
|
|
|
$status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
1970
|
|
|
} else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
1971
|
|
|
$status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
1972
|
|
|
} |
|
1973
|
|
|
$status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
|
1974
|
|
|
?> |
|
1975
|
|
|
<div class="wpinv-subscriptions-details"> |
|
1976
|
|
|
<h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1977
|
|
|
<table class="table"> |
|
1978
|
|
|
<thead> |
|
1979
|
|
|
<tr> |
|
1980
|
|
|
<th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1981
|
|
|
<th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1982
|
|
|
<th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1983
|
|
|
<th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1984
|
|
|
<th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1985
|
|
|
</tr> |
|
1986
|
|
|
</thead> |
|
1987
|
|
|
<tbody> |
|
1988
|
|
|
<tr> |
|
1989
|
|
|
<td><?php echo $billing_cycle; ?></td> |
|
1990
|
|
|
<td><?php echo $invoice->get_subscription_start(); ?></td> |
|
1991
|
|
|
<td><?php echo $invoice->get_subscription_end(); ?></td> |
|
1992
|
|
|
<td class="text-center"><?php echo $times_billed; ?></td> |
|
1993
|
|
|
<td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
1994
|
|
|
<?php echo $status_desc; ?> |
|
1995
|
|
|
</td> |
|
1996
|
|
|
</tr> |
|
1997
|
|
|
</tbody> |
|
1998
|
|
|
</table> |
|
1999
|
|
|
</div> |
|
2000
|
|
|
<?php if ( !empty( $payments ) ) { ?> |
|
2001
|
|
|
<div class="wpinv-renewal-payments"> |
|
2002
|
|
|
<h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
2003
|
|
|
<table class="table"> |
|
2004
|
|
|
<thead> |
|
2005
|
|
|
<tr> |
|
2006
|
|
|
<th>#</th> |
|
2007
|
|
|
<th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2008
|
|
|
<th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2009
|
|
|
<th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2010
|
|
|
</tr> |
|
2011
|
|
|
</thead> |
|
2012
|
|
|
<tbody> |
|
2013
|
|
|
<?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
2014
|
|
|
<tr> |
|
2015
|
|
|
<th scope="row"><?php echo ( $key + 1 );?></th> |
|
2016
|
|
|
<td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2017
|
|
|
<td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2018
|
|
|
<td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2019
|
|
|
</tr> |
|
2020
|
|
|
<?php } ?> |
|
2021
|
|
|
<tr><td colspan="4" style="padding:0"></td></tr> |
|
2022
|
|
|
</tbody> |
|
2023
|
|
|
</table> |
|
2024
|
|
|
</div> |
|
2025
|
|
|
<?php } ?> |
|
2026
|
|
|
<?php |
|
2027
|
|
|
} |
|
2028
|
|
|
} |
|
2029
|
|
|
|
|
2030
|
|
|
function wpinv_cart_total_label( $label, $invoice ) { |
|
2031
|
|
|
if ( empty( $invoice ) ) { |
|
2032
|
|
|
return $label; |
|
2033
|
|
|
} |
|
2034
|
|
|
|
|
2035
|
|
|
$prefix_label = ''; |
|
2036
|
|
|
if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2037
|
|
|
$prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2038
|
|
|
} else if ( $invoice->is_renewal() ) { |
|
2039
|
|
|
$prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2040
|
|
|
} |
|
2041
|
|
|
|
|
2042
|
|
|
if ( $prefix_label != '' ) { |
|
2043
|
|
|
$label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2044
|
|
|
} |
|
2045
|
|
|
|
|
2046
|
|
|
return $label; |
|
2047
|
|
|
} |
|
2048
|
|
|
add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2049
|
|
|
add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2050
|
|
|
add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2051
|
|
|
|
|
2052
|
|
|
add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2053
|
|
|
|
|
2054
|
|
|
function wpinv_invoice_print_description( $invoice ) { |
|
2055
|
|
|
if ( empty( $invoice ) ) { |
|
2056
|
|
|
return NULL; |
|
2057
|
|
|
} |
|
2058
|
|
|
if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2059
|
|
|
?> |
|
2060
|
|
|
<div class="row wpinv-lower"> |
|
2061
|
|
|
<div class="col-sm-12 wpinv-description"> |
|
2062
|
|
|
<?php echo wpautop( $description ); ?> |
|
2063
|
|
|
</div> |
|
2064
|
|
|
</div> |
|
2065
|
|
|
<?php |
|
2066
|
|
|
} |
|
2067
|
|
|
} |
|
2068
|
|
|
add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2069
|
|
|
|
|
2070
|
|
|
function wpinv_invoice_print_payment_info( $invoice ) { |
|
2071
|
|
|
if ( empty( $invoice ) ) { |
|
2072
|
|
|
return NULL; |
|
2073
|
|
|
} |
|
2074
|
|
|
|
|
2075
|
|
|
if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2076
|
|
|
?> |
|
2077
|
|
|
<div class="row wpinv-payments"> |
|
2078
|
|
|
<div class="col-sm-12"> |
|
2079
|
|
|
<?php echo $payments_info; ?> |
|
2080
|
|
|
</div> |
|
2081
|
|
|
</div> |
|
2082
|
|
|
<?php |
|
2083
|
|
|
} |
|
2084
|
|
|
} |
|
2085
|
|
|
// add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
|
|
|
|
|
|
2086
|
|
|
|
|
2087
|
|
|
function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2088
|
|
|
if ( empty( $note ) ) { |
|
2089
|
|
|
return NULL; |
|
2090
|
|
|
} |
|
2091
|
|
|
|
|
2092
|
|
|
if ( is_int( $note ) ) { |
|
2093
|
|
|
$note = get_comment( $note ); |
|
2094
|
|
|
} |
|
2095
|
|
|
|
|
2096
|
|
|
if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2097
|
|
|
return NULL; |
|
2098
|
|
|
} |
|
2099
|
|
|
|
|
2100
|
|
|
$note_classes = array( 'note' ); |
|
2101
|
|
|
$note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2102
|
|
|
$note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : ''; |
|
2103
|
|
|
$note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2104
|
|
|
$note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2105
|
|
|
|
|
2106
|
|
|
ob_start(); |
|
2107
|
|
|
?> |
|
2108
|
|
|
<li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2109
|
|
|
<div class="note_content"> |
|
2110
|
|
|
<?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2111
|
|
|
</div> |
|
2112
|
|
|
<p class="meta"> |
|
2113
|
|
|
<abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2114
|
|
|
</p> |
|
2115
|
|
|
</li> |
|
2116
|
|
|
<?php |
|
2117
|
|
|
$note_content = ob_get_clean(); |
|
2118
|
|
|
$note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2119
|
|
|
|
|
2120
|
|
|
if ( $echo ) { |
|
2121
|
|
|
echo $note_content; |
|
2122
|
|
|
} else { |
|
2123
|
|
|
return $note_content; |
|
2124
|
|
|
} |
|
2125
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.