Completed
Push — master ( 43d636...8512bc )
by Brian
20s queued 17s
created

WPInv_Payment_Form_Elements::edit_items_template()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 162
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 2
Metric Value
cc 6
eloc 70
nc 8
nop 1
dl 0
loc 162
rs 8.0323
c 6
b 0
f 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
    exit; // Exit if accessed directly
5
}
6
7
class WPInv_Payment_Form_Elements {
8
9
    /**
10
     * @param array payment form elements
11
     */
12
    protected $elements;
13
14
    public function __construct() {
15
16
        foreach( $this->get_elements() as $element ) {
17
            $element = $element['type'];
18
19
            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
21
            }
22
23
            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
25
            }
26
27
            if ( method_exists( $this, "frontend_render_{$element}_template" ) ) {
28
                add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 );
29
            }
30
31
        }
32
        
33
    }
34
35
    /**
36
     * Returns all the elements that can be added to a form.
37
     */
38
    public function get_elements() {
39
40
        if ( ! empty( $this->elements ) ) {
41
            return $this->elements;
42
        }
43
44
        $this->elements = array(
45
46
            array(
47
                'type'     => 'heading',
48
                'name'     => __( 'Heading', 'invoicing' ),
49
                'defaults' => array(
50
                    'level' => 'h2',
51
                    'text'  => __( 'Heading', 'invoicing' ),
52
                )
53
            ),
54
55
            array(
56
                'type' => 'paragraph',
57
                'name' => __( 'Paragraph', 'invoicing' ),
58
                'defaults'  => array(
59
                    'text'  => __( 'Paragraph text', 'invoicing' ),
60
                )
61
            ),
62
63
            array( 
64
                'type' => 'alert',
65
                'name' => __( 'Alert', 'invoicing' ),
66
                'defaults'  => array(
67
                    'value'        => '',
68
                    'class'        => 'alert-warning',
69
                    'text'         => __( 'Alert', 'invoicing' ),
70
                    'dismissible'  => false,
71
                )
72
            ),
73
74
            /*array( 
75
                'type' => 'separator',
76
                'name' => __( 'Separator', 'invoicing' ),
77
                'defaults'  => array(
78
                    'value'        => '',
79
                    'dismissible'  => false,
80
                )
81
            ),*/
82
83
            array(
84
                'type' => 'text',
85
                'name' => __( 'Text Input', 'invoicing' ),
86
                'defaults'  => array(
87
                    'placeholder'  => __( 'Enter some text', 'invoicing' ),
88
                    'value'        => '',
89
                    'label'        => __( 'Field Label', 'invoicing' ),
90
                    'description'  => '',
91
                    'required'     => false,
92
                )
93
            ),
94
95
            array(
96
                'type' => 'textarea',
97
                'name' => __( 'Textarea', 'invoicing' ),
98
                'defaults'         => array(
99
                    'placeholder'  => __( 'Enter your text hear', 'invoicing' ),
100
                    'value'        => '',
101
                    'label'        => __( 'Textarea Label', 'invoicing' ),
102
                    'description'  => '',
103
                    'required'     => false,
104
                )
105
            ),
106
107
            array(
108
                'type' => 'select',
109
                'name' => __( 'Dropdown', 'invoicing' ),
110
                'defaults'         => array(
111
                    'placeholder'  => __( 'Select a value', 'invoicing' ),
112
                    'value'        => '',
113
                    'label'        => __( 'Dropdown Label', 'invoicing' ),
114
                    'description'  => '',
115
                    'required'     => false,
116
                    'options'      => array(
117
                        esc_attr__( 'Option One', 'invoicing' ),
118
                        esc_attr__( 'Option Two', 'invoicing' ),
119
                        esc_attr__( 'Option Three', 'invoicing' )
120
                    ),
121
                )
122
            ),
123
124
            array(
125
                'type' => 'checkbox',
126
                'name' => __( 'Checkbox', 'invoicing' ),
127
                'defaults'         => array(
128
                    'value'        => '',
129
                    'label'        => __( 'Checkbox Label', 'invoicing' ),
130
                    'description'  => '',
131
                    'required'     => false,
132
                )
133
            ),
134
135
            array( 
136
                'type' => 'radio',
137
                'name' => __( 'Multiple Choice', 'invoicing' ),
138
                'defaults'     => array(
139
                    'label'    => __( 'Select one choice', 'invoicing' ),
140
                    'options'  => array(
141
                        esc_attr__( 'Choice One', 'invoicing' ),
142
                        esc_attr__( 'Choice Two', 'invoicing' ),
143
                        esc_attr__( 'Choice Three', 'invoicing' )
144
                    ),
145
                )
146
            ),
147
148
            array( 
149
                'type' => 'date',
150
                'name' => __( 'Date', 'invoicing' ),
151
                'defaults' => array(
152
                    'value'        => '',
153
                    'label'        => __( 'Date', 'invoicing' ),
154
                    'description'  => '',
155
                    'required'     => false,
156
                )
157
            ),
158
159
            array( 
160
                'type' => 'time',
161
                'name' => __( 'Time', 'invoicing' ),
162
                'defaults' => array(
163
                    'value'        => '',
164
                    'label'        => __( 'Time', 'invoicing' ),
165
                    'description'  => '',
166
                    'required'     => false,
167
                )
168
            ),
169
170
            array( 
171
                'type' => 'number',
172
                'name' => __( 'Number', 'invoicing' ),
173
                'defaults' => array(
174
                    'placeholder'  => '',
175
                    'value'        => '',
176
                    'label'        => __( 'Number', 'invoicing' ),
177
                    'description'  => '',
178
                    'required'     => false,
179
                )
180
            ),
181
182
            array( 
183
                'type' => 'website',
184
                'name' => __( 'Website', 'invoicing' ),
185
                'defaults' => array(
186
                    'placeholder'  => 'http://example.com',
187
                    'value'        => '',
188
                    'label'        => __( 'Website', 'invoicing' ),
189
                    'description'  => '',
190
                    'required'     => false,
191
                )
192
            ),
193
194
            array( 
195
                'type' => 'email',
196
                'name' => __( 'Email', 'invoicing' ),
197
                'defaults'  => array(
198
                    'placeholder'  => '[email protected]',
199
                    'value'        => '',
200
                    'label'        => __( 'Email Address', 'invoicing' ),
201
                    'description'  => '',
202
                    'required'     => false,
203
                )
204
            ),
205
206
            array( 
207
                'type' => 'address',
208
                'name' => __( 'Address', 'invoicing' ),
209
                'defaults'  => array(
210
211
                    'fields' => array(
212
                        array(
213
                            'placeholder'  => 'Jon',
214
                            'value'        => '',
215
                            'label'        => __( 'First Name', 'invoicing' ),
216
                            'description'  => '',
217
                            'required'     => false,
218
                            'visible'      => true,
219
                            'name'         => 'wpinv_first_name',
220
                        ),
221
222
                        array(
223
                            'placeholder'  => 'Snow',
224
                            'value'        => '',
225
                            'label'        => __( 'Last Name', 'invoicing' ),
226
                            'description'  => '',
227
                            'required'     => false,
228
                            'visible'      => true,
229
                            'name'         => 'wpinv_last_name',
230
                        ),
231
                    
232
                        array(
233
                            'placeholder'  => '',
234
                            'value'        => '',
235
                            'label'        => __( 'Address', 'invoicing' ),
236
                            'description'  => '',
237
                            'required'     => false,
238
                            'visible'      => true,
239
                            'name'         => 'wpinv_address',
240
                        ),
241
242
                        array(
243
                            'placeholder'  => '',
244
                            'value'        => '',
245
                            'label'        => __( 'City', 'invoicing' ),
246
                            'description'  => '',
247
                            'required'     => false,
248
                            'visible'      => true,
249
                            'name'         => 'wpinv_city',
250
                        ),
251
252
                        array(
253
                            'placeholder'  => __( 'Select your country' ),
254
                            'value'        => '',
255
                            'label'        => __( 'Country', 'invoicing' ),
256
                            'description'  => '',
257
                            'required'     => false,
258
                            'visible'      => true,
259
                            'name'         => 'wpinv_country',
260
                        ),
261
262
                        array(
263
                            'placeholder'  => __( 'Choose a state', 'invoicing' ),
264
                            'value'        => '',
265
                            'label'        => __( 'State / Province', 'invoicing' ),
266
                            'description'  => '',
267
                            'required'     => false,
268
                            'visible'      => true,
269
                            'name'         => 'wpinv_state',
270
                        ),
271
272
                        array(
273
                            'placeholder'  => '',
274
                            'value'        => '',
275
                            'label'        => __( 'ZIP / Postcode', 'invoicing' ),
276
                            'description'  => '',
277
                            'required'     => false,
278
                            'visible'      => true,
279
                            'name'         => 'wpinv_zip',
280
                        ),
281
282
                        array(
283
                            'placeholder'  => '',
284
                            'value'        => '',
285
                            'label'        => __( 'Phone', 'invoicing' ),
286
                            'description'  => '',
287
                            'required'     => false,
288
                            'visible'      => true,
289
                            'name'         => 'wpinv_phone',
290
                        )
291
                    )
292
                )
293
            ),
294
295
            array( 
296
                'type' => 'billing_email',
297
                'name' => __( 'Billing Email', 'invoicing' ),
298
                'defaults'  => array(
299
                    'placeholder'  => '[email protected]',
300
                    'value'        => '',
301
                    'label'        => __( 'Billing Email', 'invoicing' ),
302
                    'description'  => '',
303
                    'premade'      => true,
304
                )
305
            ),
306
/*
307
            array( 
308
                'type' => 'discount',
309
                'name' => __( 'Discount Input', 'invoicing' ),
310
                'defaults'  => array(
311
                    'value'        => '',
312
                    'input_label'  => __( 'Coupon Code', 'invoicing' ),
313
                    'button_label' => __( 'Apply Coupon', 'invoicing' ),
314
                    'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
315
                )
316
            ),*/
317
318
            array( 
319
                'type' => 'items',
320
                'name' => __( 'Items', 'invoicing' ),
321
                'defaults'  => array(
322
                    'value'        => '',
323
                    'items_type'   => 'total',
324
                    'description'  => '',
325
                    'premade'      => true,
326
                )
327
            ),
328
329
            array( 
330
                'type'       => 'pay_button',
331
                'name'       => __( 'Payment Button', 'invoicing' ),
332
                'defaults'   => array(
333
                    'value'        => '',
334
                    'class'        => 'btn-primary',
335
                    'label'        => __( 'Pay Now »', 'invoicing' ),
336
                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
337
                    'premade'      => true,
338
                )
339
            )
340
        );
341
342
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
343
        return $this->elements;
344
    }
345
346
    /**
347
     * Returns the restrict markup.
348
     */
349
    public function get_restrict_markup( $field, $field_type ) {
350
        $restrict = "$field.type=='$field_type'";
351
        return "v-if=\"$restrict\"";
352
    }
353
354
    /**
355
     * Renders the title element template.
356
     */
