|
1
|
|
|
<?php |
|
2
|
|
|
// MUST have WordPress. |
|
3
|
|
|
if ( !defined( 'WPINC' ) ) { |
|
4
|
|
|
exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
class WPInv_Meta_Box_Form_Items { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Outputs the payment forms items select. |
|
11
|
|
|
* |
|
12
|
|
|
* @param WP_Post $post |
|
13
|
|
|
*/ |
|
14
|
|
|
public static function output( $post ) { |
|
15
|
|
|
global $wpinv_euvat, $ajax_cart_details; |
|
16
|
|
|
|
|
17
|
|
|
$post_id = ! empty( $post->ID ) ? $post->ID : 0; |
|
|
|
|
|
|
18
|
|
|
$items = get_post_meta( $post->ID, 'wpinv_payment_items', true ); |
|
19
|
|
|
$supports_discounts = (int) get_post_meta( $post->ID, 'wpinv_form_supports_discounts', true ); |
|
20
|
|
|
$supports_quantities = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
|
21
|
|
|
$enable_taxes = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
|
22
|
|
|
$item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
if ( empty( $items ) || ! is_array( $items ) ) { |
|
25
|
|
|
$items = array(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
?> |
|
29
|
|
|
|
|
30
|
|
|
<div class="wpinv-items-wrap-pending" id="wpinv_items_wrap"> |
|
31
|
|
|
<table |
|
32
|
|
|
id="wpinv_items" |
|
33
|
|
|
class="wpinv-items" |
|
34
|
|
|
cellspacing="0" |
|
35
|
|
|
cellpadding="0" |
|
36
|
|
|
data-supports-discouts="<?php echo $supports_discounts; ?>" |
|
37
|
|
|
data-supports-discouts="<?php echo $supports_quantities; ?>" |
|
38
|
|
|
data-supports-discouts="<?php echo $enable_taxes; ?>" |
|
39
|
|
|
data-decimal-places="<?php echo esc_attr( wpinv_decimals() ); ?>" |
|
40
|
|
|
data-currency-symbol="<?php echo esc_attr( wpinv_currency_symbol() ); ?>" |
|
41
|
|
|
data-currency-position="<?php echo esc_attr( wpinv_currency_position() ); ?>" |
|
42
|
|
|
> |
|
43
|
|
|
|
|
44
|
|
|
<thead> |
|
45
|
|
|
<tr> |
|
46
|
|
|
<th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
47
|
|
|
<th class="title"><?php _e( 'Name', 'invoicing' );?></th> |
|
48
|
|
|
<th class="desc"><?php _e( 'Description', 'invoicing' );?></th> |
|
49
|
|
|
<th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
50
|
|
|
<th class="action"></th> |
|
51
|
|
|
</tr> |
|
52
|
|
|
</thead> |
|
53
|
|
|
|
|
54
|
|
|
<tbody class="wpinv-line-items"> |
|
55
|
|
|
<?php |
|
56
|
|
|
|
|
57
|
|
|
foreach ( $items as $item ) { |
|
58
|
|
|
$id = isset( $item['id'] ) ? (int) $item['id'] : 0; |
|
59
|
|
|
$name = isset( $item['name'] ) ? sanitize_text_field( $item['name'] ) : __( 'No name', 'invoicing' ); |
|
60
|
|
|
$price = isset( $item['price'] ) ? wpinv_format_amount( $item['price'] ) : 0.00; |
|
61
|
|
|
$description = isset( $item['description'] ) ? esc_textarea( $item['description'] ) : ''; |
|
62
|
|
|
|
|
63
|
|
|
?> |
|
64
|
|
|
|
|
65
|
|
|
<tr class="item" data-item-id="<?php echo $id; ?>"> |
|
66
|
|
|
<td class="id"><?php echo $id; ?></td> |
|
67
|
|
|
<td class="title"> |
|
68
|
|
|
<a href="<?php echo esc_url( get_edit_post_link( $id ) ); ?>" target="_blank"><?php echo $name ; ?></a> |
|
69
|
|
|
<?php echo wpinv_get_item_suffix( $id ); ?> |
|
70
|
|
|
</td> |
|
71
|
|
|
<td class="meta"> |
|
72
|
|
|
<?php echo $description ; ?> |
|
73
|
|
|
</td> |
|
74
|
|
|
<td class="price"> |
|
75
|
|
|
<?php echo $price ; ?> |
|
76
|
|
|
</td> |
|
77
|
|
|
</tr> |
|
78
|
|
|
|
|
79
|
|
|
<?php } ?> |
|
80
|
|
|
|
|
81
|
|
|
</tbody> |
|
82
|
|
|
</table> |
|
83
|
|
|
<div id="wpinv-quick-add" style="display: none;"> |
|
84
|
|
|
<table cellspacing="0" cellpadding="0"> |
|
85
|
|
|
<tr> |
|
86
|
|
|
<td class="id"> |
|
87
|
|
|
</td> |
|
88
|
|
|
<td class="title"> |
|
89
|
|
|
<input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
|
90
|
|
|
|
|
91
|
|
|
<div class="wp-clearfix"> |
|
92
|
|
|
<label class="wpi-item-type"> |
|
93
|
|
|
<span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
94
|
|
|
</label> |
|
95
|
|
|
</div> |
|
96
|
|
|
|
|
97
|
|
|
<div class="wp-clearfix"> |
|
98
|
|
|
<?php |
|
99
|
|
|
echo wpinv_html_textarea( array( |
|
100
|
|
|
'name' => '_wpinv_quick[excerpt]', |
|
101
|
|
|
'id' => '_wpinv_quick_excerpt', |
|
102
|
|
|
'value' => '', |
|
103
|
|
|
'class' => 'large-text', |
|
104
|
|
|
'label' => __( 'Item description', 'invoicing' ), |
|
105
|
|
|
) ); |
|
106
|
|
|
?> |
|
107
|
|
|
</div> |
|
108
|
|
|
|
|
109
|
|
|
<div class="wp-clearfix"> |
|
110
|
|
|
<label class="wpi-item-actions"> |
|
111
|
|
|
<span class="input-text-wrap"> |
|
112
|
|
|
<input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
113
|
|
|
</span> |
|
114
|
|
|
</label> |
|
115
|
|
|
</div> |
|
116
|
|
|
</td> |
|
117
|
|
|
|
|
118
|
|
|
<td class="price"> |
|
119
|
|
|
<input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /> |
|
120
|
|
|
</td> |
|
121
|
|
|
|
|
122
|
|
|
<td class="action"></td> |
|
123
|
|
|
</tr> |
|
124
|
|
|
</table> |
|
125
|
|
|
</div> |
|
126
|
|
|
<div class="wpinv-actions"> |
|
127
|
|
|
|
|
128
|
|
|
<?php |
|
129
|
|
|
|
|
130
|
|
|
echo wpinv_item_dropdown( array( |
|
131
|
|
|
'name' => 'wpinv_invoice_item', |
|
132
|
|
|
'id' => 'wpinv_invoice_item', |
|
133
|
|
|
'show_recurring' => true, |
|
134
|
|
|
'class' => 'wpi_select2', |
|
135
|
|
|
) ); |
|
136
|
|
|
|
|
137
|
|
|
?> |
|
138
|
|
|
|
|
139
|
|
|
<input type="button" value="<?php esc_attr_e( 'Add item to form', 'invoicing'); ?>" class="button button-primary" id="wpinv-add-item" /> |
|
140
|
|
|
<input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item" /> |
|
141
|
|
|
|
|
142
|
|
|
</div> |
|
143
|
|
|
</div> |
|
144
|
|
|
<?php |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Outputs the payment options. |
|
149
|
|
|
* |
|
150
|
|
|
* @param WP_Post $post |
|
151
|
|
|
*/ |
|
152
|
|
|
public static function output_options( $post ) { |
|
153
|
|
|
|
|
154
|
|
|
$post_id = ! empty( $post->ID ) ? $post->ID : 0; |
|
|
|
|
|
|
155
|
|
|
$success_page = get_post_meta( $post->ID, 'wpinv_success_page', true ); |
|
156
|
|
|
$button_text = get_post_meta( $post->ID, 'wpinv_button_text', true ); |
|
157
|
|
|
$processing_text = get_post_meta( $post->ID, 'wpinv_processing_text', true ); |
|
158
|
|
|
$supports_quantities = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
|
159
|
|
|
$supports_discounts = (int) get_post_meta( $post->ID, 'wpinv_form_supports_discounts', true ); |
|
160
|
|
|
$enable_taxes = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
|
161
|
|
|
|
|
162
|
|
|
$values = array( |
|
163
|
|
|
'success_page' => empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page, |
|
164
|
|
|
'button_text' => empty( $button_text ) ? __( 'Pay Now', 'invoicing' ) : $button_text, |
|
165
|
|
|
'processing_text' => empty( $processing_text ) ? __( 'Processing', 'invoicing' ) : $processing_text, |
|
166
|
|
|
'supports_quantities' => empty( $supports_quantities ) ? 0 : 1, |
|
167
|
|
|
'enable_taxes' => empty( $enable_taxes ) ? 0 : 1, |
|
168
|
|
|
'supports_discounts' => empty( $supports_discounts ) ? 0 : 1, |
|
169
|
|
|
); |
|
170
|
|
|
|
|
171
|
|
|
?> |
|
172
|
|
|
|
|
173
|
|
|
<div class="wpinv-items-wrap-pending" id="wpinv_items_wrap"> |
|
174
|
|
|
<table class="form-table"> |
|
175
|
|
|
<tbody> |
|
176
|
|
|
|
|
177
|
|
|
<tr class="form-field-supports_quantities"> |
|
178
|
|
|
<th scope="row"></th> |
|
179
|
|
|
<td> |
|
180
|
|
|
<div> |
|
181
|
|
|
<label> |
|
182
|
|
|
<input type="checkbox" name="supports_quantities" id="field_supports_quantities" value="1" <?php checked( $values['supports_quantities'], 1 ); ?>> |
|
183
|
|
|
<span><?php _e( 'Let users set custom item quantities', 'invoicing' ); ?></span> |
|
184
|
|
|
</label> |
|
185
|
|
|
</div> |
|
186
|
|
|
</td> |
|
187
|
|
|
</tr> |
|
188
|
|
|
|
|
189
|
|
|
<tr class="form-field-enable_taxes"> |
|
190
|
|
|
<th scope="row"></th> |
|
191
|
|
|
<td> |
|
192
|
|
|
<div> |
|
193
|
|
|
<label> |
|
194
|
|
|
<input type="checkbox" name="enable_taxes" id="field_enable_taxes" value="1" <?php checked( $values['enable_taxes'], 1 ); ?>> |
|
195
|
|
|
<span><?php _e( 'Enable tax calculations', 'invoicing' ); ?></span> |
|
196
|
|
|
</label> |
|
197
|
|
|
</div> |
|
198
|
|
|
</td> |
|
199
|
|
|
</tr> |
|
200
|
|
|
|
|
201
|
|
|
<tr class="form-field-supports_discounts"> |
|
202
|
|
|
<th scope="row"></th> |
|
203
|
|
|
<td> |
|
204
|
|
|
<div> |
|
205
|
|
|
<label> |
|
206
|
|
|
<input type="checkbox" name="supports_discounts" id="field_supports_discounts" value="1" <?php checked( $values['supports_discounts'], 1 ); ?>> |
|
207
|
|
|
<span><?php _e( 'Enable coupon codes', 'invoicing' ); ?></span> |
|
208
|
|
|
</label> |
|
209
|
|
|
</div> |
|
210
|
|
|
</td> |
|
211
|
|
|
</tr> |
|
212
|
|
|
|
|
213
|
|
|
<tr class="form-field-success_page"> |
|
214
|
|
|
<th scope="row"><label for="field_success_page"><?php _e( 'Success Page', 'invoicing' ); ?></label></th> |
|
215
|
|
|
<td> |
|
216
|
|
|
<div> |
|
217
|
|
|
<input type="text" class="regular-text" name="success_page" id="field_success_page" value="<?php echo esc_attr( $values['success_page'] ); ?>"> |
|
|
|
|
|
|
218
|
|
|
<p class="description"><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></p> |
|
219
|
|
|
</div> |
|
220
|
|
|
</td> |
|
221
|
|
|
</tr> |
|
222
|
|
|
|
|
223
|
|
|
<tr class="form-field-button_text"> |
|
224
|
|
|
<th scope="row"><label for="field_button_text"><?php _e( 'Button Text', 'invoicing' ); ?></label></th> |
|
225
|
|
|
<td> |
|
226
|
|
|
<div> |
|
227
|
|
|
<input type="text" class="regular-text" name="button_text" id="field_button_text" value="<?php echo esc_attr( $values['button_text'] ); ?>"> |
|
228
|
|
|
<p class="description"><?php _e( 'Payment button text', 'invoicing' ); ?></p> |
|
229
|
|
|
</div> |
|
230
|
|
|
</td> |
|
231
|
|
|
</tr> |
|
232
|
|
|
|
|
233
|
|
|
<tr class="form-field-processing_text"> |
|
234
|
|
|
<th scope="row"><label for="field_processing_text"><?php _e( 'Processing Text', 'invoicing' ); ?></label></th> |
|
235
|
|
|
<td> |
|
236
|
|
|
<div> |
|
237
|
|
|
<input type="text" class="regular-text" name="processing_text" id="field_processing_text" value="<?php echo esc_attr( $values['processing_text'] ); ?>"> |
|
238
|
|
|
<p class="description"><?php _e( 'Processing payment button text', 'invoicing' ); ?></p> |
|
239
|
|
|
</div> |
|
240
|
|
|
</td> |
|
241
|
|
|
</tr> |
|
242
|
|
|
|
|
243
|
|
|
</tbody> |
|
244
|
|
|
</table> |
|
245
|
|
|
</div> |
|
246
|
|
|
<?php |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public static function save( $post_id, $data, $post ) { |
|
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|