| Total Complexity | 167 |
| Total Lines | 2280 |
| Duplicated Lines | 0 % |
| Changes | 19 | ||
| Bugs | 0 | Features | 2 |
Complex classes like WPInv_Payment_Form_Elements often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WPInv_Payment_Form_Elements, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class WPInv_Payment_Form_Elements { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @param array payment form elements |
||
| 11 | */ |
||
| 12 | protected $elements; |
||
| 13 | |||
| 14 | public function __construct() { |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | } |
||
| 29 | |||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns all the elements that can be added to a form. |
||
| 34 | */ |
||
| 35 | public function get_elements() { |
||
| 36 | |||
| 37 | if ( ! empty( $this->elements ) ) { |
||
| 38 | return $this->elements; |
||
| 39 | } |
||
| 40 | |||
| 41 | $this->elements = wpinv_get_data( 'payment-form-elements' ); |
||
| 42 | |||
| 43 | $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements ); |
||
| 44 | return $this->elements; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns the restrict markup. |
||
| 49 | */ |
||
| 50 | public function get_restrict_markup( $field, $field_type ) { |
||
| 51 | $restrict = "$field.type=='$field_type'"; |
||
| 52 | return "v-if=\"$restrict\""; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Renders the title element template. |
||
| 57 | */ |
||
| 58 | public function render_heading_template( $field ) { |
||
| 59 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
| 60 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Renders the edit title element template. |
||
| 65 | */ |
||
| 66 | public function edit_heading_template( $field ) { |
||
| 67 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
| 68 | $label = __( 'Heading', 'invoicing' ); |
||
| 69 | $label2 = __( 'Select Heading Level', 'invoicing' ); |
||
| 70 | $id = $field . '.id + "_edit"'; |
||
| 71 | $id2 = $field . '.id + "_edit2"'; |
||
| 72 | |||
| 73 | echo " |
||
| 74 | <div $restrict> |
||
| 75 | <div class='form-group'> |
||
| 76 | <label :for='$id'>$label</label> |
||
| 77 | <input class='form-control' :id='$id' v-model='$field.text' type='text' /> |
||
| 78 | </div> |
||
| 79 | |||
| 80 | <div class='form-group'> |
||
| 81 | <label :for='$id2'>$label2</label> |
||
| 82 | |||
| 83 | <select class='form-control custom-select' :id='$id2' v-model='$field.level'> |
||
| 84 | <option value='h1'>H1</option> |
||
| 85 | <option value='h2'>H2</option> |
||
| 86 | <option value='h3'>H3</option> |
||
| 87 | <option value='h4'>H4</option> |
||
| 88 | <option value='h5'>H5</option> |
||
| 89 | <option value='h6'>H6</option> |
||
| 90 | <option value='h7'>H7</option> |
||
| 91 | </select> |
||
| 92 | </div> |
||
| 93 | </div> |
||
| 94 | "; |
||
| 95 | |||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Renders a paragraph element template. |
||
| 100 | */ |
||
| 101 | public function render_paragraph_template( $field ) { |
||
| 102 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
| 103 | $label = "$field.text"; |
||
| 104 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Renders the edit paragraph element template. |
||
| 109 | */ |
||
| 110 | public function edit_paragraph_template( $field ) { |
||
| 111 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
| 112 | $label = __( 'Enter your text', 'invoicing' ); |
||
| 113 | $id = $field . '.id + "_edit"'; |
||
| 114 | echo " |
||
| 115 | <div $restrict> |
||
| 116 | <div class='form-group'> |
||
| 117 | <label :for='$id'>$label</label> |
||
| 118 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
| 119 | </div> |
||
| 120 | </div> |
||
| 121 | "; |
||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Renders the text element template. |
||
| 127 | */ |
||
| 128 | public function render_text_template( $field ) { |
||
| 129 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
| 130 | $label = "$field.label"; |
||
| 131 | echo " |
||
| 132 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 133 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 134 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 135 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'> |
||
| 136 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 137 | </div> |
||
| 138 | "; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Renders the edit text element template. |
||
| 143 | */ |
||
| 144 | public function edit_text_template( $field ) { |
||
| 145 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
| 146 | $label = __( 'Field Label', 'invoicing' ); |
||
| 147 | $id = $field . '.id + "_edit"'; |
||
| 148 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 149 | $id2 = $field . '.id + "_edit2"'; |
||
| 150 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 151 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 152 | $id3 = $field . '.id + "_edit3"'; |
||
| 153 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 154 | $id4 = $field . '.id + "_edit4"'; |
||
| 155 | echo " |
||
| 156 | <div $restrict> |
||
| 157 | <div class='form-group'> |
||
| 158 | <label :for='$id'>$label</label> |
||
| 159 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 160 | </div> |
||
| 161 | <div class='form-group'> |
||
| 162 | <label :for='$id2'>$label2</label> |
||
| 163 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 164 | </div> |
||
| 165 | <div class='form-group'> |
||
| 166 | <label :for='$id3'>$label3</label> |
||
| 167 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 168 | </div> |
||
| 169 | <div class='form-group form-check'> |
||
| 170 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 171 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 172 | </div> |
||
| 173 | </div> |
||
| 174 | "; |
||
| 175 | |||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Renders the textarea element template. |
||
| 180 | */ |
||
| 181 | public function render_textarea_template( $field ) { |
||
| 182 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
| 183 | $label = "$field.label"; |
||
| 184 | echo " |
||
| 185 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 186 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 187 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 188 | <textarea :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea> |
||
| 189 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 190 | </div> |
||
| 191 | "; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Renders the edit textarea element template. |
||
| 196 | */ |
||
| 197 | public function edit_textarea_template( $field ) { |
||
| 198 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
| 199 | $label = __( 'Field Label', 'invoicing' ); |
||
| 200 | $id = $field . '.id + "_edit"'; |
||
| 201 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 202 | $id2 = $field . '.id + "_edit2"'; |
||
| 203 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 204 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 205 | $id3 = $field . '.id + "_edit3"'; |
||
| 206 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 207 | $id4 = $field . '.id + "_edit4"'; |
||
| 208 | echo " |
||
| 209 | <div $restrict> |
||
| 210 | <div class='form-group'> |
||
| 211 | <label :for='$id'>$label</label> |
||
| 212 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 213 | </div> |
||
| 214 | <div class='form-group'> |
||
| 215 | <label :for='$id2'>$label2</label> |
||
| 216 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 217 | </div> |
||
| 218 | <div class='form-group'> |
||
| 219 | <label :for='$id3'>$label3</label> |
||
| 220 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 221 | </div> |
||
| 222 | <div class='form-group form-check'> |
||
| 223 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 224 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 225 | </div> |
||
| 226 | </div> |
||
| 227 | "; |
||
| 228 | |||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Renders the select element template. |
||
| 233 | */ |
||
| 234 | public function render_select_template( $field ) { |
||
| 235 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
| 236 | $label = "$field.label"; |
||
| 237 | $placeholder = "$field.placeholder"; |
||
| 238 | $id = $field . '.id'; |
||
| 239 | echo " |
||
| 240 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 241 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 242 | <label :for='$id'>{{" . $label . "}}</label> |
||
| 243 | <select id='$id' class='form-control custom-select' v-model='$field.value'> |
||
| 244 | <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option> |
||
| 245 | <option v-for='option in $field.options' value='option'>{{option}}</option> |
||
| 246 | </select> |
||
| 247 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 248 | </div> |
||
| 249 | "; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Renders the edit select element template. |
||
| 254 | */ |
||
| 255 | public function edit_select_template( $field ) { |
||
| 256 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
| 257 | $label = __( 'Field Label', 'invoicing' ); |
||
| 258 | $id = $field . '.id + "_edit"'; |
||
| 259 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 260 | $id2 = $field . '.id + "_edit2"'; |
||
| 261 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 262 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 263 | $id3 = $field . '.id + "_edit3"'; |
||
| 264 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 265 | $id4 = $field . '.id + "_edit4"'; |
||
| 266 | $label6 = __( 'Available Options', 'invoicing' ); |
||
| 267 | echo " |
||
| 268 | <div $restrict> |
||
| 269 | <div class='form-group'> |
||
| 270 | <label :for='$id'>$label</label> |
||
| 271 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 272 | </div> |
||
| 273 | <div class='form-group'> |
||
| 274 | <label :for='$id2'>$label2</label> |
||
| 275 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 276 | </div> |
||
| 277 | <div class='form-group'> |
||
| 278 | <label :for='$id3'>$label3</label> |
||
| 279 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 280 | </div> |
||
| 281 | <div class='form-group form-check'> |
||
| 282 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 283 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 284 | </div> |
||
| 285 | <hr class='featurette-divider mt-4'> |
||
| 286 | <h5>$label6</h5> |
||
| 287 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
| 288 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
| 289 | <div class='input-group-append'> |
||
| 290 | <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
| 291 | </div> |
||
| 292 | </div> |
||
| 293 | <div class='form-group'> |
||
| 294 | <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
| 295 | </div> |
||
| 296 | </div> |
||
| 297 | "; |
||
| 298 | |||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Renders the checkbox element template. |
||
| 303 | */ |
||
| 304 | public function render_checkbox_template( $field ) { |
||
| 305 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
| 306 | echo " |
||
| 307 | <div class='form-check' $restrict> |
||
| 308 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 309 | <input :id='$field.id' class='form-check-input' type='checkbox' /> |
||
| 310 | <label class='form-check-label' :for='$field.id' v-html='$field.label'></label> |
||
| 311 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 312 | </div> |
||
| 313 | "; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Renders the edit checkbox element template. |
||
| 318 | */ |
||
| 319 | public function edit_checkbox_template( $field ) { |
||
| 320 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
| 321 | $label = __( 'Field Label', 'invoicing' ); |
||
| 322 | $id = $field . '.id + "_edit"'; |
||
| 323 | $label2 = __( 'Help text', 'invoicing' ); |
||
| 324 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 325 | $id2 = $field . '.id + "_edit2"'; |
||
| 326 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
| 327 | $id3 = $field . '.id + "_edit3"'; |
||
| 328 | echo " |
||
| 329 | <div $restrict> |
||
| 330 | <div class='form-group'> |
||
| 331 | <label :for='$id'>$label</label> |
||
| 332 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 333 | </div> |
||
| 334 | <div class='form-group'> |
||
| 335 | <label :for='$id2'>$label2</label> |
||
| 336 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 337 | </div> |
||
| 338 | <div class='form-group form-check'> |
||
| 339 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 340 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
| 341 | </div> |
||
| 342 | </div> |
||
| 343 | "; |
||
| 344 | |||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Renders the radio element template. |
||
| 349 | */ |
||
| 350 | public function render_radio_template( $field ) { |
||
| 351 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
| 352 | $label = "$field.label"; |
||
| 353 | $id = $field . '.id'; |
||
| 354 | echo " |
||
| 355 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 356 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 357 | <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend> |
||
| 358 | <div class='form-check' v-for='(option, index) in $field.options'> |
||
| 359 | <input class='form-check-input' type='radio' :id='$id + index'> |
||
| 360 | <label class='form-check-label' :for='$id + index'>{{option}}</label> |
||
| 361 | </div> |
||
| 362 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 363 | </div> |
||
| 364 | "; |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Renders the edit radio element template. |
||
| 369 | */ |
||
| 370 | public function edit_radio_template( $field ) { |
||
| 371 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
| 372 | $label = __( 'Field Label', 'invoicing' ); |
||
| 373 | $id = $field . '.id + "_edit"'; |
||
| 374 | $label2 = __( 'Help text', 'invoicing' ); |
||
| 375 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 376 | $id2 = $field . '.id + "_edit3"'; |
||
| 377 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
| 378 | $id3 = $field . '.id + "_edit4"'; |
||
| 379 | $label5 = __( 'Available Options', 'invoicing' ); |
||
| 380 | echo " |
||
| 381 | <div $restrict> |
||
| 382 | <div class='form-group'> |
||
| 383 | <label :for='$id'>$label</label> |
||
| 384 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 385 | </div> |
||
| 386 | <div class='form-group'> |
||
| 387 | <label :for='$id2'>$label2</label> |
||
| 388 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 389 | </div> |
||
| 390 | <div class='form-group form-check'> |
||
| 391 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 392 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
| 393 | </div> |
||
| 394 | <hr class='featurette-divider mt-4'> |
||
| 395 | <h5>$label5</h5> |
||
| 396 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
| 397 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
| 398 | <div class='input-group-append'> |
||
| 399 | <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
| 400 | </div> |
||
| 401 | </div> |
||
| 402 | <div class='form-group'> |
||
| 403 | <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
| 404 | </div> |
||
| 405 | </div> |
||
| 406 | "; |
||
| 407 | |||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Renders the address element template. |
||
| 412 | */ |
||
| 413 | public function render_address_template( $field ) { |
||
| 414 | $restrict = $this->get_restrict_markup( $field, 'address' ); |
||
| 415 | |||
| 416 | echo " |
||
| 417 | <div class='wpinv-address-wrapper' $restrict> |
||
| 418 | <draggable v-model='$field.fields' group='address_fields_preview'> |
||
| 419 | <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'> |
||
| 420 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 421 | <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label> |
||
| 422 | <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'> |
||
| 423 | <select v-else class='form-control' :id='field.name'> |
||
| 424 | <option v-if='field.placeholder'>{{field.placeholder}}</option> |
||
| 425 | </select> |
||
| 426 | <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small> |
||
| 427 | </div> |
||
| 428 | </draggable> |
||
| 429 | </div> |
||
| 430 | "; |
||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Renders the edit address element template. |
||
| 435 | */ |
||
| 436 | public function edit_address_template( $field ) { |
||
| 437 | $restrict = $this->get_restrict_markup( $field, 'address' ); |
||
| 438 | $label = __( 'Field Label', 'invoicing' ); |
||
| 439 | $label2 = __( 'Placeholder', 'invoicing' ); |
||
| 440 | $label3 = __( 'Description', 'invoicing' ); |
||
| 441 | $label4 = __( 'Is required', 'invoicing' ); |
||
| 442 | $label5 = __( 'Is visible', 'invoicing' ); |
||
| 443 | $id = $field . '.id + "_edit_label"'; |
||
| 444 | $id2 = $field . '.id + "_edit_placeholder"'; |
||
| 445 | $id3 = $field . '.id + "_edit_description"'; |
||
| 446 | $id4 = $field . '.id + "_edit_required"'; |
||
| 447 | $id5 = $field . '.id + "_edit_visible"'; |
||
|
|
|||
| 448 | $id5 = $field . '.id + "_edit_visible"'; |
||
| 449 | $id_main = $field . '.id'; |
||
| 450 | |||
| 451 | echo " |
||
| 452 | <div $restrict :id='$id_main'> |
||
| 453 | <draggable v-model='$field.fields' group='address_fields'> |
||
| 454 | <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'> |
||
| 455 | |||
| 456 | <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'> |
||
| 457 | <span class='label'>{{field.label}}</span> |
||
| 458 | <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'> |
||
| 459 | <span class='dashicons dashicons-hidden'></span> |
||
| 460 | <span class='dashicons dashicons-visibility'></span> |
||
| 461 | </span> |
||
| 462 | <span class='toggle-icon'> |
||
| 463 | <span class='dashicons dashicons-arrow-down'></span> |
||
| 464 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
| 465 | </span> |
||
| 466 | </div> |
||
| 467 | |||
| 468 | <div class='wpinv-form-address-field-editor-editor-body'> |
||
| 469 | <div class='p-2'> |
||
| 470 | |||
| 471 | <div class='form-group'> |
||
| 472 | <label :for='$id + index'>$label</label> |
||
| 473 | <input :id='$id + index' v-model='field.label' class='form-control' /> |
||
| 474 | </div> |
||
| 475 | |||
| 476 | <div class='form-group'> |
||
| 477 | <label :for='$id2 + index'>$label2</label> |
||
| 478 | <input :id='$id2 + index' v-model='field.placeholder' class='form-control' /> |
||
| 479 | </div> |
||
| 480 | |||
| 481 | <div class='form-group'> |
||
| 482 | <label :for='$id3 + index'>$label3</label> |
||
| 483 | <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea> |
||
| 484 | </div> |
||
| 485 | |||
| 486 | <div class='form-group form-check'> |
||
| 487 | <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' /> |
||
| 488 | <label class='form-check-label' :for='$id4 + index'>$label4</label> |
||
| 489 | </div> |
||
| 490 | |||
| 491 | <div class='form-group form-check'> |
||
| 492 | <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' /> |
||
| 493 | <label class='form-check-label' :for='$id5 + index'>$label5</label> |
||
| 494 | </div> |
||
| 495 | |||
| 496 | </div> |
||
| 497 | </div> |
||
| 498 | |||
| 499 | </div> |
||
| 500 | </draggable> |
||
| 501 | |||
| 502 | </div> |
||
| 503 | "; |
||
| 504 | |||
| 505 | } |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Renders the email element template. |
||
| 509 | */ |
||
| 510 | public function render_email_template( $field ) { |
||
| 511 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
| 512 | $label = "$field.label"; |
||
| 513 | echo " |
||
| 514 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 515 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 516 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 517 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
| 518 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 519 | </div> |
||
| 520 | "; |
||
| 521 | } |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Renders the billing_email element template. |
||
| 525 | */ |
||
| 526 | public function render_billing_email_template( $field ) { |
||
| 527 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
| 528 | $label = "$field.label"; |
||
| 529 | echo " |
||
| 530 | <div $restrict> |
||
| 531 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 532 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
| 533 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 534 | </div> |
||
| 535 | "; |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Renders the edit email element template. |
||
| 540 | */ |
||
| 541 | public function edit_email_template( $field ) { |
||
| 542 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
| 543 | $label = __( 'Field Label', 'invoicing' ); |
||
| 544 | $id = $field . '.id + "_edit"'; |
||
| 545 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 546 | $id2 = $field . '.id + "_edit2"'; |
||
| 547 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 548 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 549 | $id3 = $field . '.id + "_edit3"'; |
||
| 550 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 551 | $id4 = $field . '.id + "_edit4"'; |
||
| 552 | echo " |
||
| 553 | <div $restrict> |
||
| 554 | <div class='form-group'> |
||
| 555 | <label :for='$id'>$label</label> |
||
| 556 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 557 | </div> |
||
| 558 | <div class='form-group'> |
||
| 559 | <label :for='$id2'>$label2</label> |
||
| 560 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 561 | </div> |
||
| 562 | <div class='form-group'> |
||
| 563 | <label :for='$id3'>$label3</label> |
||
| 564 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 565 | </div> |
||
| 566 | <div class='form-group form-check'> |
||
| 567 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 568 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 569 | </div> |
||
| 570 | </div> |
||
| 571 | "; |
||
| 572 | |||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Renders the edit billing_email element template. |
||
| 577 | */ |
||
| 578 | public function edit_billing_email_template( $field ) { |
||
| 579 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
| 580 | $label = __( 'Field Label', 'invoicing' ); |
||
| 581 | $id = $field . '.id + "_edit"'; |
||
| 582 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 583 | $id2 = $field . '.id + "_edit2"'; |
||
| 584 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 585 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 586 | $id3 = $field . '.id + "_edit3"'; |
||
| 587 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 588 | $id4 = $field . '.id + "_edit4"'; |
||
| 589 | echo " |
||
| 590 | <div $restrict> |
||
| 591 | <div class='form-group'> |
||
| 592 | <label :for='$id'>$label</label> |
||
| 593 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 594 | </div> |
||
| 595 | <div class='form-group'> |
||
| 596 | <label :for='$id2'>$label2</label> |
||
| 597 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 598 | </div> |
||
| 599 | <div class='form-group'> |
||
| 600 | <label :for='$id3'>$label3</label> |
||
| 601 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 602 | </div> |
||
| 603 | </div> |
||
| 604 | "; |
||
| 605 | |||
| 606 | } |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Renders the website element template. |
||
| 610 | */ |
||
| 611 | public function render_website_template( $field ) { |
||
| 612 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
| 613 | $label = "$field.label"; |
||
| 614 | echo " |
||
| 615 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 616 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 617 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 618 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'> |
||
| 619 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 620 | </div> |
||
| 621 | "; |
||
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Renders the edit website element template. |
||
| 626 | */ |
||
| 627 | public function edit_website_template( $field ) { |
||
| 628 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
| 629 | $label = __( 'Field Label', 'invoicing' ); |
||
| 630 | $id = $field . '.id + "_edit"'; |
||
| 631 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 632 | $id2 = $field . '.id + "_edit2"'; |
||
| 633 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 634 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 635 | $id3 = $field . '.id + "_edit3"'; |
||
| 636 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 637 | $id4 = $field . '.id + "_edit4"'; |
||
| 638 | echo " |
||
| 639 | <div $restrict> |
||
| 640 | <div class='form-group'> |
||
| 641 | <label :for='$id'>$label</label> |
||
| 642 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 643 | </div> |
||
| 644 | <div class='form-group'> |
||
| 645 | <label :for='$id2'>$label2</label> |
||
| 646 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 647 | </div> |
||
| 648 | <div class='form-group'> |
||
| 649 | <label :for='$id3'>$label3</label> |
||
| 650 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 651 | </div> |
||
| 652 | <div class='form-group form-check'> |
||
| 653 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 654 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 655 | </div> |
||
| 656 | </div> |
||
| 657 | "; |
||
| 658 | |||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Renders the date element template. |
||
| 663 | */ |
||
| 664 | public function render_date_template( $field ) { |
||
| 665 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
| 666 | $label = "$field.label"; |
||
| 667 | echo " |
||
| 668 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 669 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 670 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 671 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'> |
||
| 672 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 673 | </div> |
||
| 674 | "; |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Renders the edit date element template. |
||
| 679 | */ |
||
| 680 | public function edit_date_template( $field ) { |
||
| 681 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
| 682 | $label = __( 'Field Label', 'invoicing' ); |
||
| 683 | $id = $field . '.id + "_edit"'; |
||
| 684 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 685 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 686 | $id3 = $field . '.id + "_edit3"'; |
||
| 687 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 688 | $id4 = $field . '.id + "_edit4"'; |
||
| 689 | echo " |
||
| 690 | <div $restrict> |
||
| 691 | <div class='form-group'> |
||
| 692 | <label :for='$id'>$label</label> |
||
| 693 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 694 | </div> |
||
| 695 | <div class='form-group'> |
||
| 696 | <label :for='$id3'>$label3</label> |
||
| 697 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 698 | </div> |
||
| 699 | <div class='form-group form-check'> |
||
| 700 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 701 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 702 | </div> |
||
| 703 | </div> |
||
| 704 | "; |
||
| 705 | |||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Renders the time element template. |
||
| 710 | */ |
||
| 711 | public function render_time_template( $field ) { |
||
| 712 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
| 713 | $label = "$field.label"; |
||
| 714 | echo " |
||
| 715 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 716 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 717 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 718 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'> |
||
| 719 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 720 | </div> |
||
| 721 | "; |
||
| 722 | } |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Renders the edit time element template. |
||
| 726 | */ |
||
| 727 | public function edit_time_template( $field ) { |
||
| 728 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
| 729 | $label = __( 'Field Label', 'invoicing' ); |
||
| 730 | $id = $field . '.id + "_edit"'; |
||
| 731 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 732 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 733 | $id3 = $field . '.id + "_edit3"'; |
||
| 734 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 735 | $id4 = $field . '.id + "_edit4"'; |
||
| 736 | echo " |
||
| 737 | <div $restrict> |
||
| 738 | <div class='form-group'> |
||
| 739 | <label :for='$id'>$label</label> |
||
| 740 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 741 | </div> |
||
| 742 | <div class='form-group'> |
||
| 743 | <label :for='$id3'>$label3</label> |
||
| 744 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 745 | </div> |
||
| 746 | <div class='form-group form-check'> |
||
| 747 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 748 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 749 | </div> |
||
| 750 | </div> |
||
| 751 | "; |
||
| 752 | |||
| 753 | } |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Renders the number element template. |
||
| 757 | */ |
||
| 758 | public function render_number_template( $field ) { |
||
| 759 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
| 760 | $label = "$field.label"; |
||
| 761 | echo " |
||
| 762 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 763 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 764 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 765 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'> |
||
| 766 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 767 | </div> |
||
| 768 | "; |
||
| 769 | } |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Renders the edit number element template. |
||
| 773 | */ |
||
| 774 | public function edit_number_template( $field ) { |
||
| 775 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
| 776 | $label = __( 'Field Label', 'invoicing' ); |
||
| 777 | $id = $field . '.id + "_edit"'; |
||
| 778 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 779 | $id2 = $field . '.id + "_edit2"'; |
||
| 780 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 781 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 782 | $id3 = $field . '.id + "_edit3"'; |
||
| 783 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 784 | $id4 = $field . '.id + "_edit4"'; |
||
| 785 | echo " |
||
| 786 | <div $restrict> |
||
| 787 | <div class='form-group'> |
||
| 788 | <label :for='$id'>$label</label> |
||
| 789 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 790 | </div> |
||
| 791 | <div class='form-group'> |
||
| 792 | <label :for='$id2'>$label2</label> |
||
| 793 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 794 | </div> |
||
| 795 | <div class='form-group'> |
||
| 796 | <label :for='$id3'>$label3</label> |
||
| 797 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 798 | </div> |
||
| 799 | <div class='form-group form-check'> |
||
| 800 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 801 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 802 | </div> |
||
| 803 | </div> |
||
| 804 | "; |
||
| 805 | |||
| 806 | } |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Renders the separator element template. |
||
| 810 | */ |
||
| 811 | public function render_separator_template( $field ) { |
||
| 812 | $restrict = $this->get_restrict_markup( $field, 'separator' ); |
||
| 813 | echo "<hr class='featurette-divider' $restrict>"; |
||
| 814 | } |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Renders the pay button element template. |
||
| 818 | */ |
||
| 819 | public function render_pay_button_template( $field ) { |
||
| 820 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
| 821 | $label = "$field.label"; |
||
| 822 | echo " |
||
| 823 | <div $restrict> |
||
| 824 | <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button> |
||
| 825 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 826 | </div> |
||
| 827 | "; |
||
| 828 | } |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Renders the pay button element template. |
||
| 832 | */ |
||
| 833 | public function edit_pay_button_template( $field ) { |
||
| 834 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
| 835 | $label = __( 'Button Text', 'invoicing' ); |
||
| 836 | $id = $field . '.id + "_edit"'; |
||
| 837 | $label2 = __( 'Help text', 'invoicing' ); |
||
| 838 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 839 | $id2 = $field . '.id + "_edit2"'; |
||
| 840 | $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
||
| 841 | $id3 = $field . '.id + "_edit3"'; |
||
| 842 | echo " |
||
| 843 | <div $restrict> |
||
| 844 | <div class='form-group'> |
||
| 845 | <label :for='$id'>$label</label> |
||
| 846 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 847 | </div> |
||
| 848 | <div class='form-group'> |
||
| 849 | <label :for='$id2'>$label2</label> |
||
| 850 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 851 | </div> |
||
| 852 | <div class='form-group'> |
||
| 853 | <label :for='$id3'>$label4</label> |
||
| 854 | |||
| 855 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
| 856 | <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
| 857 | <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
| 858 | <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
| 859 | <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
| 860 | <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
| 861 | <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
| 862 | <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
| 863 | <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
| 864 | <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
||
| 865 | </select> |
||
| 866 | </div> |
||
| 867 | </div> |
||
| 868 | "; |
||
| 869 | |||
| 870 | } |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Renders the alert element template. |
||
| 874 | */ |
||
| 875 | public function render_alert_template( $field ) { |
||
| 876 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
| 877 | $text = "$field.text"; |
||
| 878 | echo " |
||
| 879 | <div $restrict class='alert' :class='$field.class' role='alert'> |
||
| 880 | <span v-html='$text'></span> |
||
| 881 | <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''> |
||
| 882 | <span aria-hidden='true'>×</span> |
||
| 883 | </button> |
||
| 884 | </div> |
||
| 885 | "; |
||
| 886 | } |
||
| 887 | |||
| 888 | /** |
||
| 889 | * Renders the alert element template. |
||
| 890 | */ |
||
| 891 | public function edit_alert_template( $field ) { |
||
| 892 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
| 893 | $label = __( 'Alert Text', 'invoicing' ); |
||
| 894 | $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
||
| 895 | $id = $field . '.id + "_edit"'; |
||
| 896 | $label3 = __( 'Is Dismissible?', 'invoicing' ); |
||
| 897 | $id2 = $field . '.id + "_edit2"'; |
||
| 898 | $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
||
| 899 | $id3 = $field . '.id + "_edit3"'; |
||
| 900 | echo " |
||
| 901 | <div $restrict> |
||
| 902 | <div class='form-group'> |
||
| 903 | <label :for='$id'>$label</label> |
||
| 904 | <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
| 905 | </div> |
||
| 906 | <div class='form-group form-check'> |
||
| 907 | <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' /> |
||
| 908 | <label class='form-check-label' :for='$id2'>$label3</label> |
||
| 909 | </div> |
||
| 910 | <div class='form-group'> |
||
| 911 | <label :for='$id3'>$label4</label> |
||
| 912 | |||
| 913 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
| 914 | <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
| 915 | <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
| 916 | <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
| 917 | <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
| 918 | <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
| 919 | <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
| 920 | <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
| 921 | <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
| 922 | </select> |
||
| 923 | </div> |
||
| 924 | </div> |
||
| 925 | "; |
||
| 926 | |||
| 927 | } |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Renders the discount element template. |
||
| 931 | */ |
||
| 932 | public function render_discount_template( $field ) { |
||
| 933 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
| 934 | ?> |
||
| 935 | |||
| 936 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview"> |
||
| 937 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 938 | <div class="discount_field_inner d-flex flex-column flex-md-row"> |
||
| 939 | <input :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text"> |
||
| 940 | <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button> |
||
| 941 | </div> |
||
| 942 | <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small> |
||
| 943 | </div> |
||
| 944 | |||
| 945 | <?php |
||
| 946 | } |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Renders the discount element template. |
||
| 950 | */ |
||
| 951 | public function edit_discount_template( $field ) { |
||
| 952 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
| 953 | $label = __( 'Discount Input Placeholder', 'invoicing' ); |
||
| 954 | $label2 = __( 'Help Text', 'invoicing' ); |
||
| 955 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 956 | $label4 = __( 'Button Text', 'invoicing' ); |
||
| 957 | $id = $field . '.id + "_edit"'; |
||
| 958 | $id2 = $field . '.id + "_edit2"'; |
||
| 959 | $id3 = $field . '.id + "_edit3"'; |
||
| 960 | echo " |
||
| 961 | <div $restrict> |
||
| 962 | <div class='form-group'> |
||
| 963 | <label :for='$id'>$label</label> |
||
| 964 | <input :id='$id' v-model='$field.input_label' class='form-control' /> |
||
| 965 | </div> |
||
| 966 | |||
| 967 | <div class='form-group'> |
||
| 968 | <label :for='$id2'>$label4</label> |
||
| 969 | <input :id='$id2' v-model='$field.button_label' class='form-control' /> |
||
| 970 | </div> |
||
| 971 | |||
| 972 | <div class='form-group'> |
||
| 973 | <label :for='$id3'>$label2</label> |
||
| 974 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 975 | </div> |
||
| 976 | |||
| 977 | </div> |
||
| 978 | "; |
||
| 979 | |||
| 980 | } |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Renders the items element template. |
||
| 984 | */ |
||
| 985 | public function render_items_template( $field ) { |
||
| 986 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
| 987 | ?> |
||
| 988 | |||
| 989 | <div <?php echo $restrict; ?> class='item_totals text-center'> |
||
| 990 | <div v-if='!is_default'> |
||
| 991 | <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='p-4 bg-warning text-light'><?php _e( 'Item totals will appear here. Click to set items.', 'invoicing' ) ?></div> |
||
| 992 | <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='p-4 bg-danger'><?php _e( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' ); _e( 'To prevent this, limit customers to selecting a single item.', 'invoicing' ); ?></div> |
||
| 993 | </div> |
||
| 994 | <div v-if='is_default'> |
||
| 995 | <div class='p-4 bg-warning'><?php _e( 'Item totals will appear here.', 'invoicing' ) ?></div> |
||
| 996 | </div> |
||
| 997 | </div> |
||
| 998 | |||
| 999 | <?php |
||
| 1000 | } |
||
| 1001 | |||
| 1002 | /** |
||
| 1003 | * Renders the items element on the frontend. |
||
| 1004 | */ |
||
| 1005 | public function frontend_render_items_template( $field, $items ) { |
||
| 1006 | $tax = 0; |
||
| 1007 | $sub_total = 0; |
||
| 1008 | $total = 0; |
||
| 1009 | |||
| 1010 | ?> |
||
| 1011 | <div class="border item_totals_type_total"> |
||
| 1012 | <?php |
||
| 1013 | foreach( $items as $item ) { |
||
| 1014 | $amount = floatval( $item['price'] ); |
||
| 1015 | |||
| 1016 | // Include the tax. |
||
| 1017 | if ( wpinv_use_taxes() ) { |
||
| 1018 | $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
||
| 1019 | |||
| 1020 | if ( wpinv_prices_include_tax() ) { |
||
| 1021 | $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
||
| 1022 | $item_tax = $amount - $pre_tax; |
||
| 1023 | } else { |
||
| 1024 | $pre_tax = $amount; |
||
| 1025 | $item_tax = $amount * $rate * 0.01; |
||
| 1026 | } |
||
| 1027 | |||
| 1028 | $tax = $tax + $item_tax; |
||
| 1029 | $sub_total = $sub_total + $pre_tax; |
||
| 1030 | $total = $sub_total + $tax; |
||
| 1031 | |||
| 1032 | } else { |
||
| 1033 | $total = $total + $amount; |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | $class = 'col-8'; |
||
| 1037 | $class2 = ''; |
||
| 1038 | |||
| 1039 | if ( ! empty( $item['allow_quantities'] ) ) { |
||
| 1040 | $class = 'col-6 pt-2'; |
||
| 1041 | $class2 = 'pt-2'; |
||
| 1042 | } |
||
| 1043 | |||
| 1044 | if ( ! empty( $item['custom_price'] ) ) { |
||
| 1045 | $class .= ' pt-2'; |
||
| 1046 | } |
||
| 1047 | |||
| 1048 | $quantity = 1; |
||
| 1049 | if ( ! empty( $item['quantity'] ) ) { |
||
| 1050 | $quantity = absint( $item['quantity'] ); |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | ?> |
||
| 1054 | <div class="item_totals_item"> |
||
| 1055 | <div class='row pl-2 pr-2 pt-2'> |
||
| 1056 | <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
||
| 1057 | |||
| 1058 | <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
||
| 1059 | |||
| 1060 | <div class='col-2'> |
||
| 1061 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='<?php echo $quantity ?>' min='1' required> |
||
| 1062 | </div> |
||
| 1063 | |||
| 1064 | <?php } else { ?> |
||
| 1065 | <input type='hidden' class='wpinv-item-quantity-input' value='<?php echo $quantity ?>'> |
||
| 1066 | <?php } if ( empty( $item['custom_price'] ) ) { ?> |
||
| 1067 | |||
| 1068 | <div class='col-4 <?php echo $class2; ?>'> |
||
| 1069 | <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
||
| 1070 | <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
||
| 1071 | </div> |
||
| 1072 | |||
| 1073 | <?php } else {?> |
||
| 1074 | |||
| 1075 | <div class='col-4'> |
||
| 1076 | <div class='input-group'> |
||
| 1077 | |||
| 1078 | <?php if ( 'left' == wpinv_currency_position() ) { ?> |
||
| 1079 | <div class='input-group-prepend'> |
||
| 1080 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1081 | </div> |
||
| 1082 | <?php } ?> |
||
| 1083 | |||
| 1084 | <input type='text' 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'] ); ?>'> |
||
| 1085 | |||
| 1086 | <?php if ( 'left' != wpinv_currency_position() ) { ?> |
||
| 1087 | <div class='input-group-append'> |
||
| 1088 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1089 | </div> |
||
| 1090 | <?php } ?> |
||
| 1091 | |||
| 1092 | </div> |
||
| 1093 | </div> |
||
| 1094 | <?php } ?> |
||
| 1095 | |||
| 1096 | </div> |
||
| 1097 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1098 | <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1099 | <?php } ?> |
||
| 1100 | </div> |
||
| 1101 | <?php } ?> |
||
| 1102 | |||
| 1103 | <div class='mt-4 border-top item_totals_total p-2'> |
||
| 1104 | |||
| 1105 | <div class='row'> |
||
| 1106 | <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
||
| 1107 | <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
||
| 1108 | </div> |
||
| 1109 | |||
| 1110 | <div class='row' style='display: none;'> |
||
| 1111 | <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
||
| 1112 | <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
||
| 1113 | </div> |
||
| 1114 | |||
| 1115 | <?php if ( wpinv_use_taxes() ) { ?> |
||
| 1116 | <div class='row'> |
||
| 1117 | <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
||
| 1118 | <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
||
| 1119 | </div> |
||
| 1120 | <?php } ?> |
||
| 1121 | |||
| 1122 | <div class='row'> |
||
| 1123 | <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
||
| 1124 | <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> |
||
| 1125 | </div> |
||
| 1126 | |||
| 1127 | </div> |
||
| 1128 | |||
| 1129 | </div> |
||
| 1130 | <?php |
||
| 1131 | echo "<div class='form-group item_totals'>"; |
||
| 1132 | |||
| 1133 | $id = esc_attr( $field['id'] ); |
||
| 1134 | |||
| 1135 | if ( empty( $field[ 'items_type' ] ) ) { |
||
| 1136 | $field[ 'items_type' ] = 'total'; |
||
| 1137 | } |
||
| 1138 | |||
| 1139 | if ( 'total' == $field[ 'items_type' ] ) { |
||
| 1140 | $total = 0; |
||
| 1141 | $tax = 0; |
||
| 1142 | $sub_total = 0; |
||
| 1143 | |||
| 1144 | ?> |
||
| 1145 | <div class="border item_totals_type_total"> |
||
| 1146 | |||
| 1147 | <?php |
||
| 1148 | foreach( $items as $item ) { |
||
| 1149 | |||
| 1150 | $amount = floatval( $item['price'] ); |
||
| 1151 | |||
| 1152 | if ( wpinv_use_taxes() ) { |
||
| 1153 | |||
| 1154 | $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
||
| 1155 | |||
| 1156 | if ( wpinv_prices_include_tax() ) { |
||
| 1157 | $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
||
| 1158 | $item_tax = $amount - $pre_tax; |
||
| 1159 | } else { |
||
| 1160 | $pre_tax = $amount; |
||
| 1161 | $item_tax = $amount * $rate * 0.01; |
||
| 1162 | } |
||
| 1163 | |||
| 1164 | $tax = $tax + $item_tax; |
||
| 1165 | $sub_total = $sub_total + $pre_tax; |
||
| 1166 | $total = $sub_total + $tax; |
||
| 1167 | |||
| 1168 | } else { |
||
| 1169 | $total = $total + $amount; |
||
| 1170 | } |
||
| 1171 | |||
| 1172 | $class = 'col-8'; |
||
| 1173 | $class2 = ''; |
||
| 1174 | |||
| 1175 | if ( ! empty( $item['allow_quantities'] ) ) { |
||
| 1176 | $class = 'col-6 pt-2'; |
||
| 1177 | $class2 = 'pt-2'; |
||
| 1178 | } |
||
| 1179 | |||
| 1180 | if ( ! empty( $item['custom_price'] ) ) { |
||
| 1181 | $class .= ' pt-2'; |
||
| 1182 | } |
||
| 1183 | |||
| 1184 | $quantity = 1; |
||
| 1185 | if ( ! empty( $item['quantity'] ) ) { |
||
| 1186 | $quantity = absint( $item['quantity'] ); |
||
| 1187 | } |
||
| 1188 | |||
| 1189 | ?> |
||
| 1190 | <div class="item_totals_item"> |
||
| 1191 | <div class='row pl-2 pr-2 pt-2'> |
||
| 1192 | <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
||
| 1193 | |||
| 1194 | <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
||
| 1195 | |||
| 1196 | <div class='col-2'> |
||
| 1197 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='<?php echo $quantity ?>' min='1' required> |
||
| 1198 | </div> |
||
| 1199 | |||
| 1200 | <?php } else { ?> |
||
| 1201 | <input type='hidden' class='wpinv-item-quantity-input' value='<?php echo $quantity ?>'> |
||
| 1202 | <?php } if ( empty( $item['custom_price'] ) ) { ?> |
||
| 1203 | |||
| 1204 | <div class='col-4 <?php echo $class2; ?>'> |
||
| 1205 | <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
||
| 1206 | <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
||
| 1207 | </div> |
||
| 1208 | |||
| 1209 | <?php } else {?> |
||
| 1210 | |||
| 1211 | <div class='col-4'> |
||
| 1212 | <div class='input-group'> |
||
| 1213 | |||
| 1214 | <?php if ( 'left' == wpinv_currency_position() ) { ?> |
||
| 1215 | <div class='input-group-prepend'> |
||
| 1216 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1217 | </div> |
||
| 1218 | <?php } ?> |
||
| 1219 | |||
| 1220 | <input type='text' 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'] ); ?>'> |
||
| 1221 | |||
| 1222 | <?php if ( 'left' != wpinv_currency_position() ) { ?> |
||
| 1223 | <div class='input-group-append'> |
||
| 1224 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1225 | </div> |
||
| 1226 | <?php } ?> |
||
| 1227 | |||
| 1228 | </div> |
||
| 1229 | </div> |
||
| 1230 | <?php } ?> |
||
| 1231 | |||
| 1232 | </div> |
||
| 1233 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1234 | <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1235 | <?php } ?> |
||
| 1236 | </div> |
||
| 1237 | <?php } ?> |
||
| 1238 | |||
| 1239 | <div class='mt-4 border-top item_totals_total p-2'> |
||
| 1240 | |||
| 1241 | <div class='row'> |
||
| 1242 | <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
||
| 1243 | <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
||
| 1244 | </div> |
||
| 1245 | |||
| 1246 | <div class='row' style='display: none;'> |
||
| 1247 | <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
||
| 1248 | <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
||
| 1249 | </div> |
||
| 1250 | |||
| 1251 | <?php if ( wpinv_use_taxes() ) { ?> |
||
| 1252 | <div class='row'> |
||
| 1253 | <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
||
| 1254 | <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
||
| 1255 | </div> |
||
| 1256 | <?php } ?> |
||
| 1257 | |||
| 1258 | <div class='row'> |
||
| 1259 | <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
||
| 1260 | <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> |
||
| 1261 | </div> |
||
| 1262 | |||
| 1263 | </div> |
||
| 1264 | |||
| 1265 | </div> |
||
| 1266 | <?php } ?> |
||
| 1267 | |||
| 1268 | <?php if ( 'radio' == $field[ 'items_type' ] ) { ?> |
||
| 1269 | <div class="item_totals_type_radio"> |
||
| 1270 | |||
| 1271 | <?php |
||
| 1272 | foreach( $items as $index => $item ) { |
||
| 1273 | |||
| 1274 | if ( ! empty( $item['required'] ) ) { |
||
| 1275 | continue; |
||
| 1276 | } |
||
| 1277 | ?> |
||
| 1278 | <div class="form-check"> |
||
| 1279 | <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'> |
||
| 1280 | <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?> <strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); ?></strong></label> |
||
| 1281 | </div> |
||
| 1282 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1283 | <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1284 | <?php } ?> |
||
| 1285 | <?php } ?> |
||
| 1286 | |||
| 1287 | <div class="mt-3 border item_totals_type_radio_totals"> |
||
| 1288 | |||
| 1289 | <?php |
||
| 1290 | |||
| 1291 | $total = 0; |
||
| 1292 | $tax = 0; |
||
| 1293 | $sub_total = 0; |
||
| 1294 | |||
| 1295 | foreach ( $items as $item ) { |
||
| 1296 | |||
| 1297 | $class = 'col-8'; |
||
| 1298 | $class2 = ''; |
||
| 1299 | |||
| 1300 | if ( ! empty( $item['allow_quantities'] ) ) { |
||
| 1301 | $class = 'col-6 pt-2'; |
||
| 1302 | $class2 = 'pt-2'; |
||
| 1303 | } |
||
| 1304 | |||
| 1305 | if ( ! empty( $item['custom_price'] ) ) { |
||
| 1306 | $class .= ' pt-2'; |
||
| 1307 | } |
||
| 1308 | |||
| 1309 | $class3 = 'd-none'; |
||
| 1310 | $name = ''; |
||
| 1311 | if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) { |
||
| 1312 | |||
| 1313 | $amount = floatval( $item['price'] ); |
||
| 1314 | |||
| 1315 | if ( wpinv_use_taxes() ) { |
||
| 1316 | |||
| 1317 | $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
||
| 1318 | |||
| 1319 | if ( wpinv_prices_include_tax() ) { |
||
| 1320 | $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
||
| 1321 | $item_tax = $amount - $pre_tax; |
||
| 1322 | } else { |
||
| 1323 | $pre_tax = $amount; |
||
| 1324 | $item_tax = $amount * $rate * 0.01; |
||
| 1325 | } |
||
| 1326 | |||
| 1327 | $tax = $tax + $item_tax; |
||
| 1328 | $sub_total = $sub_total + $pre_tax; |
||
| 1329 | $total = $sub_total + $tax; |
||
| 1330 | |||
| 1331 | } else { |
||
| 1332 | $total = $total + $amount; |
||
| 1333 | } |
||
| 1334 | |||
| 1335 | $class3 = ''; |
||
| 1336 | $name = "wpinv-items[{$item['id']}]"; |
||
| 1337 | |||
| 1338 | if ( empty( $item['required'] ) ) { |
||
| 1339 | $totals_selected_radio_item = 1; |
||
| 1340 | } |
||
| 1341 | |||
| 1342 | } |
||
| 1343 | |||
| 1344 | $class3 .= " wpinv_item_{$item['id']}"; |
||
| 1345 | |||
| 1346 | ?> |
||
| 1347 | |||
| 1348 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
||
| 1349 | <div class='row pl-2 pr-2 pt-2'> |
||
| 1350 | <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
||
| 1351 | |||
| 1352 | <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
||
| 1353 | |||
| 1354 | <div class='col-2'> |
||
| 1355 | <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> |
||
| 1356 | </div> |
||
| 1357 | |||
| 1358 | <?php } else { ?> |
||
| 1359 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
||
| 1360 | <?php } if ( empty( $item['custom_price'] ) ) { ?> |
||
| 1361 | |||
| 1362 | <div class='col-4 <?php echo $class2; ?>'> |
||
| 1363 | <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
||
| 1364 | <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
||
| 1365 | </div> |
||
| 1366 | |||
| 1367 | <?php } else {?> |
||
| 1368 | |||
| 1369 | <div class='col-4'> |
||
| 1370 | <div class='input-group'> |
||
| 1371 | |||
| 1372 | <?php if ( 'left' == wpinv_currency_position() ) { ?> |
||
| 1373 | <div class='input-group-prepend'> |
||
| 1374 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1375 | </div> |
||
| 1376 | <?php } ?> |
||
| 1377 | |||
| 1378 | <input type='text' 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'] ); ?>'> |
||
| 1379 | |||
| 1380 | <?php if ( 'left' != wpinv_currency_position() ) { ?> |
||
| 1381 | <div class='input-group-append'> |
||
| 1382 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1383 | </div> |
||
| 1384 | <?php } ?> |
||
| 1385 | |||
| 1386 | </div> |
||
| 1387 | </div> |
||
| 1388 | <?php } ?> |
||
| 1389 | |||
| 1390 | </div> |
||
| 1391 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1392 | <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1393 | <?php } ?> |
||
| 1394 | </div> |
||
| 1395 | <?php } ?> |
||
| 1396 | |||
| 1397 | <div class='mt-4 border-top item_totals_total p-2'> |
||
| 1398 | |||
| 1399 | <div class='row'> |
||
| 1400 | <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
||
| 1401 | <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
||
| 1402 | </div> |
||
| 1403 | |||
| 1404 | <div class='row' style='display: none;'> |
||
| 1405 | <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
||
| 1406 | <div class='col-4'><strong class='wpinv-items-discount'></strong></div> |
||
| 1407 | </div> |
||
| 1408 | |||
| 1409 | <?php if ( wpinv_use_taxes() ) { ?> |
||
| 1410 | <div class='row'> |
||
| 1411 | <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
||
| 1412 | <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
||
| 1413 | </div> |
||
| 1414 | <?php } ?> |
||
| 1415 | |||
| 1416 | <div class='row'> |
||
| 1417 | <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
||
| 1418 | <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> |
||
| 1419 | </div> |
||
| 1420 | </div> |
||
| 1421 | |||
| 1422 | </div> |
||
| 1423 | </div> |
||
| 1424 | <?php } ?> |
||
| 1425 | |||
| 1426 | <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?> |
||
| 1427 | |||
| 1428 | <div class="item_totals_type_checkbox"> |
||
| 1429 | |||
| 1430 | <?php |
||
| 1431 | foreach ( $items as $index => $item ) { |
||
| 1432 | |||
| 1433 | if ( ! empty( $item['required'] ) ) { |
||
| 1434 | continue; |
||
| 1435 | } |
||
| 1436 | |||
| 1437 | $title = sanitize_text_field( $item['title'] ); |
||
| 1438 | $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
||
| 1439 | $item_id = esc_attr( $id . "_$index" ); |
||
| 1440 | $value = esc_attr( $item['id'] ); |
||
| 1441 | $checked = checked( ! isset( $selected_checkbox_item ), true, false ); |
||
| 1442 | $selected_checkbox_item = 1; |
||
| 1443 | |||
| 1444 | echo " |
||
| 1445 | <div class='custom-control custom-checkbox'> |
||
| 1446 | <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> |
||
| 1447 | <label for='$item_id' class='custom-control-label'>$title ($price)</label> |
||
| 1448 | </div>"; |
||
| 1449 | |||
| 1450 | if ( ! empty( $item['description'] ) ) { |
||
| 1451 | echo "<small class='form-text text-muted'>{$item['description']}</small>"; |
||
| 1452 | } |
||
| 1453 | } |
||
| 1454 | ?> |
||
| 1455 | |||
| 1456 | <div class="mt-3 border item_totals_type_checkbox_totals"> |
||
| 1457 | |||
| 1458 | <?php |
||
| 1459 | |||
| 1460 | $total = 0; |
||
| 1461 | $tax = 0; |
||
| 1462 | $sub_total = 0; |
||
| 1463 | |||
| 1464 | foreach ( $items as $item ) { |
||
| 1465 | |||
| 1466 | $class = 'col-8'; |
||
| 1467 | $class2 = ''; |
||
| 1468 | |||
| 1469 | if ( ! empty( $item['allow_quantities'] ) ) { |
||
| 1470 | $class = 'col-6 pt-2'; |
||
| 1471 | $class2 = 'pt-2'; |
||
| 1472 | } |
||
| 1473 | |||
| 1474 | if ( ! empty( $item['custom_price'] ) ) { |
||
| 1475 | $class .= ' pt-2'; |
||
| 1476 | } |
||
| 1477 | |||
| 1478 | $class3 = 'd-none'; |
||
| 1479 | $name = ''; |
||
| 1480 | if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) { |
||
| 1481 | |||
| 1482 | $amount = floatval( $item['price'] ); |
||
| 1483 | if ( wpinv_use_taxes() ) { |
||
| 1484 | |||
| 1485 | $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
||
| 1486 | |||
| 1487 | if ( wpinv_prices_include_tax() ) { |
||
| 1488 | $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
||
| 1489 | $item_tax = $amount - $pre_tax; |
||
| 1490 | } else { |
||
| 1491 | $pre_tax = $amount; |
||
| 1492 | $item_tax = $amount * $rate * 0.01; |
||
| 1493 | } |
||
| 1494 | |||
| 1495 | $tax = $tax + $item_tax; |
||
| 1496 | $sub_total = $sub_total + $pre_tax; |
||
| 1497 | $total = $sub_total + $tax; |
||
| 1498 | |||
| 1499 | } else { |
||
| 1500 | $total = $total + $amount; |
||
| 1501 | } |
||
| 1502 | |||
| 1503 | $class3 = ''; |
||
| 1504 | $name = "wpinv-items[{$item['id']}]"; |
||
| 1505 | |||
| 1506 | if ( empty( $item['required'] ) ) { |
||
| 1507 | $totals_selected_checkbox_item = 1; |
||
| 1508 | } |
||
| 1509 | |||
| 1510 | } |
||
| 1511 | |||
| 1512 | $class3 .= " wpinv_item_{$item['id']}"; |
||
| 1513 | |||
| 1514 | ?> |
||
| 1515 | |||
| 1516 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
||
| 1517 | <div class='row pl-2 pr-2 pt-2'> |
||
| 1518 | <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
||
| 1519 | |||
| 1520 | <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
||
| 1521 | |||
| 1522 | <div class='col-2'> |
||
| 1523 | <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> |
||
| 1524 | </div> |
||
| 1525 | |||
| 1526 | <?php } else { ?> |
||
| 1527 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
||
| 1528 | <?php } if ( empty( $item['custom_price'] ) ) { ?> |
||
| 1529 | |||
| 1530 | <div class='col-4 <?php echo $class2; ?>'> |
||
| 1531 | <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
||
| 1532 | <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
||
| 1533 | </div> |
||
| 1534 | |||
| 1535 | <?php } else {?> |
||
| 1536 | |||
| 1537 | <div class='col-4'> |
||
| 1538 | <div class='input-group'> |
||
| 1539 | |||
| 1540 | <?php if ( 'left' == wpinv_currency_position() ) { ?> |
||
| 1541 | <div class='input-group-prepend'> |
||
| 1542 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1543 | </div> |
||
| 1544 | <?php } ?> |
||
| 1545 | |||
| 1546 | <input type='text' 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'] ); ?>'> |
||
| 1547 | |||
| 1548 | <?php if ( 'left' != wpinv_currency_position() ) { ?> |
||
| 1549 | <div class='input-group-append'> |
||
| 1550 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1551 | </div> |
||
| 1552 | <?php } ?> |
||
| 1553 | |||
| 1554 | </div> |
||
| 1555 | </div> |
||
| 1556 | <?php } ?> |
||
| 1557 | |||
| 1558 | </div> |
||
| 1559 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1560 | <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1561 | <?php } ?> |
||
| 1562 | </div> |
||
| 1563 | <?php } ?> |
||
| 1564 | |||
| 1565 | <div class='mt-4 border-top item_totals_total p-2'> |
||
| 1566 | |||
| 1567 | <div class='row'> |
||
| 1568 | <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
||
| 1569 | <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
||
| 1570 | </div> |
||
| 1571 | |||
| 1572 | <div class='row' style='display: none;'> |
||
| 1573 | <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
||
| 1574 | <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
||
| 1575 | </div> |
||
| 1576 | |||
| 1577 | <?php if ( wpinv_use_taxes() ) { ?> |
||
| 1578 | <div class='row'> |
||
| 1579 | <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
||
| 1580 | <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
||
| 1581 | </div> |
||
| 1582 | <?php } ?> |
||
| 1583 | |||
| 1584 | <div class='row'> |
||
| 1585 | <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
||
| 1586 | <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> |
||
| 1587 | </div> |
||
| 1588 | </div> |
||
| 1589 | </div> |
||
| 1590 | </div> |
||
| 1591 | <?php } ?> |
||
| 1592 | |||
| 1593 | <?php if ( 'select' == $field[ 'items_type' ] ) { ?> |
||
| 1594 | |||
| 1595 | <div class="item_totals_type_select"> |
||
| 1596 | |||
| 1597 | <?php |
||
| 1598 | |||
| 1599 | $options = array(); |
||
| 1600 | $selected = ''; |
||
| 1601 | foreach ( $items as $index => $item ) { |
||
| 1602 | |||
| 1603 | if ( ! empty( $item['required'] ) ) { |
||
| 1604 | continue; |
||
| 1605 | } |
||
| 1606 | |||
| 1607 | $title = sanitize_text_field( $item['title'] ); |
||
| 1608 | $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
||
| 1609 | $options[ $item['id'] ] = "$title ($price)"; |
||
| 1610 | |||
| 1611 | if ( ! isset( $selected_item ) ) { |
||
| 1612 | $selected = $item['id']; |
||
| 1613 | $selected_item = 1; |
||
| 1614 | } |
||
| 1615 | |||
| 1616 | } |
||
| 1617 | |||
| 1618 | echo aui()->select( |
||
| 1619 | array( |
||
| 1620 | 'name' => 'payment-form-items', |
||
| 1621 | 'id' => $id, |
||
| 1622 | 'placeholder' => __( 'Select an item', 'invoicing' ), |
||
| 1623 | 'no_wrap' => true, |
||
| 1624 | 'options' => $options, |
||
| 1625 | 'class' => 'wpi_select2 wpinv-items-select-selector', |
||
| 1626 | 'value' => $selected, |
||
| 1627 | ) |
||
| 1628 | ); |
||
| 1629 | ?> |
||
| 1630 | |||
| 1631 | <div class="mt-3 border item_totals_type_select_totals"> |
||
| 1632 | |||
| 1633 | <?php |
||
| 1634 | |||
| 1635 | $total = 0; |
||
| 1636 | $tax = 0; |
||
| 1637 | $sub_total = 0; |
||
| 1638 | |||
| 1639 | foreach ( $items as $item ) { |
||
| 1640 | |||
| 1641 | $class = 'col-8'; |
||
| 1642 | $class2 = ''; |
||
| 1643 | |||
| 1644 | if ( ! empty( $item['allow_quantities'] ) ) { |
||
| 1645 | $class = 'col-6 pt-2'; |
||
| 1646 | $class2 = 'pt-2'; |
||
| 1647 | } |
||
| 1648 | |||
| 1649 | if ( ! empty( $item['custom_price'] ) ) { |
||
| 1650 | $class .= ' pt-2'; |
||
| 1651 | } |
||
| 1652 | |||
| 1653 | $class3 = 'd-none'; |
||
| 1654 | $name = ''; |
||
| 1655 | if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) { |
||
| 1656 | |||
| 1657 | $amount = floatval( $item['price'] ); |
||
| 1658 | if ( wpinv_use_taxes() ) { |
||
| 1659 | |||
| 1660 | $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
||
| 1661 | |||
| 1662 | if ( wpinv_prices_include_tax() ) { |
||
| 1663 | $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
||
| 1664 | $item_tax = $amount - $pre_tax; |
||
| 1665 | } else { |
||
| 1666 | $pre_tax = $amount; |
||
| 1667 | $item_tax = $amount * $rate * 0.01; |
||
| 1668 | } |
||
| 1669 | |||
| 1670 | $tax = $tax + $item_tax; |
||
| 1671 | $sub_total = $sub_total + $pre_tax; |
||
| 1672 | $total = $sub_total + $tax; |
||
| 1673 | |||
| 1674 | } else { |
||
| 1675 | $total = $total + $amount; |
||
| 1676 | } |
||
| 1677 | |||
| 1678 | $class3 = ''; |
||
| 1679 | $name = "wpinv-items[{$item['id']}]"; |
||
| 1680 | |||
| 1681 | if ( empty( $item['required'] ) ) { |
||
| 1682 | $totals_selected_select_item = 1; |
||
| 1683 | } |
||
| 1684 | |||
| 1685 | } |
||
| 1686 | |||
| 1687 | $class3 .= " wpinv_item_{$item['id']}"; |
||
| 1688 | |||
| 1689 | ?> |
||
| 1690 | |||
| 1691 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
||
| 1692 | <div class='row pl-2 pr-2 pt-2'> |
||
| 1693 | <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
||
| 1694 | |||
| 1695 | <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
||
| 1696 | |||
| 1697 | <div class='col-2'> |
||
| 1698 | <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> |
||
| 1699 | </div> |
||
| 1700 | |||
| 1701 | <?php } else { ?> |
||
| 1702 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
||
| 1703 | <?php } if ( empty( $item['custom_price'] ) ) { ?> |
||
| 1704 | |||
| 1705 | <div class='col-4 <?php echo $class2; ?>'> |
||
| 1706 | <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
||
| 1707 | <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
||
| 1708 | </div> |
||
| 1709 | |||
| 1710 | <?php } else {?> |
||
| 1711 | |||
| 1712 | <div class='col-4'> |
||
| 1713 | <div class='input-group'> |
||
| 1714 | |||
| 1715 | <?php if ( 'left' == wpinv_currency_position() ) { ?> |
||
| 1716 | <div class='input-group-prepend'> |
||
| 1717 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1718 | </div> |
||
| 1719 | <?php } ?> |
||
| 1720 | |||
| 1721 | <input type='text' 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'] ); ?>'> |
||
| 1722 | |||
| 1723 | <?php if ( 'left' != wpinv_currency_position() ) { ?> |
||
| 1724 | <div class='input-group-append'> |
||
| 1725 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1726 | </div> |
||
| 1727 | <?php } ?> |
||
| 1728 | |||
| 1729 | </div> |
||
| 1730 | </div> |
||
| 1731 | <?php } ?> |
||
| 1732 | |||
| 1733 | </div> |
||
| 1734 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1735 | <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1736 | <?php } ?> |
||
| 1737 | </div> |
||
| 1738 | <?php } ?> |
||
| 1739 | |||
| 1740 | <div class='mt-4 border-top item_totals_total p-2'> |
||
| 1741 | |||
| 1742 | <div class='row'> |
||
| 1743 | <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
||
| 1744 | <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
||
| 1745 | </div> |
||
| 1746 | |||
| 1747 | <div class='row' style='display: none;'> |
||
| 1748 | <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
||
| 1749 | <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
||
| 1750 | </div> |
||
| 1751 | |||
| 1752 | <?php if ( wpinv_use_taxes() ) { ?> |
||
| 1753 | <div class='row'> |
||
| 1754 | <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
||
| 1755 | <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
||
| 1756 | </div> |
||
| 1757 | <?php } ?> |
||
| 1758 | <div class='row'> |
||
| 1759 | <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
||
| 1760 | <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> |
||
| 1761 | </div> |
||
| 1762 | </div> |
||
| 1763 | |||
| 1764 | </div> |
||
| 1765 | <?php } ?> |
||
| 1766 | |||
| 1767 | <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?> |
||
| 1768 | |||
| 1769 | <div class="item_totals_type_multi_select"> |
||
| 1770 | |||
| 1771 | <?php |
||
| 1772 | |||
| 1773 | $options = array(); |
||
| 1774 | $selected = array(); |
||
| 1775 | |||
| 1776 | foreach ( $items as $index => $item ) { |
||
| 1777 | |||
| 1778 | if ( ! empty( $item['required'] ) ) { |
||
| 1779 | continue; |
||
| 1780 | } |
||
| 1781 | |||
| 1782 | $title = sanitize_text_field( $item['title'] ); |
||
| 1783 | $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
||
| 1784 | $options[ $item['id'] ] = "$title ($price)"; |
||
| 1785 | |||
| 1786 | if ( ! isset( $selected_item ) ) { |
||
| 1787 | $selected = array( $item['id'] ); |
||
| 1788 | $selected_item = 1; |
||
| 1789 | } |
||
| 1790 | |||
| 1791 | } |
||
| 1792 | |||
| 1793 | echo aui()->select( |
||
| 1794 | array( |
||
| 1795 | 'name' => 'payment-form-items', |
||
| 1796 | 'id' => $id, |
||
| 1797 | 'no_wrap' => true, |
||
| 1798 | 'options' => $options, |
||
| 1799 | 'multiple' => true, |
||
| 1800 | 'class' => 'wpi_select2 wpinv-items-multiselect-selector', |
||
| 1801 | 'value' => $selected, |
||
| 1802 | ) |
||
| 1803 | ); |
||
| 1804 | ?> |
||
| 1805 | |||
| 1806 | <div class="mt-3 border item_totals_type_select_totals"> |
||
| 1807 | |||
| 1808 | <?php |
||
| 1809 | |||
| 1810 | $total = 0; |
||
| 1811 | $tax = 0; |
||
| 1812 | $sub_total = 0; |
||
| 1813 | |||
| 1814 | foreach ( $items as $item ) { |
||
| 1815 | |||
| 1816 | $class = 'col-8'; |
||
| 1817 | $class2 = ''; |
||
| 1818 | |||
| 1819 | if ( ! empty( $item['allow_quantities'] ) ) { |
||
| 1820 | $class = 'col-6 pt-2'; |
||
| 1821 | $class2 = 'pt-2'; |
||
| 1822 | } |
||
| 1823 | |||
| 1824 | if ( ! empty( $item['custom_price'] ) ) { |
||
| 1825 | $class .= ' pt-2'; |
||
| 1826 | } |
||
| 1827 | |||
| 1828 | $class3 = 'd-none'; |
||
| 1829 | $name = ''; |
||
| 1830 | if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) { |
||
| 1831 | |||
| 1832 | $amount = floatval( $item['price'] ); |
||
| 1833 | if ( wpinv_use_taxes() ) { |
||
| 1834 | |||
| 1835 | $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
||
| 1836 | |||
| 1837 | if ( wpinv_prices_include_tax() ) { |
||
| 1838 | $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
||
| 1839 | $item_tax = $amount - $pre_tax; |
||
| 1840 | } else { |
||
| 1841 | $pre_tax = $amount; |
||
| 1842 | $item_tax = $amount * $rate * 0.01; |
||
| 1843 | } |
||
| 1844 | |||
| 1845 | $tax = $tax + $item_tax; |
||
| 1846 | $sub_total = $sub_total + $pre_tax; |
||
| 1847 | $total = $sub_total + $tax; |
||
| 1848 | |||
| 1849 | } else { |
||
| 1850 | $total = $total + $amount; |
||
| 1851 | } |
||
| 1852 | |||
| 1853 | $class3 = ''; |
||
| 1854 | $name = "wpinv-items[{$item['id']}]"; |
||
| 1855 | |||
| 1856 | if ( empty( $item['required'] ) ) { |
||
| 1857 | $totals_selected_select_item = 1; |
||
| 1858 | } |
||
| 1859 | |||
| 1860 | } |
||
| 1861 | |||
| 1862 | $class3 .= " wpinv_item_{$item['id']}"; |
||
| 1863 | |||
| 1864 | ?> |
||
| 1865 | |||
| 1866 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
||
| 1867 | <div class='row pl-2 pr-2 pt-2'> |
||
| 1868 | <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
||
| 1869 | |||
| 1870 | <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
||
| 1871 | |||
| 1872 | <div class='col-2'> |
||
| 1873 | <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> |
||
| 1874 | </div> |
||
| 1875 | |||
| 1876 | <?php } else { ?> |
||
| 1877 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
||
| 1878 | <?php } if ( empty( $item['custom_price'] ) ) { ?> |
||
| 1879 | |||
| 1880 | <div class='col-4 <?php echo $class2; ?>'> |
||
| 1881 | <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
||
| 1882 | <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
||
| 1883 | </div> |
||
| 1884 | |||
| 1885 | <?php } else {?> |
||
| 1886 | |||
| 1887 | <div class='col-4'> |
||
| 1888 | <div class='input-group'> |
||
| 1889 | |||
| 1890 | <?php if ( 'left' == wpinv_currency_position() ) { ?> |
||
| 1891 | <div class='input-group-prepend'> |
||
| 1892 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1893 | </div> |
||
| 1894 | <?php } ?> |
||
| 1895 | |||
| 1896 | <input type='text' 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'] ); ?>'> |
||
| 1897 | |||
| 1898 | <?php if ( 'left' != wpinv_currency_position() ) { ?> |
||
| 1899 | <div class='input-group-append'> |
||
| 1900 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
||
| 1901 | </div> |
||
| 1902 | <?php } ?> |
||
| 1903 | |||
| 1904 | </div> |
||
| 1905 | </div> |
||
| 1906 | <?php } ?> |
||
| 1907 | |||
| 1908 | </div> |
||
| 1909 | <?php if ( ! empty( $item['description'] )) { ?> |
||
| 1910 | <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
||
| 1911 | <?php } ?> |
||
| 1912 | </div> |
||
| 1913 | <?php } ?> |
||
| 1914 | |||
| 1915 | <div class='mt-4 border-top item_totals_total p-2'> |
||
| 1916 | |||
| 1917 | <div class='row'> |
||
| 1918 | <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
||
| 1919 | <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
||
| 1920 | </div> |
||
| 1921 | |||
| 1922 | <div class='row' style='display: none;'> |
||
| 1923 | <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
||
| 1924 | <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
||
| 1925 | </div> |
||
| 1926 | |||
| 1927 | <?php if ( wpinv_use_taxes() ) { ?> |
||
| 1928 | <div class='row'> |
||
| 1929 | <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
||
| 1930 | <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
||
| 1931 | </div> |
||
| 1932 | <?php } ?> |
||
| 1933 | |||
| 1934 | <div class='row'> |
||
| 1935 | <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
||
| 1936 | <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> |
||
| 1937 | </div> |
||
| 1938 | </div> |
||
| 1939 | |||
| 1940 | </div> |
||
| 1941 | <?php } ?> |
||
| 1942 | <?php if ( ! empty( $field[ 'description' ] ) ) { ?> |
||
| 1943 | <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small> |
||
| 1944 | <?php } ?> |
||
| 1945 | </div> |
||
| 1946 | <?php |
||
| 1947 | } |
||
| 1948 | |||
| 1949 | /** |
||
| 1950 | * Renders the items element template. |
||
| 1951 | */ |
||
| 1952 | public function edit_items_template( $field ) { |
||
| 1953 | global $wpinv_euvat, $post; |
||
| 1954 | |||
| 1955 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
| 1956 | $id2 = $field . '.id + "_edit2"'; |
||
| 1957 | $id3 = $field . '.id + "_edit3"'; |
||
| 1958 | |||
| 1959 | // Item types. |
||
| 1960 | $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
||
| 1961 | |||
| 1962 | ?> |
||
| 1963 | <div <?php echo $restrict; ?>> |
||
| 1964 | <div v-if="!is_default"> |
||
| 1965 | <div class="mb-1"><?php _e( 'Form Items', 'invoicing' ); ?></div> |
||
| 1966 | <draggable v-model='form_items' group='selectable_form_items'> |
||
| 1967 | <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class="'item_' + item.id" :key="item.id"> |
||
| 1968 | |||
| 1969 | <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'> |
||
| 1970 | <span class='label'>{{item.title}}</span> |
||
| 1971 | <span class='price'>({{formatPrice(item.price)}})</span> |
||
| 1972 | <span class='toggle-icon'> |
||
| 1973 | <span class='dashicons dashicons-arrow-down'></span> |
||
| 1974 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
| 1975 | </span> |
||
| 1976 | </div> |
||
| 1977 | |||
| 1978 | <div class='wpinv-available-items-editor-body'> |
||
| 1979 | <div class='p-3'> |
||
| 1980 | |||
| 1981 | <div class="form-group" v-if="! item.new"> |
||
| 1982 | <span class='form-text'> |
||
| 1983 | <a target="_blank" :href="'<?php echo esc_url( admin_url( '/post.php?action=edit&post' ) ) ?>=' + item.id"> |
||
| 1984 | <?php _e( 'Edit the item name, price and other details', 'invoicing' ); ?> |
||
| 1985 | </a> |
||
| 1986 | </span> |
||
| 1987 | </div> |
||
| 1988 | |||
| 1989 | <div class='form-group' v-if="item.new"> |
||
| 1990 | <label class='mb-0 w-100'> |
||
| 1991 | <span><?php _e( 'Item Name', 'invoicing' ); ?></span> |
||
| 1992 | <input v-model='item.title' type='text' class='w-100'/> |
||
| 1993 | </label> |
||
| 1994 | </div> |
||
| 1995 | |||
| 1996 | <div class='form-group' v-if="item.new"> |
||
| 1997 | <label class='mb-0 w-100'> |
||
| 1998 | <span v-if='!item.custom_price'><?php _e( 'Item Price', 'invoicing' ); ?></span> |
||
| 1999 | <span v-if='item.custom_price'><?php _e( 'Recommended Price', 'invoicing' ); ?></span> |
||
| 2000 | <input v-model='item.price' type='text' class='w-100'/> |
||
| 2001 | </label> |
||
| 2002 | </div> |
||
| 2003 | |||
| 2004 | <div class='form-group' v-if='item.new'> |
||
| 2005 | <label :for="'edit_item_type' + item.id" class='mb-0 w-100'> |
||
| 2006 | <span><?php _e( 'Item Type', 'invoicing' ); ?></span> |
||
| 2007 | <select class='w-100' v-model='item.type'> |
||
| 2008 | <?php |
||
| 2009 | foreach ( $item_types as $type => $_label ) { |
||
| 2010 | $type = esc_attr( $type ); |
||
| 2011 | $_label = esc_html( $_label ); |
||
| 2012 | echo "<option value='$type'>$_label</type>"; |
||
| 2013 | } |
||
| 2014 | ?> |
||
| 2015 | </select> |
||
| 2016 | </label> |
||
| 2017 | </div> |
||
| 2018 | |||
| 2019 | <div v-if='item.new'> |
||
| 2020 | <?php if ( $wpinv_euvat->allow_vat_rules() ) : ?> |
||
| 2021 | <div class='form-group'> |
||
| 2022 | <label class='w-100 mb-0'><?php _e( 'VAT Rule', 'invoicing' ) ; ?> |
||
| 2023 | <select class='w-100' v-model='item.rule'> |
||
| 2024 | <?php |
||
| 2025 | foreach ( $wpinv_euvat->get_rules() as $type => $_label ) { |
||
| 2026 | $type = esc_attr( $type ); |
||
| 2027 | $_label = esc_html( $_label ); |
||
| 2028 | echo "<option value='$type'>$_label</type>"; |
||
| 2029 | } |
||
| 2030 | ?> |
||
| 2031 | </select> |
||
| 2032 | </label> |
||
| 2033 | </div> |
||
| 2034 | <?php endif;?> |
||
| 2035 | |||
| 2036 | <?php if ( $wpinv_euvat->allow_vat_classes() ) : ?> |
||
| 2037 | <div class='form-group'> |
||
| 2038 | <label class='w-100 mb-0'><?php _e( 'VAT class', 'invoicing' ) ; ?> |
||
| 2039 | <select class='w-100' v-model='item.class'> |
||
| 2040 | <?php |
||
| 2041 | foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) { |
||
| 2042 | $type = esc_attr( $type ); |
||
| 2043 | $_label = esc_html( $_label ); |
||
| 2044 | echo "<option value='$type'>$_label</type>"; |
||
| 2045 | } |
||
| 2046 | ?> |
||
| 2047 | </select> |
||
| 2048 | </label> |
||
| 2049 | </div> |
||
| 2050 | <?php endif;?> |
||
| 2051 | |||
| 2052 | </div> |
||
| 2053 | |||
| 2054 | <label v-if='item.new' class='form-group'> |
||
| 2055 | <input v-model='item.custom_price' type='checkbox' /> |
||
| 2056 | <span class='form-check-label'><?php _e( 'Allow users to pay what they want', 'invoicing' ); ?></span> |
||
| 2057 | </label> |
||
| 2058 | |||
| 2059 | <div class='form-group' v-if='item.new && item.custom_price'> |
||
| 2060 | <label class='mb-0 w-100'> |
||
| 2061 | <span><?php _e( 'Minimum Price', 'invoicing' ); ?></span> |
||
| 2062 | <input placeholder='0.00' v-model='item.minimum_price' class='w-100' /> |
||
| 2063 | <small class='form-text text-muted'><?php _e( 'Enter the minimum price that a user can pay', 'invoicing' ); ?></small> |
||
| 2064 | </label> |
||
| 2065 | </div> |
||
| 2066 | |||
| 2067 | <label class='form-group'> |
||
| 2068 | <input v-model='item.allow_quantities' type='checkbox' /> |
||
| 2069 | <span><?php _e( 'Allow users to buy several quantities', 'invoicing' ); ?></span> |
||
| 2070 | </label> |
||
| 2071 | |||
| 2072 | <label class='form-group'> |
||
| 2073 | <input v-model='item.required' type='checkbox' /> |
||
| 2074 | <span><?php _e( 'This item is required', 'invoicing' ); ?></span> |
||
| 2075 | </label> |
||
| 2076 | |||
| 2077 | <div class='form-group'> |
||
| 2078 | <label class="mb-0 w-100"> |
||
| 2079 | <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
||
| 2080 | <textarea v-model='item.description' class='w-100'></textarea> |
||
| 2081 | </label> |
||
| 2082 | </div> |
||
| 2083 | |||
| 2084 | <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e( 'Delete Item', 'invoicing' ); ?></button> |
||
| 2085 | |||
| 2086 | </div> |
||
| 2087 | </div> |
||
| 2088 | |||
| 2089 | </div> |
||
| 2090 | </draggable> |
||
| 2091 | |||
| 2092 | <small v-if='! form_items.length' class='form-text text-danger'><?php _e( 'You have not set up any items. Please select an item below or create a new item.', 'invoicing' ); ?></small> |
||
| 2093 | |||
| 2094 | <div class='form-group mt-2'> |
||
| 2095 | |||
| 2096 | <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" v-model='selected_item' @change='addSelectedItem'> |
||
| 2097 | <option value=''><?php _e( 'Select an item to add...', 'invoicing' ) ?></option> |
||
| 2098 | <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option> |
||
| 2099 | </select> |
||
| 2100 | |||
| 2101 | </div> |
||
| 2102 | |||
| 2103 | <div class='form-group'> |
||
| 2104 | <button @click.prevent='addNewItem' class="button button-link"><?php _e( 'Or create a new item.', 'invoicing' ) ?></button> |
||
| 2105 | </div> |
||
| 2106 | |||
| 2107 | <div class='form-group mt-5'> |
||
| 2108 | <label :for='<?php echo $id2; ?>'><?php _e( 'Let customers...', 'invoicing' ) ?></label> |
||
| 2109 | |||
| 2110 | <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" :id='<?php echo $id2; ?>' v-model='<?php echo $field; ?>.items_type'> |
||
| 2111 | <option value='total' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Buy all items on the list', 'invoicing' ); ?></option> |
||
| 2112 | <option value='radio'><?php _e( 'Select a single item from the list', 'invoicing' ); ?></option> |
||
| 2113 | <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select one or more items on the list', 'invoicing' ) ;?></option> |
||
| 2114 | <option value='select'><?php _e( 'Select a single item from a dropdown', 'invoicing' ); ?></option> |
||
| 2115 | <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select a one or more items from a dropdown', 'invoicing' ) ;?></option> |
||
| 2116 | </select> |
||
| 2117 | |||
| 2118 | </div> |
||
| 2119 | </div> |
||
| 2120 | <div class='form-group'> |
||
| 2121 | <label :for='<?php echo $id3; ?>'><?php _e( 'Help Text', 'invoicing' ); ?></label> |
||
| 2122 | <textarea placeholder='<?php esc_attr_e( 'Add some help text for this element', 'invoicing' ); ?>' :id='<?php echo $id3; ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea> |
||
| 2123 | </div> |
||
| 2124 | |||
| 2125 | </div> |
||
| 2126 | |||
| 2127 | <?php |
||
| 2128 | |||
| 2129 | } |
||
| 2130 | |||
| 2131 | /** |
||
| 2132 | * Returns an array of all published items. |
||
| 2133 | */ |
||
| 2134 | public function get_published_items() { |
||
| 2135 | |||
| 2136 | $item_args = array( |
||
| 2137 | 'post_type' => 'wpi_item', |
||
| 2138 | 'orderby' => 'title', |
||
| 2139 | 'order' => 'ASC', |
||
| 2140 | 'posts_per_page' => -1, |
||
| 2141 | 'post_status' => array( 'publish' ), |
||
| 2142 | 'meta_query' => array( |
||
| 2143 | array( |
||
| 2144 | 'key' => '_wpinv_type', |
||
| 2145 | 'compare' => '!=', |
||
| 2146 | 'value' => 'package' |
||
| 2147 | ) |
||
| 2148 | ) |
||
| 2149 | ); |
||
| 2150 | |||
| 2151 | $items = get_posts( apply_filters( 'getpaid_payment_form_item_dropdown_query_args', $item_args ) ); |
||
| 2152 | |||
| 2153 | if ( empty( $items ) ) { |
||
| 2154 | return array(); |
||
| 2155 | } |
||
| 2156 | |||
| 2157 | $options = array(); |
||
| 2158 | foreach ( $items as $item ) { |
||
| 2159 | $item = new GetPaid_Form_Item( $item ); |
||
| 2160 | $options[] = $item->prepare_data_for_use(); |
||
| 2161 | } |
||
| 2162 | return $options; |
||
| 2163 | |||
| 2164 | } |
||
| 2165 | |||
| 2166 | /** |
||
| 2167 | * Returns an array of items for the currently being edited form. |
||
| 2168 | */ |
||
| 2169 | public function get_form_items( $id = false ) { |
||
| 2170 | $form = new GetPaid_Payment_Form( $id ); |
||
| 2171 | |||
| 2172 | // Is this a default form? |
||
| 2173 | if ( $form->is_default() ) { |
||
| 2174 | return array(); |
||
| 2175 | } |
||
| 2176 | |||
| 2177 | return $form->get_items( 'view', 'arrays' ); |
||
| 2178 | } |
||
| 2179 | |||
| 2180 | /** |
||
| 2181 | * Converts form items for use. |
||
| 2182 | */ |
||
| 2183 | public function convert_checkout_items( $items, $invoice ) { |
||
| 2184 | |||
| 2185 | $converted = array(); |
||
| 2186 | foreach ( $items as $item ) { |
||
| 2187 | |||
| 2188 | $item_id = $item['id']; |
||
| 2189 | $_item = new WPInv_Item( $item_id ); |
||
| 2190 | |||
| 2191 | if( ! $_item ) { |
||
| 2192 | continue; |
||
| 2193 | } |
||
| 2194 | |||
| 2195 | $converted[] = array( |
||
| 2196 | 'title' => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ), |
||
| 2197 | 'id' => $item['id'], |
||
| 2198 | 'price' => $item['subtotal'], |
||
| 2199 | 'custom_price' => $_item->get_is_dynamic_pricing(), |
||
| 2200 | 'recurring' => $_item->is_recurring(), |
||
| 2201 | 'description' => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ), |
||
| 2202 | 'minimum_price' => $_item->get_minimum_price(), |
||
| 2203 | 'allow_quantities' => false, |
||
| 2204 | 'quantity' => $item['quantity'], |
||
| 2205 | 'required' => true, |
||
| 2206 | ); |
||
| 2207 | } |
||
| 2208 | return $converted; |
||
| 2209 | |||
| 2210 | } |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * Converts an array of id => quantity for use. |
||
| 2214 | */ |
||
| 2215 | public function convert_normal_items( $items ) { |
||
| 2216 | |||
| 2217 | $converted = array(); |
||
| 2218 | foreach ( $items as $item_id => $quantity ) { |
||
| 2219 | |||
| 2220 | $item = new WPInv_Item( $item_id ); |
||
| 2221 | |||
| 2222 | if( ! $item ) { |
||
| 2223 | continue; |
||
| 2224 | } |
||
| 2225 | |||
| 2226 | $converted[] = array( |
||
| 2227 | 'title' => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ), |
||
| 2228 | 'id' => $item_id, |
||
| 2229 | 'price' => $item->get_price(), |
||
| 2230 | 'custom_price' => $item->get_is_dynamic_pricing(), |
||
| 2231 | 'recurring' => $item->is_recurring(), |
||
| 2232 | 'description' => $item->get_summary(), |
||
| 2233 | 'minimum_price' => $item->get_minimum_price(), |
||
| 2234 | 'allow_quantities' => ! empty( $quantity ), |
||
| 2235 | 'quantity' => empty( $quantity ) ? 1 : $quantity, |
||
| 2236 | 'required' => true, |
||
| 2237 | ); |
||
| 2238 | |||
| 2239 | } |
||
| 2240 | |||
| 2241 | return $converted; |
||
| 2242 | |||
| 2243 | } |
||
| 2244 | |||
| 2245 | /** |
||
| 2246 | * Returns an array of elements for the currently being edited form. |
||
| 2247 | */ |
||
| 2248 | public function get_form_elements( $id = false ) { |
||
| 2261 | } |
||
| 2262 | |||
| 2263 | /** |
||
| 2264 | * Sends a redrect response to payment details. |
||
| 2265 | * |
||
| 2266 | */ |
||
| 2267 | public function send_redirect_response( $url ) { |
||
| 2268 | $url = urlencode( $url ); |
||
| 2269 | wp_send_json_success( $url ); |
||
| 2270 | } |
||
| 2271 | |||
| 2272 | /** |
||
| 2273 | * Fired when a checkout error occurs |
||
| 2274 | * |
||
| 2275 | */ |
||
| 2276 | public function checkout_error() { |
||
| 2277 | |||
| 2278 | $errors = wpinv_get_errors(); |
||
| 2279 | |||
| 2280 | if ( ! empty( $errors ) ) { |
||
| 2281 | wpinv_print_errors(); |
||
| 2282 | exit; |
||
| 2283 | } |
||
| 2284 | |||
| 2285 | wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) ); |
||
| 2286 | exit; |
||
| 2287 | |||
| 2288 | } |
||
| 2289 | |||
| 2290 | } |
||
| 2291 |