357
    public function render_heading_template( $field ) {
358
        $restrict = $this->get_restrict_markup( $field, 'heading' );
359
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
360
    }
361
362
    /**
363
     * Renders the title element on the frontend.
364
     */
365
    public function frontend_render_heading_template( $field ) {
366
        $tag = $field['level'];
367
        echo "<$tag>{$field['text']}</$tag>";
368
    }
369
370
    /**
371
     * Renders the edit title element template.
372
     */
373
    public function edit_heading_template( $field ) {
374
        $restrict = $this->get_restrict_markup( $field, 'heading' );
375
        $label    = __( 'Heading', 'invoicing' );
376
        $label2   = __( 'Select Heading Level', 'invoicing' );
377
        $id       = $field . '.id + "_edit"';
378
        $id2      = $field . '.id + "_edit2"';
379
380
        echo "
381
            <div $restrict>
382
                <div class='form-group'>
383
                    <label :for='$id'>$label</label>
384
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
385
                </div>
386
387
                <div class='form-group'>
388
                    <label :for='$id2'>$label2</label>
389
390
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
391
                        <option value='h1'>H1</option>
392
                        <option value='h2'>H2</option>
393
                        <option value='h3'>H3</option>
394
                        <option value='h4'>H4</option>
395
                        <option value='h5'>H5</option>
396
                        <option value='h6'>H6</option>
397
                        <option value='h7'>H7</option>
398
                    </select>
399
                </div>
400
            </div>
401
        ";
402
403
    }
404
405
    /**
406
     * Renders a paragraph element template.
407
     */
408
    public function render_paragraph_template( $field ) {
409
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
410
        $label    = "$field.text";
411
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
412
    }
413
414
    /**
415
     * Renders the paragraph element on the frontend.
416
     */
417
    public function frontend_render_paragraph_template( $field ) {
418
        echo "<p>{$field['text']}</p>";
419
    }
420
421
    /**
422
     * Renders the edit paragraph element template.
423
     */
424
    public function edit_paragraph_template( $field ) {
425
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
426
        $label    = __( 'Enter your text', 'invoicing' );
427
        $id       = $field . '.id + "_edit"';
428
        echo "
429
            <div $restrict>
430
                <div class='form-group'>
431
                    <label :for='$id'>$label</label>
432
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
433
                </div>
434
            </div>
435
        ";
436
437
    }
438
439
    /**
440
     * Renders the text element template.
441
     */
442
    public function render_text_template( $field ) {
443
        $restrict = $this->get_restrict_markup( $field, 'text' );
444
        $label    = "$field.label";
445
        echo "
446
            <div $restrict class='wpinv-payment-form-field-preview'>
447
                <div class='wpinv-payment-form-field-preview-overlay'></div>
448
                <label :for='$field.id'>{{" . $label . "}}</label>
449
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
450
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
451
            </div>    
452
        ";
453
    }
454
455
    /**
456
     * Renders the text element on the frontend.
457
     */
458
    public function frontend_render_text_template( $field ) {
459
        
460
        echo "<div class='form-group'>";
461
462
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

462
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
463
            array(
464
                'name'       => esc_attr( $field['id'] ),
465
                'id'         => esc_attr( $field['id'] ),
466
                'placeholder'=> esc_attr( $field['placeholder'] ),
467
                'required'   => (bool) $field['required'],
468
                'label'      => wp_kses_post( $field['label'] ),
469
                'no_wrap'    => true,
470
            )
471
        );
472
473
        if ( ! empty( $field['description'] ) ) {
474
            $description = wp_kses_post( $field['description'] );
475
            echo "<small class='form-text text-muted'>$description</small>";
476
        }
477
478
        echo '</div>';
479
480
    }
481
482
    /**
483
     * Renders the edit text element template.
484
     */
485
    public function edit_text_template( $field ) {
486
        $restrict = $this->get_restrict_markup( $field, 'text' );
487
        $label    = __( 'Field Label', 'invoicing' );
488
        $id       = $field . '.id + "_edit"';
489
        $label2   = __( 'Placeholder text', 'invoicing' );
490
        $id2      = $field . '.id + "_edit2"';
491
        $label3   = __( 'Help text', 'invoicing' );
492
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
493
        $id3      = $field . '.id + "_edit3"';
494
        $label5   = __( 'Is this field required?', 'invoicing' );
495
        $id4      = $field . '.id + "_edit4"';
496
        echo "
497
            <div $restrict>
498
                <div class='form-group'>
499
                    <label :for='$id'>$label</label>
500
                    <input :id='$id' v-model='$field.label' class='form-control' />
501
                </div>
502
                <div class='form-group'>
503
                    <label :for='$id2'>$label2</label>
504
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
505
                </div>
506
                <div class='form-group'>
507
                    <label :for='$id3'>$label3</label>
508
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
509
                </div>
510
                <div class='form-group form-check'>
511
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
512
                    <label class='form-check-label' :for='$id4'>$label5</label>
513
                </div>
514
            </div>
515
        ";
516
517
    }
518
519
    /**
520
     * Renders the textarea element template.
521
     */
522
    public function render_textarea_template( $field ) {
523
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
524
        $label    = "$field.label";
525
        echo "
526
            <div $restrict class='wpinv-payment-form-field-preview'>
527
                <div class='wpinv-payment-form-field-preview-overlay'></div>
528
                <label :for='$field.id'>{{" . $label . "}}</label>
529
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
530
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
531
            </div>    
532
        ";
533
    }
534
535
    /**
536
     * Renders the textarea element on the frontend.
537
     */
538
    public function frontend_render_textarea_template( $field ) {
539
        
540
        echo "<div class='form-group'>";
541
542
        echo aui()->textarea(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

542
        echo /** @scrutinizer ignore-call */ aui()->textarea(
Loading history...
543
            array(
544
                'name'       => esc_attr( $field['id'] ),
545
                'id'         => esc_attr( $field['id'] ),
546
                'placeholder'=> esc_attr( $field['placeholder'] ),
547
                'required'   => (bool) $field['required'],
548
                'label'      => wp_kses_post( $field['label'] ),
549
                'no_wrap'    => true,
550
                'rows'       => 3,
551
            )
552
        );
553
554
        if ( ! empty( $field['description'] ) ) {
555
            $description = wp_kses_post( $field['description'] );
556
            echo "<small class='form-text text-muted'>$description</small>";
557
        }
558
559
        echo '</div>';
560
561
    }
562
563
    /**
564
     * Renders the edit textarea element template.
565
     */
566
    public function edit_textarea_template( $field ) {
567
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
568
        $label    = __( 'Field Label', 'invoicing' );
569
        $id       = $field . '.id + "_edit"';
570
        $label2   = __( 'Placeholder text', 'invoicing' );
571
        $id2      = $field . '.id + "_edit2"';
572
        $label3   = __( 'Help text', 'invoicing' );
573
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
574
        $id3      = $field . '.id + "_edit3"';
575
        $label5   = __( 'Is this field required?', 'invoicing' );
576
        $id4      = $field . '.id + "_edit4"';
577
        echo "
578
            <div $restrict>
579
                <div class='form-group'>
580
                    <label :for='$id'>$label</label>
581
                    <input :id='$id' v-model='$field.label' class='form-control' />
582
                </div>
583
                <div class='form-group'>
584
                    <label :for='$id2'>$label2</label>
585
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
586
                </div>
587
                <div class='form-group'>
588
                    <label :for='$id3'>$label3</label>
589
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
590
                </div>
591
                <div class='form-group form-check'>
592
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
593
                    <label class='form-check-label' :for='$id4'>$label5</label>
594
                </div>
595
            </div>
596
        ";
597
598
    }
599
600
    /**
601
     * Renders the select element template.
602
     */
603
    public function render_select_template( $field ) {
604
        $restrict    = $this->get_restrict_markup( $field, 'select' );
605
        $label       = "$field.label";
606
        $placeholder = "$field.placeholder";
607
        $id          = $field . '.id';
608
        echo "
609
            <div $restrict class='wpinv-payment-form-field-preview'>
610
                <div class='wpinv-payment-form-field-preview-overlay'></div>
611
                <label :for='$id'>{{" . $label . "}}</label>
612
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
613
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
614
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
615
                </select>
616
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
617
            </div>
618
        ";
619
    }
620
621
    /**
622
     * Renders the select element on the frontend.
623
     */
624
    public function frontend_render_select_template( $field ) {
625
        
626
        echo "<div class='form-group'>";
627
628
        echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

628
        echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
629
            array(
630
                'name'       => esc_attr( $field['id'] ),
631
                'id'         => esc_attr( $field['id'] ),
632
                'placeholder'=> esc_attr( $field['placeholder'] ),
633
                'required'   => (bool) $field['required'],
634
                'label'      => wp_kses_post( $field['label'] ),
635
                'no_wrap'    => true,
636
                'options'    => array_combine( $field['options'], $field['options'] ),
637
            )
638
        );
639
640
        if ( ! empty( $field['description'] ) ) {
641
            $description = wp_kses_post( $field['description'] );
642
            echo "<small class='form-text text-muted'>$description</small>";
643
        }
644
645
        echo '</div>';
646
647
    }
648
649
    /**
650
     * Renders the edit select element template.
651
     */
652
    public function edit_select_template( $field ) {
653
        $restrict = $this->get_restrict_markup( $field, 'select' );
654
        $label    = __( 'Field Label', 'invoicing' );
655
        $id       = $field . '.id + "_edit"';
656
        $label2   = __( 'Placeholder text', 'invoicing' );
657
        $id2      = $field . '.id + "_edit2"';
658
        $label3   = __( 'Help text', 'invoicing' );
659
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
660
        $id3      = $field . '.id + "_edit3"';
661
        $label5   = __( 'Is this field required?', 'invoicing' );
662
        $id4      = $field . '.id + "_edit4"';
663
        $label6   = __( 'Available Options', 'invoicing' );
664
        echo "
665
            <div $restrict>
666
                <div class='form-group'>
667
                    <label :for='$id'>$label</label>
668
                    <input :id='$id' v-model='$field.label' class='form-control' />
669
                </div>
670
                <div class='form-group'>
671
                    <label :for='$id2'>$label2</label>
672
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
673
                </div>
674
                <div class='form-group'>
675
                    <label :for='$id3'>$label3</label>
676
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
677
                </div>
678
                <div class='form-group form-check'>
679
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
680
                    <label class='form-check-label' :for='$id4'>$label5</label>
681
                </div>
682
                <hr class='featurette-divider mt-4'>
683
                <h5>$label6</h5>
684
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
685
                    <input type='text' class='form-control' v-model='$field.options[index]'>
686
                    <div class='input-group-append'>
687
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
688
                    </div>
689
                </div>
690
                <div class='form-group'>
691
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
692
                </div>
693
            </div>
694
        ";
695
696
    }
697
698
    /**
699
     * Renders the checkbox element template.
700
     */
701
    public function render_checkbox_template( $field ) {
702
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
703
        $label    = "$field.label";
704
        echo "
705
            <div class='form-check' $restrict>
706
                <div class='wpinv-payment-form-field-preview-overlay'></div>
707
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
708
                <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label>
709
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
710
            </div>    
711
        ";
712
    }
713
714
    /**
715
     * Renders the checkbox element on the frontend.
716
     */
717
    public function frontend_render_checkbox_template( $field ) {
718
        
719
        echo "<div class='form-group'>";
720
721
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

721
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
722
            array(
723
                'name'       => esc_attr( $field['id'] ),
724
                'id'         => esc_attr( $field['id'] ),
725
                'required'   => (bool) $field['required'],
726
                'label'      => wp_kses_post( $field['label'] ),
727
                'no_wrap'    => true,
728
                'value'      => esc_attr__( 'Yes', 'invoicing' ),
729
                'type'       => 'checkbox',
730
            )
731
        );
732
733
        if ( ! empty( $field['description'] ) ) {
734
            $description = wp_kses_post( $field['description'] );
735
            echo "<small class='form-text text-muted'>$description</small>";
736
        }
737
738
        echo '</div>';
739
740
    }
741
742
    /**
743
     * Renders the edit checkbox element template.
744
     */
745
    public function edit_checkbox_template( $field ) {
746
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
747
        $label    = __( 'Field Label', 'invoicing' );
748
        $id       = $field . '.id + "_edit"';
749
        $label2   = __( 'Help text', 'invoicing' );
750
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
751
        $id2      = $field . '.id + "_edit2"';
752
        $label4   = __( 'Is this field required?', 'invoicing' );
753
        $id3      = $field . '.id + "_edit3"';
754
        echo "
755
            <div $restrict>
756
                <div class='form-group'>
757
                    <label :for='$id'>$label</label>
758
                    <input :id='$id' v-model='$field.label' class='form-control' />
759
                </div>
760
                <div class='form-group'>
761
                    <label :for='$id2'>$label2</label>
762
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
763
                </div>
764
                <div class='form-group form-check'>
765
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
766
                    <label class='form-check-label' :for='$id3'>$label4</label>
767
                </div>
768
            </div>
769
        ";
770
771
    }
772
773
    /**
774
     * Renders the radio element template.
775
     */
776
    public function render_radio_template( $field ) {
777
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
778
        $label       = "$field.label";
779
        $id          = $field . '.id';
780
        echo "
781
            <div $restrict class='wpinv-payment-form-field-preview'>
782
                <div class='wpinv-payment-form-field-preview-overlay'></div>
783
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
784
                <div class='form-check' v-for='(option, index) in $field.options'>
785
                    <input class='form-check-input' type='radio' :id='$id + index'>
786
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
787
                </div>
788
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
789
            </div>
790
        ";
791
    }
792
793
    /**
794
     * Renders the radio element on the frontend.
795
     */
796
    public function frontend_render_radio_template( $field ) {
797
        
798
        echo "<div class='form-group'>";
799
800
        if ( ! empty( $field['label'] ) ) {
801
            $label = wp_kses_post( $field['label'] );
802
            echo "<legend class='col-form-label'>$label</legend>";
803
        }
804
805
        foreach( $field['options'] as $index => $option ) {
806
            $id    = $field['id'] . $index;
807
            $name  = $field['id'];
808
            $value = esc_attr( $option );
809
            $label = wp_kses_post( $option );
810
811
            echo "
812
                <div class='form-check'>
813
                    <input class='form-check-input' type='radio' name='$name' id='$id' value='$value'>
814
                    <label class='form-check-label' for='$id'>$label</label>
815
                </div>
816
            ";
817
        }
818
819
        if ( ! empty( $field['description'] ) ) {
820
            $description = wp_kses_post( $field['description'] );
821
            echo "<small class='form-text text-muted'>$description</small>";
822
        }
823
824
        echo '</div>';
825
826
    }
827
828
    /**
829
     * Renders the edit radio element template.
830
     */
831
    public function edit_radio_template( $field ) {
832
        $restrict = $this->get_restrict_markup( $field, 'radio' );
833
        $label    = __( 'Field Label', 'invoicing' );
834
        $id       = $field . '.id + "_edit"';
835
        $label2   = __( 'Help text', 'invoicing' );
836
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
837
        $id2      = $field . '.id + "_edit3"';
838
        $label4   = __( 'Is this field required?', 'invoicing' );
839
        $id3      = $field . '.id + "_edit4"';
840
        $label5   = __( 'Available Options', 'invoicing' );
841
        echo "
842
            <div $restrict>
843
                <div class='form-group'>
844
                    <label :for='$id'>$label</label>
845
                    <input :id='$id' v-model='$field.label' class='form-control' />
846
                </div>
847
                <div class='form-group'>
848
                    <label :for='$id2'>$label2</label>
849
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
850
                </div>
851
                <div class='form-group form-check'>
852
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
853
                    <label class='form-check-label' :for='$id3'>$label4</label>
854
                </div>
855
                <hr class='featurette-divider mt-4'>
856
                <h5>$label5</h5>
857
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
858
                    <input type='text' class='form-control' v-model='$field.options[index]'>
859
                    <div class='input-group-append'>
860
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
861
                    </div>
862
                </div>
863
                <div class='form-group'>
864
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
865
                </div>
866
            </div>
867
        ";
868
869
    }
870
871
    /**
872
     * Renders the address element template.
873
     */
874
    public function render_address_template( $field ) {
875
        $restrict    = $this->get_restrict_markup( $field, 'address' );
876
877
        echo "
878
            <div class='wpinv-address-wrapper' $restrict>
879
                <draggable v-model='$field.fields' group='address_fields_preview'>
880
                    <div class='form-group address-field-preview wpinv-payment-form-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'>
881
                        <div class='wpinv-payment-form-field-preview-overlay'></div>
882
                        <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label>
883
                        <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'>
884
                        <select v-else class='form-control' :id='field.name'>
885
                            <option v-if='field.placeholder'>{{field.placeholder}}</option>
886
                        </select>
887
                        <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small>
888
                    </div>
889
                </draggable>
890
            </div>
891
        ";
892
    }
893
894
    /**
895
     * Renders the address element on the frontend.
896
     */
897
    public function frontend_render_address_template( $field ) {
898
        
899
        echo "<div class='wpinv-address-fields'>";
900
901
        foreach( $field['fields'] as $address_field ) {
902
903
            if ( empty( $address_field['visible'] ) ) {
904
                continue;
905
            }
906
907
            $class = esc_attr( $address_field['name'] );
908
            echo "<div class='form-group $class'>";
909
910
            $label = $address_field['label'];
911
912
            if ( ! empty( $address_field['required'] ) ) {
913
                $label .= "<span class='text-danger'> *</span>";
914
            }
915
916
            if ( 'wpinv_country' == $address_field['name'] ) {
917
918
                echo aui()->select( array(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

918
                echo /** @scrutinizer ignore-call */ aui()->select( array(
Loading history...
919
                    'options'          => wpinv_get_country_list(),
920
                    'name'             => esc_attr( $address_field['name'] ),
921
                    'id'               => esc_attr( $address_field['name'] ),
922
                    'value'            => wpinv_get_default_country(),
923
                    'placeholder'      => esc_attr( $address_field['placeholder'] ),
924
                    'required'         => (bool) $address_field['required'],
925
                    'no_wrap'          => true,
926
                    'label'            => wp_kses_post( $label ),
927
                    'select2'          => false,
928
                ));
929
    
930
            } else if ( 'wpinv_state' == $address_field['name'] ) {
931
932
                $states = wpinv_get_country_states( wpinv_get_default_country() );
933
                $state  = wpinv_get_default_state();
934
935
                if ( ! empty( $states ) ) {
936
937
                    echo aui()->select( array(
938
                        'options'          => $states,
939
                        'name'             => esc_attr( $address_field['name'] ),
940
                        'id'               => esc_attr( $address_field['name'] ),
941
                        'value'            => $state,
942
                        'placeholder'      => esc_attr( $address_field['placeholder'] ),
943
                        'required'         => (bool) $address_field['required'],
944
                        'no_wrap'          => true,
945
                        'label'            => wp_kses_post( $label ),
946
                        'select2'          => false,
947
                    ));
948
949
                } else {
950
951
                    echo aui()->input(
952
                        array(
953
                            'name'       => esc_attr( $address_field['name'] ),
954
                            'id'         => esc_attr( $address_field['name'] ),
955
                            'required'   => (bool) $address_field['required'],
956
                            'label'      => wp_kses_post( $label ),
957
                            'no_wrap'    => true,
958
                            'type'       => 'text',
959
                        )
960
                    );
961
962
                }
963
964
            } else {
965
966
                echo aui()->input(
967
                    array(
968
                        'name'       => esc_attr( $address_field['name'] ),
969
                        'id'         => esc_attr( $address_field['name'] ),
970
                        'required'   => (bool) $address_field['required'],
971
                        'label'      => wp_kses_post( $label ),
972
                        'no_wrap'    => true,
973
                        'placeholder' => esc_attr( $address_field['placeholder'] ),
974
                        'type'       => 'text',
975
                    )
976
                );
977
978
            }
979
            
980
981
            if ( ! empty( $address_field['description'] ) ) {
982
                $description = wp_kses_post( $address_field['description'] );
983
                echo "<small class='form-text text-muted'>$description</small>";
984
            }
985
    
986
            echo '</div>';
987
988
        }
989
990
        echo '</div>';
991
992
    }
993
994
    /**
995
     * Renders the edit address element template.
996
     */
997
    public function edit_address_template( $field ) {
998
        $restrict  = $this->get_restrict_markup( $field, 'address' );
999
        $label     = __( 'Field Label', 'invoicing' );
1000
        $label2    = __( 'Placeholder', 'invoicing' );
1001
        $label3    = __( 'Description', 'invoicing' );
1002
        $label4    = __( 'Is required', 'invoicing' );
1003
        $label5    = __( 'Is visible', 'invoicing' );
1004
        $id        = $field . '.id + "_edit_label"';
1005
        $id2       = $field . '.id + "_edit_placeholder"';
1006
        $id3       = $field . '.id + "_edit_description"';
1007
        $id4       = $field . '.id + "_edit_required"';
1008
        $id5       = $field . '.id + "_edit_visible"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id5 is dead and can be removed.
Loading history...
1009
        $id5       = $field . '.id + "_edit_visible"';
1010
        $id_main   = $field . '.id';
1011
1012
        echo "
1013
            <div $restrict :id='$id_main'>
1014
                <draggable v-model='$field.fields' group='address_fields'>
1015
                    <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'>
1016
1017
                        <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'>
1018
                            <span class='label'>{{field.label}}</span>
1019
                            <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'>
1020
                                <span class='dashicons dashicons-hidden'></span>
1021
                                <span class='dashicons dashicons-visibility'></span>
1022
                            </span>
1023
                            <span class='toggle-icon'>
1024
                                <span class='dashicons dashicons-arrow-down'></span>
1025
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
1026
                            </span>
1027
                        </div>
1028
1029
                        <div class='wpinv-form-address-field-editor-editor-body'>
1030
                            <div class='p-2'>
1031
1032
                                <div class='form-group'>
1033
                                    <label :for='$id + index'>$label</label>
1034
                                    <input :id='$id + index' v-model='field.label' class='form-control' />
1035
                                </div>
1036
1037
                                <div class='form-group'>
1038
                                    <label :for='$id2 + index'>$label2</label>
1039
                                    <input :id='$id2 + index' v-model='field.placeholder' class='form-control' />
1040
                                </div>
1041
1042
                                <div class='form-group'>
1043
                                    <label :for='$id3 + index'>$label3</label>
1044
                                    <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea>
1045
                                </div>
1046
1047
                                <div class='form-group form-check'>
1048
                                    <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' />
1049
                                    <label class='form-check-label' :for='$id4 + index'>$label4</label>
1050
                                </div>
1051
1052
                                <div class='form-group form-check'>
1053
                                    <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' />
1054
                                    <label class='form-check-label' :for='$id5 + index'>$label5</label>
1055
                                </div>
1056
1057
                            </div>
1058
                        </div>
1059
1060
                    </div>
1061
                </draggable>
1062
1063
            </div>
1064
        ";
1065
1066
    }
1067
1068
    /**
1069
     * Renders the email element template.
1070
     */
1071
    public function render_email_template( $field ) {
1072
        $restrict = $this->get_restrict_markup( $field, 'email' );
1073
        $label    = "$field.label";
1074
        echo "
1075
            <div $restrict class='wpinv-payment-form-field-preview'>
1076
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1077
                <label :for='$field.id'>{{" . $label . "}}</label>
1078
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1079
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1080
            </div>    
1081
        ";
1082
    }
1083
1084
    /**
1085
     * Renders the billing_email element template.
1086
     */
1087
    public function render_billing_email_template( $field ) {
1088
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1089
        $label    = "$field.label";
1090
        echo "
1091
            <div $restrict>
1092
                <label :for='$field.id'>{{" . $label . "}}</label>
1093
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1094
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1095
            </div>    
1096
        ";
1097
    }
1098
1099
    /**
1100
     * Renders the email element on the frontend.
1101
     */
1102
    public function frontend_render_email_template( $field ) {
1103
        
1104
        echo "<div class='form-group'>";
1105
1106
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1106
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1107
            array(
1108
                'name'       => esc_attr( $field['id'] ),
1109
                'id'         => esc_attr( $field['id'] ),
1110
                'required'   => (bool) $field['required'],
1111
                'label'      => wp_kses_post( $field['label'] ),
1112
                'no_wrap'    => true,
1113
                'placeholder' => esc_attr( $field['placeholder'] ),
1114
                'type'       => 'email',
1115
            )
1116
        );
1117
1118
        if ( ! empty( $field['description'] ) ) {
1119
            $description = wp_kses_post( $field['description'] );
1120
            echo "<small class='form-text text-muted'>$description</small>";
1121
        }
1122
1123
        echo '</div>';
1124
1125
    }
1126
1127
    /**
1128
     * Renders the billing email element on the frontend.
1129
     */
1130
    public function frontend_render_billing_email_template( $field ) {
1131
        
1132
        echo "<div class='form-group'>";
1133
        $value = '';
1134
1135
        if ( is_user_logged_in() ) {
1136
            $user  = wp_get_current_user();
1137
            $value = sanitize_email( $user->user_email );
1138
        }
1139
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1139
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1140
            array(
1141
                'name'       => 'billing_email',
1142
                'value'      => $value,
1143
                'id'         => esc_attr( $field['id'] ),
1144
                'required'   => true,
1145
                'label'      => wp_kses_post( $field['label'] ),
1146
                'no_wrap'    => true,
1147
                'placeholder' => esc_attr( $field['placeholder'] ),
1148
                'type'       => 'email',
1149
            )
1150
        );
1151
1152
        if ( ! empty( $field['description'] ) ) {
1153
            $description = wp_kses_post( $field['description'] );
1154
            echo "<small class='form-text text-muted'>$description</small>";
1155
        }
1156
1157
        echo '</div>';
1158
1159
    }
1160
1161
    /**
1162
     * Renders the edit email element template.
1163
     */
1164
    public function edit_email_template( $field ) {
1165
        $restrict = $this->get_restrict_markup( $field, 'email' );
1166
        $label    = __( 'Field Label', 'invoicing' );
1167
        $id       = $field . '.id + "_edit"';
1168
        $label2   = __( 'Placeholder text', 'invoicing' );
1169
        $id2      = $field . '.id + "_edit2"';
1170
        $label3   = __( 'Help text', 'invoicing' );
1171
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1172
        $id3      = $field . '.id + "_edit3"';
1173
        $label5   = __( 'Is this field required?', 'invoicing' );
1174
        $id4      = $field . '.id + "_edit4"';
1175
        echo "
1176
            <div $restrict>
1177
                <div class='form-group'>
1178
                    <label :for='$id'>$label</label>
1179
                    <input :id='$id' v-model='$field.label' class='form-control' />
1180
                </div>
1181
                <div class='form-group'>
1182
                    <label :for='$id2'>$label2</label>
1183
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1184
                </div>
1185
                <div class='form-group'>
1186
                    <label :for='$id3'>$label3</label>
1187
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1188
                </div>
1189
                <div class='form-group form-check'>
1190
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1191
                    <label class='form-check-label' :for='$id4'>$label5</label>
1192
                </div>
1193
            </div>
1194
        ";
1195
1196
    }
1197
1198
    /**
1199
     * Renders the edit billing_email element template.
1200
     */
1201
    public function edit_billing_email_template( $field ) {
1202
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1203
        $label    = __( 'Field Label', 'invoicing' );
1204
        $id       = $field . '.id + "_edit"';
1205
        $label2   = __( 'Placeholder text', 'invoicing' );
1206
        $id2      = $field . '.id + "_edit2"';
1207
        $label3   = __( 'Help text', 'invoicing' );
1208
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1209
        $id3      = $field . '.id + "_edit3"';
1210
        $label5   = __( 'Is this field required?', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label5 is dead and can be removed.
Loading history...
1211
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
1212
        echo "
1213
            <div $restrict>
1214
                <div class='form-group'>
1215
                    <label :for='$id'>$label</label>
1216
                    <input :id='$id' v-model='$field.label' class='form-control' />
1217
                </div>
1218
                <div class='form-group'>
1219
                    <label :for='$id2'>$label2</label>
1220
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1221
                </div>
1222
                <div class='form-group'>
1223
                    <label :for='$id3'>$label3</label>
1224
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1225
                </div>
1226
            </div>
1227
        ";
1228
1229
    }
1230
1231
    /**
1232
     * Renders the website element template.
1233
     */
1234
    public function render_website_template( $field ) {
1235
        $restrict = $this->get_restrict_markup( $field, 'website' );
1236
        $label    = "$field.label";
1237
        echo "
1238
            <div $restrict class='wpinv-payment-form-field-preview'>
1239
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1240
                <label :for='$field.id'>{{" . $label . "}}</label>
1241
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
1242
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1243
            </div>    
1244
        ";
1245
    }
1246
1247
    /**
1248
     * Renders the website element on the frontend.
1249
     */
1250
    public function frontend_render_website_template( $field ) {
1251
        
1252
        echo "<div class='form-group'>";
1253
1254
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1254
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1255
            array(
1256
                'name'       => esc_attr( $field['id'] ),
1257
                'id'         => esc_attr( $field['id'] ),
1258
                'required'   => (bool) $field['required'],
1259
                'label'      => wp_kses_post( $field['label'] ),
1260
                'no_wrap'    => true,
1261
                'placeholder' => esc_attr( $field['placeholder'] ),
1262
                'type'       => 'url',
1263
            )
1264
        );
1265
1266
        if ( ! empty( $field['description'] ) ) {
1267
            $description = wp_kses_post( $field['description'] );
1268
            echo "<small class='form-text text-muted'>$description</small>";
1269
        }
1270
1271
        echo '</div>';
1272
1273
    }
1274
1275
    /**
1276
     * Renders the edit website element template.
1277
     */
1278
    public function edit_website_template( $field ) {
1279
        $restrict = $this->get_restrict_markup( $field, 'website' );
1280
        $label    = __( 'Field Label', 'invoicing' );
1281
        $id       = $field . '.id + "_edit"';
1282
        $label2   = __( 'Placeholder text', 'invoicing' );
1283
        $id2      = $field . '.id + "_edit2"';
1284
        $label3   = __( 'Help text', 'invoicing' );
1285
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1286
        $id3      = $field . '.id + "_edit3"';
1287
        $label5   = __( 'Is this field required?', 'invoicing' );
1288
        $id4      = $field . '.id + "_edit4"';
1289
        echo "
1290
            <div $restrict>
1291
                <div class='form-group'>
1292
                    <label :for='$id'>$label</label>
1293
                    <input :id='$id' v-model='$field.label' class='form-control' />
1294
                </div>
1295
                <div class='form-group'>
1296
                    <label :for='$id2'>$label2</label>
1297
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1298
                </div>
1299
                <div class='form-group'>
1300
                    <label :for='$id3'>$label3</label>
1301
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1302
                </div>
1303
                <div class='form-group form-check'>
1304
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1305
                    <label class='form-check-label' :for='$id4'>$label5</label>
1306
                </div>
1307
            </div>
1308
        ";
1309
1310
    }
1311
1312
    /**
1313
     * Renders the date element template.
1314
     */
1315
    public function render_date_template( $field ) {
1316
        $restrict = $this->get_restrict_markup( $field, 'date' );
1317
        $label    = "$field.label";
1318
        echo "
1319
            <div $restrict class='wpinv-payment-form-field-preview'>
1320
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1321
                <label :for='$field.id'>{{" . $label . "}}</label>
1322
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
1323
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1324
            </div>    
1325
        ";
1326
    }
1327
1328
    /**
1329
     * Renders the date element on the frontend.
1330
     */
1331
    public function frontend_render_date_template( $field ) {
1332
        
1333
        echo "<div class='form-group'>";
1334
1335
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1335
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1336
            array(
1337
                'name'       => esc_attr( $field['id'] ),
1338
                'id'         => esc_attr( $field['id'] ),
1339
                'required'   => (bool) $field['required'],
1340
                'label'      => wp_kses_post( $field['label'] ),
1341
                'no_wrap'    => true,
1342
                'type'       => 'date',
1343
            )
1344
        );
1345
1346
        if ( ! empty( $field['description'] ) ) {
1347
            $description = wp_kses_post( $field['description'] );
1348
            echo "<small class='form-text text-muted'>$description</small>";
1349
        }
1350
1351
        echo '</div>';
1352
1353
    }
1354
1355
    /**
1356
     * Renders the edit date element template.
1357
     */
1358
    public function edit_date_template( $field ) {
1359
        $restrict = $this->get_restrict_markup( $field, 'date' );
1360
        $label    = __( 'Field Label', 'invoicing' );
1361
        $id       = $field . '.id + "_edit"';
1362
        $label3   = __( 'Help text', 'invoicing' );
1363
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1364
        $id3      = $field . '.id + "_edit3"';
1365
        $label5   = __( 'Is this field required?', 'invoicing' );
1366
        $id4      = $field . '.id + "_edit4"';
1367
        echo "
1368
            <div $restrict>
1369
                <div class='form-group'>
1370
                    <label :for='$id'>$label</label>
1371
                    <input :id='$id' v-model='$field.label' class='form-control' />
1372
                </div>
1373
                <div class='form-group'>
1374
                    <label :for='$id3'>$label3</label>
1375
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1376
                </div>
1377
                <div class='form-group form-check'>
1378
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1379
                    <label class='form-check-label' :for='$id4'>$label5</label>
1380
                </div>
1381
            </div>
1382
        ";
1383
1384
    }
1385
1386
    /**
1387
     * Renders the time element template.
1388
     */
1389
    public function render_time_template( $field ) {
1390
        $restrict = $this->get_restrict_markup( $field, 'time' );
1391
        $label    = "$field.label";
1392
        echo "
1393
            <div $restrict class='wpinv-payment-form-field-preview'>
1394
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1395
                <label :for='$field.id'>{{" . $label . "}}</label>
1396
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
1397
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1398
            </div>    
1399
        ";
1400
    }
1401
1402
    /**
1403
     * Renders the time element on the frontend.
1404
     */
1405
    public function frontend_render_time_template( $field ) {
1406
        
1407
        echo "<div class='form-group'>";
1408
1409
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1409
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1410
            array(
1411
                'name'       => esc_attr( $field['id'] ),
1412
                'id'         => esc_attr( $field['id'] ),
1413
                'required'   => (bool) $field['required'],
1414
                'label'      => wp_kses_post( $field['label'] ),
1415
                'no_wrap'    => true,
1416
                'type'       => 'time',
1417
            )
1418
        );
1419
1420
        if ( ! empty( $field['description'] ) ) {
1421
            $description = wp_kses_post( $field['description'] );
1422
            echo "<small class='form-text text-muted'>$description</small>";
1423
        }
1424
1425
        echo '</div>';
1426
1427
    }
1428
1429
    /**
1430
     * Renders the edit time element template.
1431
     */
1432
    public function edit_time_template( $field ) {
1433
        $restrict = $this->get_restrict_markup( $field, 'time' );
1434
        $label    = __( 'Field Label', 'invoicing' );
1435
        $id       = $field . '.id + "_edit"';
1436
        $label3   = __( 'Help text', 'invoicing' );
1437
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1438
        $id3      = $field . '.id + "_edit3"';
1439
        $label5   = __( 'Is this field required?', 'invoicing' );
1440
        $id4      = $field . '.id + "_edit4"';
1441
        echo "
1442
            <div $restrict>
1443
                <div class='form-group'>
1444
                    <label :for='$id'>$label</label>
1445
                    <input :id='$id' v-model='$field.label' class='form-control' />
1446
                </div>
1447
                <div class='form-group'>
1448
                    <label :for='$id3'>$label3</label>
1449
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1450
                </div>
1451
                <div class='form-group form-check'>
1452
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1453
                    <label class='form-check-label' :for='$id4'>$label5</label>
1454
                </div>
1455
            </div>
1456
        ";
1457
1458
    }
1459
1460
    /**
1461
     * Renders the number element template.
1462
     */
1463
    public function render_number_template( $field ) {
1464
        $restrict = $this->get_restrict_markup( $field, 'number' );
1465
        $label    = "$field.label";
1466
        echo "
1467
            <div $restrict class='wpinv-payment-form-field-preview'>
1468
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1469
                <label :for='$field.id'>{{" . $label . "}}</label>
1470
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
1471
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1472
            </div>    
1473
        ";
1474
    }
1475
1476
    /**
1477
     * Renders the number element on the frontend.
1478
     */
1479
    public function frontend_render_number_template( $field ) {
1480
        
1481
        echo "<div class='form-group'>";
1482
1483
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1483
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1484
            array(
1485
                'name'       => esc_attr( $field['id'] ),
1486
                'id'         => esc_attr( $field['id'] ),
1487
                'required'   => (bool) $field['required'],
1488
                'label'      => wp_kses_post( $field['label'] ),
1489
                'placeholder' => esc_attr( $field['placeholder'] ),
1490
                'no_wrap'    => true,
1491
                'type'       => 'number',
1492
            )
1493
        );
1494
1495
        if ( ! empty( $field['description'] ) ) {
1496
            $description = wp_kses_post( $field['description'] );
1497
            echo "<small class='form-text text-muted'>$description</small>";
1498
        }
1499
1500
        echo '</div>';
1501
1502
    }
1503
1504
    /**
1505
     * Renders the edit number element template.
1506
     */
1507
    public function edit_number_template( $field ) {
1508
        $restrict = $this->get_restrict_markup( $field, 'number' );
1509
        $label    = __( 'Field Label', 'invoicing' );
1510
        $id       = $field . '.id + "_edit"';
1511
        $label2   = __( 'Placeholder text', 'invoicing' );
1512
        $id2      = $field . '.id + "_edit2"';
1513
        $label3   = __( 'Help text', 'invoicing' );
1514
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1515
        $id3      = $field . '.id + "_edit3"';
1516
        $label5   = __( 'Is this field required?', 'invoicing' );
1517
        $id4      = $field . '.id + "_edit4"';
1518
        echo "
1519
            <div $restrict>
1520
                <div class='form-group'>
1521
                    <label :for='$id'>$label</label>
1522
                    <input :id='$id' v-model='$field.label' class='form-control' />
1523
                </div>
1524
                <div class='form-group'>
1525
                    <label :for='$id2'>$label2</label>
1526
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1527
                </div>
1528
                <div class='form-group'>
1529
                    <label :for='$id3'>$label3</label>
1530
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1531
                </div>
1532
                <div class='form-group form-check'>
1533
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1534
                    <label class='form-check-label' :for='$id4'>$label5</label>
1535
                </div>
1536
            </div>
1537
        ";
1538
1539
    }
1540
1541
    /**
1542
     * Renders the separator element template.
1543
     */
1544
    public function render_separator_template( $field ) {
1545
        $restrict = $this->get_restrict_markup( $field, 'separator' );
1546
        echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1547
    }
1548
1549
    /**
1550
     * Renders the separator element on the frontend.
1551
     */
1552
    public function frontend_render_separator_template( $field ) {
1553
        echo '<hr class="featurette-divider mt-0 mb-2" />';
1554
    }
1555
1556
    /**
1557
     * Renders the pay button element template.
1558
     */
1559
    public function render_pay_button_template( $field ) {
1560
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1561
        $label    = "$field.label";
1562
        echo "
1563
            <div $restrict>
1564
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
1565
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1566
            </div>    
1567
        ";
1568
    }
1569
1570
    /**
1571
     * Renders the pay_button element on the frontend.
1572
     */
1573
    public function frontend_render_pay_button_template( $field ) {
1574
1575
        echo "<div class='mt-4 mb-4'>";
1576
            do_action( 'wpinv_payment_mode_select' );
1577
        echo "</div>";
1578
1579
        echo "<div class='form-group'>";
1580
1581
        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1582
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1582
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1583
            array(
1584
                'name'       => esc_attr( $field['id'] ),
1585
                'id'         => esc_attr( $field['id'] ),
1586
                'value'      => esc_attr( $field['label'] ),
1587
                'no_wrap'    => true,
1588
                'type'       => 'submit',
1589
                'class'      => $class,
1590
            )
1591
        );
1592
1593
        if ( ! empty( $field['description'] ) ) {
1594
            $description = wp_kses_post( $field['description'] );
1595
            echo "<small class='form-text text-muted'>$description</small>";
1596
        }
1597
1598
        echo '</div>';
1599
1600
    }
1601
1602
    /**
1603
     * Renders the pay button element template.
1604
     */
1605
    public function edit_pay_button_template( $field ) {
1606
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1607
        $label    = __( 'Button Text', 'invoicing' );
1608
        $id       = $field . '.id + "_edit"';
1609
        $label2   = __( 'Help text', 'invoicing' );
1610
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1611
        $id2      = $field . '.id + "_edit2"';
1612
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1613
        $id3      = $field . '.id + "_edit3"';
1614
        echo "
1615
            <div $restrict>
1616
                <div class='form-group'>
1617
                    <label :for='$id'>$label</label>
1618
                    <input :id='$id' v-model='$field.label' class='form-control' />
1619
                </div>
1620
                <div class='form-group'>
1621
                    <label :for='$id2'>$label2</label>
1622
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
1623
                </div>
1624
                <div class='form-group'>
1625
                    <label :for='$id3'>$label4</label>
1626
1627
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1628
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1629
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1630
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1631
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1632
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1633
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1634
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1635
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1636
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1637
                    </select>
1638
                </div>
1639
            </div>
1640
        ";
1641
1642
    }
1643
1644
    /**
1645
     * Renders the alert element template.
1646
     */
1647
    public function render_alert_template( $field ) {
1648
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1649
        $text     = "$field.text";
1650
        echo "
1651
            <div $restrict class='alert' :class='$field.class' role='alert'>
1652
                <span v-html='$text'></span>
1653
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
1654
                    <span aria-hidden='true'>&times;</span>
1655
                </button>
1656
            </div>    
1657
        ";
1658
    }
1659
1660
    /**
1661
     * Renders the alert element on the frontend.
1662
     */
1663
    public function frontend_render_alert_template( $field ) {
1664
        
1665
        echo "<div class='form-group'>";
1666
1667
        echo aui()->alert(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1667
        echo /** @scrutinizer ignore-call */ aui()->alert(
Loading history...
1668
            array(
1669
                'content'     => wp_kses_post( $field['text'] ),
1670
                'dismissible' => $field['dismissible'],
1671
                'type'        => str_replace( 'alert-', '', $field['class'] ),
1672
            )
1673
        );
1674
1675
        echo '</div>';
1676
1677
    }
1678
1679
    /**
1680
     * Renders the alert element template.
1681
     */
1682
    public function edit_alert_template( $field ) {
1683
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1684
        $label    = __( 'Alert Text', 'invoicing' );
1685
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1686
        $id       = $field . '.id + "_edit"';
1687
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1688
        $id2      = $field . '.id + "_edit2"';
1689
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1690
        $id3      = $field . '.id + "_edit3"';
1691
        echo "
1692
            <div $restrict>
1693
                <div class='form-group'>
1694
                    <label :for='$id'>$label</label>
1695
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1696
                </div>
1697
                <div class='form-group form-check'>
1698
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1699
                    <label class='form-check-label' :for='$id2'>$label3</label>
1700
                </div>
1701
                <div class='form-group'>
1702
                    <label :for='$id3'>$label4</label>
1703
1704
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1705
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1706
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1707
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1708
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1709
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1710
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1711
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1712
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1713
                    </select>
1714
                </div>
1715
            </div>
1716
        ";
1717
1718
    }
1719
1720
    /**
1721
     * Renders the discount element template.
1722
     */
1723
    public function render_discount_template( $field ) {
1724
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1725
        ?>
1726
1727
            <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
1728
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1729
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1730
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1731
                </div>
1732
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1733
            </div>
1734
1735
        <?php
1736
    }
1737
1738
    /**
1739
     * Renders the discount element on the frontend.
1740
     */
1741
    public function frontend_render_discount_template( $field ) {
1742
        
1743
        $placeholder = esc_attr( $field['input_label'] );
1744
        $label       = sanitize_text_field( $field['button_label'] );
1745
        $description = '';
1746
1747
        if ( ! empty( $field['description'] ) ) {
1748
            $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1749
        }
1750
?>
1751
1752
    <div class="form-group">
1753
        <div class="discount_field  border rounded p-3">
1754
            <div class="discount_field_inner d-flex flex-column flex-md-row">
1755
                <input  placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1756
                <a href="#" class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button"><?php echo $label; ?></a>
1757
            </div>
1758
            <?php echo $description ?>
1759
        </div>
1760
    </div>
1761
1762
<?php
1763
    }
1764
1765
    /**
1766
     * Renders the discount element template.
1767
     */
1768
    public function edit_discount_template( $field ) {
1769
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1770
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1771
        $label2   = __( 'Help Text', 'invoicing' );
1772
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1773
        $label4   = __( 'Button Text', 'invoicing' );
1774
        $id       = $field . '.id + "_edit"';
1775
        $id2      = $field . '.id + "_edit2"';
1776
        $id3      = $field . '.id + "_edit3"';
1777
        echo "
1778
            <div $restrict>
1779
                <div class='form-group'>
1780
                    <label :for='$id'>$label</label>
1781
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1782
                </div>
1783
1784
                <div class='form-group'>
1785
                    <label :for='$id2'>$label4</label>
1786
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1787
                </div>
1788
1789
                <div class='form-group'>
1790
                    <label :for='$id3'>$label2</label>
1791
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1792
                </div>
1793
1794
            </div>
1795
        ";
1796
1797
    }
1798
1799
    /**
1800
     * Renders the items element template.
1801
     */
1802
    public function render_items_template( $field ) {
1803
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1804
        $label     = __( 'Item totals will appear here. Click to set items.', 'invoicing' );
1805
        $label2    = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' );
1806
        $label2   .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' );
1807
        echo "
1808
            <div $restrict class='item_totals text-center'>
1809
                <div v-if='canCheckoutSeveralSubscriptions($field)' class='p-4 bg-danger text-light'>$label2</div>
1810
                <div v-if='! canCheckoutSeveralSubscriptions($field)' class='p-4 bg-warning'>$label</div>
1811
            </div>
1812
        ";
1813
    }
1814
1815
    /**
1816
     * Renders the items element on the frontend.
1817
     */
1818
    public function frontend_render_items_template( $field, $items ) {
1819
        
1820
        echo "<div class='form-group item_totals'>";
1821
        
1822
        $id = esc_attr( $field['id'] );
1823
        if ( 'total' == $field[ 'items_type' ] ) {
1824
            $total     = 0;
1825
            $tax       = 0;
1826
            $sub_total = 0;
1827
1828
            ?>
1829
            <div class="border item_totals_type_total">
1830
1831
                <?php
1832
                    foreach( $items as $item ) {
1833
1834
                        $amount = floatval( $item['price'] );
1835
1836
                        if ( wpinv_use_taxes() ) {
1837
1838
                            $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1839
1840
                            if ( wpinv_prices_include_tax() ) {
1841
                                $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1842
                                $item_tax = $amount - $pre_tax;
1843
                            } else {
1844
                                $pre_tax  = $amount;
1845
                                $item_tax = $amount * $rate * 0.01;
1846
                            }
1847
1848
                            $tax       = $tax + $item_tax;
1849
                            $sub_total = $sub_total + $pre_tax;
1850
                            $total     = $sub_total + $tax;
1851
1852
                        } else {
1853
                            $total  = $total + $amount;
1854
                        }
1855
1856
                        $class  = 'col-8';
1857
                        $class2 = '';
1858
1859
                        if ( ! empty( $item['allow_quantities'] ) ) {
1860
                            $class = 'col-6 pt-2';
1861
                            $class2 = 'pt-2';
1862
                        }
1863
1864
                        if ( ! empty( $item['custom_price'] ) ) {
1865
                            $class .= ' pt-2';
1866
                        }
1867
            
1868
                ?>
1869
                    <div  class="item_totals_item">
1870
                        <div class='row pl-2 pr-2 pt-2'>
1871
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
1872
1873
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1874
1875
                                <div class='col-2'>
1876
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
1877
                                </div>
1878
1879
                            <?php } else { ?>
1880
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1881
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1882
1883
                                <div class='col-4 <?php echo $class2; ?>'>
1884
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1885
                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1886
                                </div>
1887
1888
                            <?php } else {?>
1889
1890
                                <div class='col-4'>
1891
                                    <div class='input-group'>
1892
1893
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1894
                                            <div class='input-group-prepend'>
1895
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1896
                                            </div>
1897
                                        <?php } ?>
1898
1899
                                        <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1900
                                    
1901
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1902
                                            <div class='input-group-append'>
1903
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1904
                                            </div>
1905
                                        <?php } ?>
1906
1907
                                    </div>
1908
                                </div>
1909
                            <?php } ?>
1910
1911
                        </div>
1912
                        <?php if ( ! empty( $item['description'] )) { ?>
1913
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1914
                        <?php } ?>
1915
                    </div>
1916
                <?php } ?>
1917
1918
                <div class='mt-4 border-top item_totals_total p-2'>
1919
1920
                    <?php if ( wpinv_use_taxes() ) { ?>
1921
                        <div class='row'>
1922
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1923
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1924
                        </div>
1925
                        <div class='row'>
1926
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1927
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1928
                        </div>
1929
                    <?php } ?>
1930
1931
                    <div class='row'>
1932
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1933
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1934
                    </div>
1935
1936
                </div>
1937
1938
            </div>
1939
        <?php } ?>
1940
1941
        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
1942
            <div class="item_totals_type_radio">
1943
1944
                <?php
1945
                    foreach( $items as $index => $item ) {
1946
1947
                        if ( ! empty( $item['required'] ) ) {
1948
                            continue;
1949
                        }
1950
                ?>
1951
                    <div  class="form-check">
1952
                        <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
1953
                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?>&nbsp;<strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) ); ?></strong></label>
1954
                    </div>
1955
                    <?php if ( ! empty( $item['description'] )) { ?>
1956
                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1957
                    <?php } ?>
1958
                <?php } ?>
1959
1960
                <div class="mt-3 border item_totals_type_radio_totals">
1961
1962
                    <?php
1963
1964
                        $total     = 0;
1965
                        $tax       = 0;
1966
                        $sub_total = 0;
1967
1968
                        foreach ( $items as $item ) {
1969
1970
                            $class  = 'col-8';
1971
                            $class2 = '';
1972
1973
                            if ( ! empty( $item['allow_quantities'] ) ) {
1974
                                $class = 'col-6 pt-2';
1975
                                $class2 = 'pt-2';
1976
                            }
1977
1978
                            if ( ! empty( $item['custom_price'] ) ) {
1979
                                $class .= ' pt-2';
1980
                            }
1981
1982
                            $class3 = 'd-none';
1983
                            $name   = '';
1984
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
1985
1986
                                $amount = floatval( $item['price'] );
1987
1988
                                if ( wpinv_use_taxes() ) {
1989
1990
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1991
1992
                                    if ( wpinv_prices_include_tax() ) {
1993
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1994
                                        $item_tax = $amount - $pre_tax;
1995
                                    } else {
1996
                                        $pre_tax  = $amount;
1997
                                        $item_tax = $amount * $rate * 0.01;
1998
                                    }
1999
2000
                                    $tax       = $tax + $item_tax;
2001
                                    $sub_total = $sub_total + $pre_tax;
2002
                                    $total     = $sub_total + $tax;
2003
2004
                                } else {
2005
                                    $total  = $total + $amount;
2006
                                }
2007
2008
                                $class3 = '';
2009
                                $name   = "wpinv-items[{$item['id']}]";
2010
2011
                                if ( empty( $item['required'] ) ) {
2012
                                    $totals_selected_radio_item = 1;
2013
                                }
2014
2015
                            }
2016
2017
                            $class3 .= " wpinv_item_{$item['id']}";
2018
2019
                    ?>
2020
2021
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2022
                        <div class='row pl-2 pr-2 pt-2'>
2023
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2024
2025
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2026
2027
                                <div class='col-2'>
2028
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2029
                                </div>
2030
2031
                            <?php } else { ?>
2032
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2033
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2034
2035
                                <div class='col-4 <?php echo $class2; ?>'>
2036
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2037
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2038
                                </div>
2039
2040
                            <?php } else {?>
2041
2042
                                <div class='col-4'>
2043
                                    <div class='input-group'>
2044
2045
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2046
                                            <div class='input-group-prepend'>
2047
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2048
                                            </div>
2049
                                        <?php } ?>
2050
2051
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2052
                                    
2053
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2054
                                            <div class='input-group-append'>
2055
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2056
                                            </div>
2057
                                        <?php } ?>
2058
2059
                                    </div>
2060
                                </div>
2061
                            <?php } ?>
2062
2063
                        </div>
2064
                        <?php if ( ! empty( $item['description'] )) { ?>
2065
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2066
                        <?php } ?>
2067
                    </div>
2068
                <?php } ?>
2069
2070
                <div class='mt-4 border-top item_totals_total p-2'>
2071
                    <?php if ( wpinv_use_taxes() ) { ?>
2072
                        <div class='row'>
2073
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2074
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2075
                        </div>
2076
                        <div class='row'>
2077
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2078
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2079
                        </div>
2080
                    <?php } ?>
2081
2082
                    <div class='row'>
2083
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2084
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2085
                    </div>
2086
                </div>
2087
2088
            </div>
2089
            </div>
2090
        <?php } ?>
2091
2092
        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
2093
2094
            <div class="item_totals_type_checkbox">
2095
2096
                <?php
2097
                    foreach ( $items as $index => $item ) {
2098
2099
                        if ( ! empty( $item['required'] ) ) {
2100
                            continue;
2101
                        }
2102
2103
                        $title = sanitize_text_field(  $item['title'] );
2104
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2105
                        $item_id    = esc_attr( $id . "_$index" );
2106
                        $value = esc_attr( $item['id'] );
2107
                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
2108
                        $selected_checkbox_item = 1;
2109
2110
                        echo "
2111
                            <div class='custom-control custom-checkbox'>
2112
                                <input type='checkbox' name='payment-form-items[]' id='$item_id' value='$value' class='wpi-payment-form-items-select-checkbox form-control custom-control-input' $checked>
2113
                                <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
2114
                            </div>";
2115
2116
                        if ( ! empty( $item['description'] ) ) {
2117
                            echo "<small class='form-text text-muted'>{$item['description']}</small>";
2118
                        }
2119
                    }
2120
                ?>
2121
2122
                <div class="mt-3 border item_totals_type_checkbox_totals">
2123
2124
                    <?php
2125
2126
                        $total     = 0;
2127
                        $tax       = 0;
2128
                        $sub_total = 0;
2129
2130
                        foreach ( $items as $item ) {
2131
2132
                            $class  = 'col-8';
2133
                            $class2 = '';
2134
2135
                            if ( ! empty( $item['allow_quantities'] ) ) {
2136
                                $class = 'col-6 pt-2';
2137
                                $class2 = 'pt-2';
2138
                            }
2139
2140
                            if ( ! empty( $item['custom_price'] ) ) {
2141
                                $class .= ' pt-2';
2142
                            }
2143
2144
                            $class3 = 'd-none';
2145
                            $name  = '';
2146
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2147
2148
                                $amount = floatval( $item['price'] );
2149
                                if ( wpinv_use_taxes() ) {
2150
2151
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2152
2153
                                    if ( wpinv_prices_include_tax() ) {
2154
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2155
                                        $item_tax = $amount - $pre_tax;
2156
                                    } else {
2157
                                        $pre_tax  = $amount;
2158
                                        $item_tax = $amount * $rate * 0.01;
2159
                                    }
2160
2161
                                    $tax       = $tax + $item_tax;
2162
                                    $sub_total = $sub_total + $pre_tax;
2163
                                    $total     = $sub_total + $tax;
2164
2165
                                } else {
2166
                                    $total  = $total + $amount;
2167
                                }
2168
2169
                                $class3 = '';
2170
                                $name  = "wpinv-items[{$item['id']}]";
2171
2172
                                if ( empty( $item['required'] ) ) {
2173
                                    $totals_selected_checkbox_item = 1;
2174
                                }
2175
2176
                            }
2177
2178
                            $class3 .= " wpinv_item_{$item['id']}";
2179
2180
                    ?>
2181
2182
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2183
                        <div class='row pl-2 pr-2 pt-2'>
2184
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2185
2186
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2187
2188
                                <div class='col-2'>
2189
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2190
                                </div>
2191
2192
                            <?php } else { ?>
2193
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2194
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2195
2196
                                <div class='col-4 <?php echo $class2; ?>'>
2197
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2198
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2199
                                </div>
2200
2201
                            <?php } else {?>
2202
2203
                                <div class='col-4'>
2204
                                    <div class='input-group'>
2205
2206
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2207
                                            <div class='input-group-prepend'>
2208
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2209
                                            </div>
2210
                                        <?php } ?>
2211
2212
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2213
                                    
2214
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2215
                                            <div class='input-group-append'>
2216
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2217
                                            </div>
2218
                                        <?php } ?>
2219
2220
                                    </div>
2221
                                </div>
2222
                            <?php } ?>
2223
2224
                        </div>
2225
                        <?php if ( ! empty( $item['description'] )) { ?>
2226
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2227
                        <?php } ?>
2228
                    </div>
2229
                <?php } ?>
2230
2231
                <div class='mt-4 border-top item_totals_total p-2'>
2232
2233
                    <?php if ( wpinv_use_taxes() ) { ?>
2234
                        <div class='row'>
2235
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2236
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2237
                        </div>
2238
                        <div class='row'>
2239
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2240
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2241
                        </div>
2242
                    <?php } ?>
2243
2244
                    <div class='row'>
2245
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2246
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2247
                    </div>
2248
                </div>
2249
            </div>
2250
            </div>
2251
        <?php } ?>
2252
2253
        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2254
2255
            <div class="item_totals_type_select">
2256
2257
                <?php
2258
2259
                    $options  = array();
2260
                    $selected = '';
2261
                    foreach ( $items as $index => $item ) {
2262
2263
                        if ( ! empty( $item['required'] ) ) {
2264
                            continue;
2265
                        }
2266
2267
                        $title = sanitize_text_field(  $item['title'] );
2268
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2269
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2270
2271
                        if ( ! isset( $selected_item ) ) {
2272
                            $selected = $item['id'];
2273
                            $selected_item = 1;
2274
                        }
2275
                        
2276
                    }
2277
2278
                    echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2278
                    echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
2279
                        array(
2280
                                'name'        => 'payment-form-items',
2281
                                'id'          => $id,
2282
                                'placeholder' => __( 'Select an item', 'invoicing' ),
2283
                                'no_wrap'     => true,
2284
                                'options'     => $options,
2285
                                'class'       => 'wpi_select2 wpinv-items-select-selector',
2286
                                'value'       => $selected,
2287
                        )
2288
                    );
2289
                ?>
2290
2291
                <div class="mt-3 border item_totals_type_select_totals">
2292
2293
                    <?php
2294
2295
                        $total     = 0;
2296
                        $tax       = 0;
2297
                        $sub_total = 0;
2298
2299
                        foreach ( $items as $item ) {
2300
2301
                            $class  = 'col-8';
2302
                            $class2 = '';
2303
2304
                            if ( ! empty( $item['allow_quantities'] ) ) {
2305
                                $class = 'col-6 pt-2';
2306
                                $class2 = 'pt-2';
2307
                            }
2308
2309
                            if ( ! empty( $item['custom_price'] ) ) {
2310
                                $class .= ' pt-2';
2311
                            }
2312
2313
                            $class3 = 'd-none';
2314
                            $name  = '';
2315
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2316
2317
                                $amount = floatval( $item['price'] );
2318
                                if ( wpinv_use_taxes() ) {
2319
2320
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2321
2322
                                    if ( wpinv_prices_include_tax() ) {
2323
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2324
                                        $item_tax = $amount - $pre_tax;
2325
                                    } else {
2326
                                        $pre_tax  = $amount;
2327
                                        $item_tax = $amount * $rate * 0.01;
2328
                                    }
2329
2330
                                    $tax       = $tax + $item_tax;
2331
                                    $sub_total = $sub_total + $pre_tax;
2332
                                    $total     = $sub_total + $tax;
2333
2334
                                } else {
2335
                                    $total  = $total + $amount;
2336
                                }
2337
2338
                                $class3 = '';
2339
                                $name  = "wpinv-items[{$item['id']}]";
2340
2341
                                if ( empty( $item['required'] ) ) {
2342
                                    $totals_selected_select_item = 1;
2343
                                }
2344
2345
                            }
2346
2347
                            $class3 .= " wpinv_item_{$item['id']}";
2348
2349
                    ?>
2350
2351
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2352
                        <div class='row pl-2 pr-2 pt-2'>
2353
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2354
2355
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2356
2357
                                <div class='col-2'>
2358
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2359
                                </div>
2360
2361
                            <?php } else { ?>
2362
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2363
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2364
2365
                                <div class='col-4 <?php echo $class2; ?>'>
2366
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2367
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2368
                                </div>
2369
2370
                            <?php } else {?>
2371
2372
                                <div class='col-4'>
2373
                                    <div class='input-group'>
2374
2375
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2376
                                            <div class='input-group-prepend'>
2377
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2378
                                            </div>
2379
                                        <?php } ?>
2380
2381
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2382
                                    
2383
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2384
                                            <div class='input-group-append'>
2385
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2386
                                            </div>
2387
                                        <?php } ?>
2388
2389
                                    </div>
2390
                                </div>
2391
                            <?php } ?>
2392
2393
                        </div>
2394
                        <?php if ( ! empty( $item['description'] )) { ?>
2395
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2396
                        <?php } ?>
2397
                    </div>
2398
                <?php } ?>
2399
2400
                <div class='mt-4 border-top item_totals_total p-2'>
2401
2402
                    <?php if ( wpinv_use_taxes() ) { ?>
2403
                        <div class='row'>
2404
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2405
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2406
                        </div>
2407
                        <div class='row'>
2408
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2409
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2410
                        </div>
2411
                    <?php } ?>
2412
                    <div class='row'>
2413
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2414
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2415
                    </div>
2416
                </div>
2417
2418
            </div>
2419
        <?php } ?>
2420
2421
        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2422
2423
            <div class="item_totals_type_multi_select">
2424
2425
                <?php
2426
2427
                    $options  = array();
2428
                    $selected = array();
2429
2430
                    foreach ( $items as $index => $item ) {
2431
2432
                        if ( ! empty( $item['required'] ) ) {
2433
                            continue;
2434
                        }
2435
2436
                        $title = sanitize_text_field(  $item['title'] );
2437
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2438
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2439
2440
                        if ( ! isset( $selected_item ) ) {
2441
                            $selected = array( $item['id'] );
2442
                            $selected_item = 1;
2443
                        }
2444
2445
                    }
2446
2447
                    echo aui()->select(
2448
                        array(
2449
                                'name'        => 'payment-form-items',
2450
                                'id'          => $id,
2451
                                'no_wrap'     => true,
2452
                                'options'     => $options,
2453
                                'multiple'    => true,
2454
                                'class'       => 'wpi_select2 wpinv-items-multiselect-selector',
2455
                                'value'       => $selected,
2456
                        )
2457
                    );
2458
                ?>
2459
2460
                <div class="mt-3 border item_totals_type_select_totals">
2461
2462
                    <?php
2463
2464
                        $total     = 0;
2465
                        $tax       = 0;
2466
                        $sub_total = 0;
2467
2468
                        foreach ( $items as $item ) {
2469
2470
                            $class  = 'col-8';
2471
                            $class2 = '';
2472
2473
                            if ( ! empty( $item['allow_quantities'] ) ) {
2474
                                $class = 'col-6 pt-2';
2475
                                $class2 = 'pt-2';
2476
                            }
2477
2478
                            if ( ! empty( $item['custom_price'] ) ) {
2479
                                $class .= ' pt-2';
2480
                            }
2481
2482
                            $class3 = 'd-none';
2483
                            $name  = '';
2484
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2485
2486
                                $amount = floatval( $item['price'] );
2487
                                if ( wpinv_use_taxes() ) {
2488
2489
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2490
2491
                                    if ( wpinv_prices_include_tax() ) {
2492
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2493
                                        $item_tax = $amount - $pre_tax;
2494
                                    } else {
2495
                                        $pre_tax  = $amount;
2496
                                        $item_tax = $amount * $rate * 0.01;
2497
                                    }
2498
2499
                                    $tax       = $tax + $item_tax;
2500
                                    $sub_total = $sub_total + $pre_tax;
2501
                                    $total     = $sub_total + $tax;
2502
2503
                                } else {
2504
                                    $total  = $total + $amount;
2505
                                }
2506
2507
                                $class3 = '';
2508
                                $name  = "wpinv-items[{$item['id']}]";
2509
2510
                                if ( empty( $item['required'] ) ) {
2511
                                    $totals_selected_select_item = 1;
2512
                                }
2513
2514
                            }
2515
2516
                            $class3 .= " wpinv_item_{$item['id']}";
2517
2518
                    ?>
2519
2520
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2521
                        <div class='row pl-2 pr-2 pt-2'>
2522
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2523
2524
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2525
2526
                                <div class='col-2'>
2527
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
2528
                                </div>
2529
2530
                            <?php } else { ?>
2531
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2532
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2533
2534
                                <div class='col-4 <?php echo $class2; ?>'>
2535
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2536
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2537
                                </div>
2538
2539
                            <?php } else {?>
2540
2541
                                <div class='col-4'>
2542
                                    <div class='input-group'>
2543
2544
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2545
                                            <div class='input-group-prepend'>
2546
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2547
                                            </div>
2548
                                        <?php } ?>
2549
2550
                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2551
                                    
2552
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2553
                                            <div class='input-group-append'>
2554
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2555
                                            </div>
2556
                                        <?php } ?>
2557
2558
                                    </div>
2559
                                </div>
2560
                            <?php } ?>
2561
2562
                        </div>
2563
                        <?php if ( ! empty( $item['description'] )) { ?>
2564
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2565
                        <?php } ?>
2566
                    </div>
2567
                <?php } ?>
2568
2569
                <div class='mt-4 border-top item_totals_total p-2'>
2570
2571
                    <?php if ( wpinv_use_taxes() ) { ?>
2572
                        <div class='row'>
2573
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2574
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2575
                        </div>
2576
                        <div class='row'>
2577
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2578
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2579
                        </div>
2580
                    <?php } ?>
2581
2582
                    <div class='row'>
2583
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2584
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2585
                    </div>
2586
                </div>
2587
2588
            </div>
2589
        <?php } ?>
2590
        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2591
            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2592
        <?php } ?>
2593
        </div>
2594
        <?php
2595
    }
2596
2597
    /**
2598
     * Renders the items element template.
2599
     */
2600
    public function edit_items_template( $field ) {
2601
        global $wpinv_euvat, $post;
2602
2603
        $restrict = $this->get_restrict_markup( $field, 'items' );
2604
        $label    = __( 'Let customers...', 'invoicing' );
2605
        $label2   = __( 'Available Items', 'invoicing' );
2606
        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2607
        $id       = $field . '.id + "_edit"';
2608
        $id2      = $field . '.id + "_edit2"';
2609
        $id3      = $field . '.id + "_edit3"';
2610
        $id4      = $field . '.id + "_edit4"';
2611
        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2612
        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2613
        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2614
        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2615
        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2616
2617
        // Item types.
2618
        $item_types      = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
2619
        $item_types_html = '';
2620
2621
        foreach ( $item_types as $type => $label ) {
2622
            $type  = esc_attr( $type );
2623
            $label = esc_html( $label );
2624
            $item_types_html .= "<option value='$type'>$label</type>";
2625
        }
2626
2627
        // Taxes.
2628
        $taxes = '';
2629
        if ( $wpinv_euvat->allow_vat_rules() ) {
2630
            $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"rule\"'>";
2631
            $taxes .= __( 'VAT rule type', 'invoicing' );
2632
            $taxes .= "</label><select :id='$id + item.id + \"rule\"' class='form-control custom-select' v-model='item.rule'>";
2633
2634
            foreach ( $wpinv_euvat->get_rules() as $type => $label ) {
2635
                $type   = esc_attr( $type );
2636
                $label  = esc_html( $label );
2637
                $taxes .= "<option value='$type'>$label</type>";
2638
            }
2639
2640
            $taxes .= '</select></div>';
2641
        }
2642
2643
        if ( $wpinv_euvat->allow_vat_classes() ) {
2644
            $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"class\"'>";
2645
            $taxes .= __( 'VAT class', 'invoicing' );
2646
            $taxes .= "</label><select :id='$id + item.id + \"class\"' class='form-control custom-select' v-model='item.class'>";
2647
2648
            foreach ( $wpinv_euvat->get_all_classes() as $type => $label ) {
2649
                $type   = esc_attr( $type );
2650
                $label  = esc_html( $label );
2651
                $taxes .= "<option value='$type'>$label</type>";
2652
            }
2653
2654
            $taxes .= '</select></div>';
2655
        }
2656
2657
        echo "<div $restrict>
2658
2659
                <label>$label2</label>
2660
2661
                <draggable v-model='form_items' group='selectable_form_items'>
2662
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'>
2663
2664
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
2665
                            <span class='label'>{{item.title}}</span>
2666
                            <span class='price'>({{formatPrice(item.price)}})</span>
2667
                            <span class='toggle-icon'>
2668
                                <span class='dashicons dashicons-arrow-down'></span>
2669
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
2670
                            </span>
2671
                        </div>
2672
2673
                        <div class='wpinv-available-items-editor-body'>
2674
                            <div class='p-2'>
2675
2676
                                <div class='form-group'>
2677
                                    <label :for='$id + item.id'>Item Name</label>
2678
                                    <input :id='$id + item.id' v-model='item.title' class='form-control' />
2679
                                </div>
2680
2681
                                <div class='form-group'>
2682
                                    <label :for='$id + item.id + \"price\"'>Item Price</label>
2683
                                    <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' />
2684
                                    <small class='form-text text-muted' v-if='item.custom_price'>$label4</small>
2685
                                </div>
2686
2687
                                <div class='form-group' v-if='item.new'>
2688
                                    <label :for='$id + item.id + \"type\"'>Item Type</label>
2689
                                    <select class='form-control custom-select' v-model='item.type'>
2690
                                        $item_types_html
2691
                                    </select>
2692
                                </div>
2693
2694
                                <div v-if='item.new'>$taxes</div>
2695
2696
                                <div class='form-group form-check'>
2697
                                    <input :id='$id4 + item.id + \"custom_price\"' v-model='item.custom_price' type='checkbox' class='form-check-input' />
2698
                                    <label class='form-check-label' :for='$id4 + item.id + \"custom_price\"'>$label5</label>
2699
                                </div>
2700
2701
                                <div class='form-group' v-if='item.custom_price'>
2702
                                    <label :for='$id + item.id + \"minimum_price\"'>Minimum Price</label>
2703
                                    <input :id='$id + item.id + \"minimum_price\"' placeholder='0.00' v-model='item.minimum_price' class='form-control' />
2704
                                    <small class='form-text text-muted'>$label6</small>
2705
                                </div>
2706
2707
                                <div class='form-group form-check'>
2708
                                    <input :id='$id + item.id + \"quantities\"' v-model='item.allow_quantities' type='checkbox' class='form-check-input' />
2709
                                    <label class='form-check-label' :for='$id + item.id + \"quantities\"'>$label7</label>
2710
                                </div>
2711
2712
                                <div class='form-group form-check'>
2713
                                    <input :id='$id + item.id + \"required\"' v-model='item.required' type='checkbox' class='form-check-input' />
2714
                                    <label class='form-check-label' :for='$id + item.id + \"required\"'>$label8</label>
2715
                                </div>
2716
2717
                                <div class='form-group'>
2718
                                    <label :for='$id + item.id + \"description\"'>Item Description</label>
2719
                                    <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea>
2720
                                </div>
2721
2722
                                <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'>Delete Item</button>
2723
2724
                            </div>
2725
                        </div>
2726
2727
                    </div>
2728
                </draggable>
2729
2730
                <small v-if='! form_items.length' class='form-text text-danger'> You have not set up any items. Please select an item below or create a new item.</small>
2731
2732
                <div class='form-group mt-2'>
2733
2734
                    <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'>
2735
                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2736
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2737
                    </select>
2738
2739
                </div>
2740
2741
                <div class='form-group'>
2742
                    <input type='button' value='Add item' class='button button-primary'  @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'>
2743
                    <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small>
2744
                </div>
2745
2746
                <div class='form-group mt-5'>
2747
                    <label :for='$id2'>$label</label>
2748
2749
                    <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2750
                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2751
                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2752
                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2753
                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2754
                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2755
                    </select>
2756
2757
                </div>
2758
2759
                <div class='form-group'>
2760
                    <label :for='$id3'>Help Text</label>
2761
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
2762
                </div>
2763
2764
            </div>
2765
        ";
2766
2767
    }
2768
2769
    /**
2770
     * Returns an array of all published items.
2771
     */
2772
    public function get_published_items() {
2773
    
2774
        $item_args = array(
2775
            'post_type'      => 'wpi_item',
2776
            'orderby'        => 'title',
2777
            'order'          => 'ASC',
2778
            'posts_per_page' => -1,
2779
            'post_status'    => array( 'publish' ),
2780
            'meta_query'     => array(
2781
                array(
2782
                    'key'       => '_wpinv_type',
2783
                    'compare'   => '!=',
2784
                    'value'     => 'package'
2785
                )
2786
            )
2787
        );
2788
    
2789
        $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) );
2790
2791
        if ( empty( $items ) ) {
2792
            return array();
2793
        }
2794
2795
        $options    = array();
2796
        foreach ( $items as $item ) {
2797
            $title            = esc_html( $item->post_title );
2798
            $title           .= wpinv_get_item_suffix( $item->ID, false );
2799
            $id               = absint( $item->ID );
2800
            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
2801
            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
2802
            $description      = $item->post_excerpt;
2803
            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
2804
            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
2805
            $allow_quantities = false;
2806
            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
2807
2808
        }
2809
        return $options;
2810
2811
    }
2812
2813
    /**
2814
     * Returns an array of items for the currently being edited form.
2815
     */
2816
    public function get_form_items( $id = false ) {
2817
        
2818
        if ( empty( $id ) ) {
2819
            return wpinv_get_data( 'sample-payment-form-items' );
2820
        }
2821
        
2822
        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
2823
2824
        if ( is_array( $form_elements ) ) {
2825
            return $form_elements;
2826
        }
2827
2828
        return wpinv_get_data( 'sample-payment-form-items' );
2829
2830
    }
2831
2832
    /**
2833
     * Returns an array of elements for the currently being edited form.
2834
     */
2835
    public function get_form_elements( $id = false ) {
2836
2837
        if ( empty( $id ) ) {
2838
            return wpinv_get_data( 'sample-payment-form' );
2839
        }
2840
        
2841
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
2842
2843
        if ( is_array( $form_elements ) ) {
2844
            return $form_elements;
2845
        }
2846
2847
        return wpinv_get_data( 'sample-payment-form' );
2848
    }
2849
2850
    /**
2851
     * Sends a redrect response to payment details.
2852
     *
2853
     */
2854
    public function send_redirect_response( $url ) {
2855
        $url = urlencode( $url );
2856
        wp_send_json_success( $url );
2857
    }
2858
2859
    /**
2860
     * Fired when a checkout error occurs
2861
     *
2862
     */
2863
    public function checkout_error() {
2864
2865
        $errors = wpinv_get_errors();
2866
2867
        if ( ! empty( $errors ) ) {
2868
            wpinv_print_errors();
2869
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2870
        }
2871
2872
        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
2873
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2874
2875
    }
2876
2877
}
2878