Flexible Checkout Fields for WooCommerce – WooCommerce Checkout Manager - Version 1.3.3

Version Description

  • 2016-11-28 =
  • Fixed radio buttons saving
  • Strip tags from labels when viewing fields settings
Download this release

Release Info

Developer wpdesk
Plugin Icon wp plugin Flexible Checkout Fields for WooCommerce – WooCommerce Checkout Manager
Version 1.3.3
Comparing to
See all releases

Code changes from version 1.3.2 to 1.3.3

assets/css/front.css CHANGED
@@ -24,8 +24,3 @@
24
  .woocommerce-account .woocommerce .form-right{
25
  float: right!important;
26
  }
27
-
28
- .form-inspireradio input[type=radio]{
29
- float: left;
30
- clear: left;
31
- }
24
  .woocommerce-account .woocommerce .form-right{
25
  float: right!important;
26
  }
 
 
 
 
 
class/views/settings-fields.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
- global $woocommerce;
3
 
4
- $checkout_fields = $args['checkout_fields'];
5
- $settings = get_option('inspire_checkout_fields_settings');
6
  /*
7
  $checkout_field_type_name = array(
8
  'billing' => __( 'Billing Fields', 'flexible-checkout-fields' ),
@@ -17,506 +17,558 @@
17
  }
18
  */
19
 
20
- $checkout_field_type = $args['plugin']->get_fields();
21
  ?>
22
 
23
  <div class="wrap">
24
- <?php if (!empty($_POST['option_page']) && $_POST['option_page'] === 'inspire_checkout_fields_settings'): ?>
25
  <?php if ( isset( $_POST['reset_settings'] ) ) : ?>
26
- <div id="message" class="updated fade">
27
- <p><strong><?php _e( 'Settings resetted.', 'flexible-checkout-fields' ); ?></strong></p>
28
- </div>
29
  <?php endif; ?>
30
- <div id="message" class="updated fade">
31
- <p><strong><?php _e( 'Settings saved.', 'flexible-checkout-fields' ); ?></strong></p>
32
- </div>
33
  <?php endif; ?>
34
 
35
- <div id="nav-menus-frame" class="wp-clearfix">
36
- <div id="menu-settings-column" class="metabox-holder add-new-field-box">
37
- <div id="side-sortables" class="accordion-container">
38
- <form method="post" action="" id="add-new-field">
39
- <h3><?php _e( 'Add New Field', 'flexible-checkout-fields' ); ?></h3>
40
-
41
- <div class="add-new-field-content accordion-section-content" style="display:block;">
42
- <div>
43
- <label for="woocommerce_checkout_fields_field_type"><?php _e( 'Field Type', 'flexible-checkout-fields' ); ?></label>
44
-
45
- <select id="woocommerce_checkout_fields_field_type" name="woocommerce_checkout_fields_field_type">
46
- <?php foreach ($checkout_field_type as $key => $value): ?>
47
- <option value="<?php echo $key ?>"><?php echo $value['name'] ?></option>
48
- <?php endforeach; ?>
49
- </select>
50
- </div>
51
-
52
- <div>
53
- <label for="woocommerce_checkout_fields_field_name"><?php _e( 'Label', 'flexible-checkout-fields' ); ?></label>
54
-
55
- <textarea id="woocommerce_checkout_fields_field_name" name="woocommerce_checkout_fields_field_name"></textarea>
56
-
57
- <p class="description"><?php _e( 'You can use HTML.', 'flexible-checkout-fields' ); ?></p>
58
- </div>
59
-
60
- <div style="display:none;">
61
- <label for="woocommerce_checkout_fields_field_section"><?php _e( 'Section', 'flexible-checkout-fields' ); ?></label>
62
-
63
- <select id="woocommerce_checkout_fields_field_section" name="woocommerce_checkout_fields_field_section">
64
- <?php foreach ( $this->plugin->sections as $custom_section => $custom_section_data ) : ?>
65
- <?php $selected = ""; ?>
66
- <?php if ( $custom_section_data['tab'] == $current_tab ) $selected = " selected"; ?>
67
- <option value="<?php echo $custom_section_data['section']; ?>" <?php echo $selected; ?>><?php echo $custom_section_data['tab_title']; ?></option>
68
- <?php endforeach; ?>
69
- </select>
70
- </div>
71
-
72
- <p class="list-controls"><?php _e( 'Save changes after adding a field.', 'flexible-checkout-fields' ) ?></p>
73
-
74
- <p class="button-controls wp-clearfix">
 
 
 
 
 
75
  <span class="add-to-menu">
76
- <input type="submit" name="" value="<?php _e( 'Add Field', 'flexible-checkout-fields' ) ?>" class="button-secondary right">
 
 
77
  </span>
78
- </p>
79
- </div>
80
- </form>
81
- </div>
82
-
83
- <?php include( 'settings-ads.php' ); ?>
84
- </div>
85
-
86
- <div id="menu-management-liquid">
87
- <div id="menu-management">
88
- <form method="post" action="" id="inspire_checkout_field" class="nav-menus-php">
89
- <?php settings_fields( 'inspire_checkout_fields_settings' ); ?>
90
-
91
- <div class="menu-edit wp-clearfix">
92
- <div id="nav-menu-header">
93
- <div class="major-publishing-actions wp-clearfix">
94
- <h3><?php _e( 'Edit Section', 'flexible-checkout-fields' ) ?></h3>
95
-
96
- <div class="publishing-action">
97
- <span class="spinner"></span>
98
- <input type="submit" name="" value="<?php _e( 'Save Changes', 'flexible-checkout-fields' ) ?>" class="button button-primary">
99
- </div>
100
- </div>
101
- </div>
 
 
102
 
103
  <?php foreach ( $checkout_fields as $key => $fields ): ?>
104
- <?php if ( 'fields_' . $key != $current_tab ) continue; ?>
105
- <input type="hidden" name="inspire_checkout_fields[settings][<?php echo $key ?>]" value="" />
106
- <div id="post-body" class="fields-container">
107
- <h3><?php _e( 'Section Fields', 'flexible-checkout-fields' ) ?> <?php //echo $checkout_field_type_name[$key] ?></h3>
108
-
109
- <ul class="fields menu sortable" id="<?php echo $key; ?>">
110
- <?php foreach ($fields as $name => $field): ?>
 
 
111
  <?php
112
- $field_required = ( ! empty( $settings[$key][$name]['required'] ) && $settings[$key][$name]['required'] == '1' ) || ( isset($field['required'] ) && $field['required'] == 1 && empty( $settings[$key][$name]['required'] ) );
113
- $field_visible = empty( $settings[$key][$name]['visible'] );
114
- $is_custom_field = ! empty($settings[$key][$name]['custom_field'] ) and $settings[$key][$name]['custom_field'] == 1;
115
  ?>
116
 
117
- <li class="field-item menu-item<?php if( ! $field_visible ): ?> field-hidden<?php endif; ?>">
118
- <div class="menu-item-bar">
119
- <div class="menu-item-handle field-item-handle">
120
- <?php if(!empty($settings[$key][$name]['custom_field'])): ?>
121
- <input type="hidden" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][custom_field]" value="1" />
122
- <?php endif; ?>
123
-
124
- <input type="hidden" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][name]" value="<?php echo $name ?>" />
125
-
126
- <span class="item-title">
127
- <?php if(!empty($field['label'])): ?>
128
- <?php echo $field['label'] ?>
129
- <?php else: ?>
130
- <?php echo $name ?>
131
- <?php endif; ?>
132
-
133
- <?php if( $field_required ): ?> *<?php endif; ?>
 
 
 
 
134
  </span>
135
 
136
- <span class="item-controls">
137
- <a href="#" class="item-edit more"><?php _e( 'Edit', 'flexible-checkout-fields' ) ?></a>
 
138
  </span>
139
- </div>
140
- </div>
141
-
142
- <div class="menu-item-settings field-settings">
143
- <div style="margin-bottom: -1px ! important;" class="nav-tab-wrapper">
144
- <a href="#general" class="nav-tab nav-tab-active"><?php _e( 'General', 'flexible-checkout-fields' ); ?></a>
145
- <a class="nav-tab" href="#apperance"><?php _e( 'Appearance', 'flexible-checkout-fields' ); ?></a>
146
- <?php
147
- $additional_tabs = apply_filters( 'flexible_checkout_fields_field_tabs', array() );
148
- foreach ( $additional_tabs as $additional_tab ) {
149
- ?>
150
- <a class="nav-tab" href="#<?php echo $additional_tab['hash']; ?>"><?php echo $additional_tab['title']; ?></a>
151
- <?php
152
- }
153
- ?>
154
- </div>
155
- <div class="field-settings-tab-container field-settings-general">
156
- <?php if( $is_custom_field ): ?>
157
- <?php if ( isset($checkout_field_type[$settings[$key][$name]['type']]['description'] ) ) :?>
158
- <div class="element-<?php echo $settings[$key][$name]['type']; ?>-description show">
159
- <p class="description"><?php echo $checkout_field_type[$settings[$key][$name]['type']]['description']; ?></p>
160
- </div>
161
- <?php endif; ?>
162
- <?php endif; ?>
163
-
164
-
165
- <div>
166
- <input type="hidden" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][visible]" value="1" />
167
-
168
- <label>
169
- <input type="checkbox" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][visible]" value="0" <?php if( $field_visible ): ?> checked<?php endif; ?>>
170
- <?php _e( 'Enable Field', 'flexible-checkout-fields' ) ?>
171
- </label>
172
- </div>
173
-
174
- <?php
 
 
 
 
 
 
 
175
  $checked = '';
176
- $style = '';
177
- if ( isset($settings[$key][$name]['type'])
178
- && isset($checkout_field_type[$settings[$key][$name]['type']]['has_required'])
179
- && $checkout_field_type[$settings[$key][$name]['type']]['has_required'] == false
180
  ) {
181
  $style = ' display:none; ';
182
- }
183
- else {
184
- if( $field_required ) $checked = ' checked';
 
185
  }
186
- ?>
187
- <div style="<?php echo $style; ?>">
188
- <input type="hidden" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][required]" value="0" />
189
-
190
- <label>
191
- <input type="checkbox" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][required]" value="1" <?php echo $checked; ?>>
192
- <?php _e( 'Required Field', 'flexible-checkout-fields' ) ?>
193
- </label>
194
- </div>
195
-
196
- <div class="field-type-label">
197
-
198
- <label for="label_<?php echo $name ?>"><?php _e( 'Label', 'flexible-checkout-fields' ) ?></label>
199
-
200
- <textarea id="label_<?php echo $name ?>" class="field-name" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][label]"><?php if(isset($settings[$key][$name]['label'])): echo stripslashes($settings[$key][$name]['label']); elseif(isset($field['label'])): echo $field['label']; endif; ?></textarea>
201
-
202
- <p class="description"><?php _e( 'You can use HTML.', 'flexible-checkout-fields' ); ?></p>
203
- </div>
204
-
205
- <?php if( $is_custom_field ): ?>
206
- <?php
207
- $required = '';
208
- if( isset($checkout_field_type[$settings[$key][$name]['type']]['has_options']) && $checkout_field_type[$settings[$key][$name]['type']]['has_options']) {
209
- $required = ' required';
210
- }
211
- ?>
212
- <div class="element-option<?php if( isset($checkout_field_type[$settings[$key][$name]['type']]['has_options']) && $checkout_field_type[$settings[$key][$name]['type']]['has_options']) echo " show" ?>">
213
- <label for="option_<?php echo $name ?>"><?php _e( 'Options', 'flexible-checkout-fields' ) ?></label>
214
-
215
- <textarea id="option_<?php echo $name ?>" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][option]" <?php echo $required; ?>><?php echo isset( $settings[$key][$name]['option'] )?$settings[$key][$name]['option']:''; ?></textarea>
216
-
217
- <p><?php _e( 'Format: <code>Value : Name</code>. Value will be in the code, name will be visible to the user. One option per line. Example:<br /><code>woman : I am a woman</code><br /><code>man : I am a man</code>', 'flexible-checkout-fields' ) ?></p>
218
- </div>
219
- <?php endif; ?>
220
-
221
- <?php if( $is_custom_field ): ?>
222
- <?php do_action( 'flexible_checkout_fields_settings_html', $key, $name, $settings ); ?>
223
- <div>
224
- <label for="type_<?php echo $name ?>"><?php _e( 'Field Type', 'flexible-checkout-fields' ) ?></label>
225
-
226
- <select id="woocommerce_checkout_fields_field_type" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][type]" disabled>
227
- <?php foreach ($checkout_field_type as $type_key => $value): ?>
228
- <option value="<?php echo $type_key ?>"<?php if($settings[$key][$name]['type'] == $type_key) echo " selected";?>><?php echo $value['name'] ?></option>
229
- <?php endforeach; ?>
230
- </select>
231
- </div>
232
- <?php endif; ?>
233
- </div>
234
- <div class="field-settings-tab-container field-settings-apperance" style="display:none;">
235
- <?php if( !$is_custom_field || empty( $checkout_field_type[$settings[$key][$name]['type']]['disable_placeholder'] ) || !$checkout_field_type[$settings[$key][$name]['type']]['disable_placeholder'] ): ?>
236
- <div class="field_placeholder">
237
- <?php
238
- $required = '';
239
- if( isset( $settings[$key][$name]['type'] ) && isset( $checkout_field_type[$settings[$key][$name]['type']]['label_is_required'] ) ) {
240
- $required = ' required';
241
- }
242
- ?>
243
- <label for="placeholder_<?php echo $name ?>"><?php if( $is_custom_field && isset( $checkout_field_type[$settings[$key][$name]['type']]['placeholder_label'] ) ): ?><?php echo $checkout_field_type[$settings[$key][$name]['type']]['placeholder_label']; ?><?php else: ?><?php _e( 'Placeholder', 'flexible-checkout-fields' ) ?><?php endif; ?></label>
244
-
245
- <input type="text" id="placeholder_<?php echo $name ?>" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][placeholder]" value="<?php if(!empty($settings[$key][$name]['placeholder'])): echo $settings[$key][$name]['placeholder']; else: echo isset($field['placeholder'])?$field['placeholder']:''; endif; ?>" <?php echo $required; ?> />
246
- </div>
247
- <?php endif; ?>
248
- <div>
249
- <label for="class_<?php echo $name ?>"><?php _e( 'CSS Class', 'flexible-checkout-fields' ) ?></label>
250
- <input type="text" id="class_<?php echo $name ?>" name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][class]" value="<?php if(!empty($settings[$key][$name]['class'])): echo $settings[$key][$name]['class']; else: if(!empty($field['class'])) echo implode(' ', $field['class']); endif; ?>" />
251
- </div>
252
- </div>
253
- <?php do_action( 'flexible_checkout_fields_field_tabs_content', $key, $name, $field, $settings ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  <?php if ( $is_custom_field ) : ?>
255
- <a class="remove-field" href="#"><?php _e( 'Delete Field', 'flexible-checkout-fields' ) ?></a>
 
256
  <?php endif; ?>
257
- </div>
258
- </li>
259
  <?php endforeach; ?>
260
- </ul>
261
- </div>
262
 
263
  <?php do_action( 'flexible_checkout_fields_section_settings', $key, $settings ); ?>
264
-
265
  <?php endforeach; ?>
266
 
267
- <div id="nav-menu-footer">
268
- <div class="major-publishing-actions wp-clearfix">
269
- <input type="submit" name="" value="<?php _e( 'Save Changes', 'flexible-checkout-fields' ) ?>" class="button button-primary">
270
- <input type="submit" value="<?php _e( 'Reset Section Settings', 'flexible-checkout-fields' ); ?>" class="button reset_settings" id="submit" name="reset_settings">
271
- <span class="spinner"></span>
272
- </div>
273
- </div>
274
- </div>
275
- </form>
276
- </div>
277
- </div>
278
- </div>
 
 
 
 
279
  </div>
280
 
281
  <script type="text/javascript">
282
- jQuery(document).ready(function () {
283
- jQuery('.sortable').sortable({
284
- handle: '.field-item-handle',
285
- placeholder: 'sortable-placeholder',
286
- opacity: 0.7,
287
- activate: function(event, ui) {
288
- ui.item.find('.field-settings').hide();
289
- }
290
- });
291
-
292
- // Add New Field
293
- jQuery( "#add-new-field" ).submit(function( e ) {
294
- var field_name = jQuery(this).find('#woocommerce_checkout_fields_field_name').val();
295
- var field_section = jQuery(this).find('#woocommerce_checkout_fields_field_section').val();
296
- var field_type = jQuery(this).find('#woocommerce_checkout_fields_field_type').val();
297
- var field_option = jQuery(this).find('#woocommerce_checkout_fields_field_option').val();
298
- //var field_slug = stringToSlug(field_section + '_' + field_name + '_' + Math.floor((Math.random() * 100000) + 1));
299
- var field_slug = field_section + '_' + stringToSlug(field_name).substr(0,20) + '_' + Math.floor((Math.random() * 100000) + 1);
300
-
301
- // Proceed if Name (label) is filled
302
- if(field_name) {
303
- var html = '';
304
- html += '<li class="field-item menu-item element_' + field_slug + ' just-added">';
305
- html += '<div class="menu-item-bar">';
306
- html += '<div class="menu-item-handle field-item-handle">';
307
- html += '<input type="hidden" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][custom_field]" value="1">';
308
- html += '<input type="hidden" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][name]" value="'+ field_slug +'">';
309
- html += '<span class="item-title">';
310
- html += field_name;
311
- html += '</span>';
312
- html += '<span class="item-controls">';
313
- html += '<a href="#" class="item-edit more"><?php _e( 'Edit', 'flexible-checkout-fields' ) ?></a>';
314
- html += '</span>';
315
- html += '</div>';
316
- html += '</div>';
317
- html += '<div class="menu-item-settings field-settings">';
318
-
319
- html += '<div style="margin-bottom: -1px ! important;" class="nav-tab-wrapper">';
320
- html += '<a href="#general" class="nav-tab nav-tab-active"><?php _e( 'General', 'flexible-checkout-fields' ); ?></a>';
321
- html += '<a class="nav-tab" href="#apperance"><?php _e( 'Appearance', 'flexible-checkout-fields' ); ?></a>';
322
- <?php
323
- $additional_tabs = apply_filters( 'flexible_checkout_fields_field_tabs', array() );
324
- foreach ( $additional_tabs as $additional_tab ) {
325
- ?>
326
- html += '<a class="nav-tab" href="#<?php echo $additional_tab['hash']; ?>"><?php echo $additional_tab['title']; ?></a>';
327
- <?php
328
- }
329
- ?>
330
- html += '</div>';
331
- html += '<div class="field-settings-tab-container field-settings-general">';
332
-
333
- <?php foreach ( $checkout_field_type as $key => $value ) : ?>
334
  <?php if ( isset( $value['description'] ) ) : ?>
335
- html += '<div class="element-<?php echo $key; ?>-description">';
336
- html += '<p class="description"><?php echo $value['description']; ?></p>';
337
- html += '</div>';
338
  <?php endif; ?>
339
- <?php endforeach; ?>
340
- html += '<div>';
341
- html += '<input type="hidden" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][visible]" value="1">';
342
- html += '<label>';
343
- html += '<input type="checkbox" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][visible]" value="0" checked>';
344
- html += '<?php _e( 'Enable Field', 'flexible-checkout-fields' ) ?>';
345
- html += '</label>';
346
- html += '</div>';
347
- html += '<div>';
348
- html += '<input type="hidden" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][required]" value="0">';
349
- html += '<label>';
350
- html += '<input type="checkbox" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][required]" value="1">';
351
- html += '<?php _e( 'Required Field', 'flexible-checkout-fields' ) ?>';
352
- html += '</label>';
353
- html += '</div>';
354
- html += '<div class="field-type-label">';
355
- html += '<label for="label_' + field_slug + '"><?php _e( 'Label', 'flexible-checkout-fields' ) ?></label>';
356
- html += '<textarea id="label_'+ field_slug + '" class="field-name" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][label]">' + field_name + '</textarea>';
357
- html += '<p class="description"><?php _e( 'You can use HTML.', 'flexible-checkout-fields' ); ?></p>';
358
- html += '</div>';
359
-
360
- <?php do_action( 'flexible_checkout_fields_settings_js_html' ); ?>
361
-
362
- html += '<div>';
363
- html += '<label for="type_' + field_slug + '"><?php _e( 'Field Type', 'flexible-checkout-fields' ) ?></label>';
364
- html += '<select id="woocommerce_checkout_fields_field_type" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][type]" disabled>'+printSelectTypeOptions(field_type)+'</select>';
365
- html += '</div>';
366
-
367
- html += '</div>';
368
- html += '<div class="field-settings-tab-container field-settings-apperance" style="display:none;">';
369
-
370
- html += '<div class="field_placeholder">';
371
- html += '<label for="placeholder_'+ field_slug +'"><?php _e( 'Placeholder', 'flexible-checkout-fields' ) ?></label>';
372
- html += '<input type="text" id="placeholder_' + field_slug + '" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][placeholder]" value="">';
373
- html += '</div>';
374
- html += '<div>';
375
- html += '<label for="class_' + field_slug + '"><?php _e( 'CSS Class', 'flexible-checkout-fields') ?></label>';
376
- html += '<input type="text" id="class_' + field_slug + '" name="inspire_checkout_fields[settings]['+ field_section +']['+ field_slug +'][class]" value="">';
377
- html += '</div>';
378
-
379
- html += '</div>';
380
-
381
- <?php do_action( 'flexible_checkout_fields_field_tabs_content_js', $field ); ?>
382
-
383
- html += '<a class="remove-field" href="#"><?php _e( 'Delete Field', 'flexible-checkout-fields' ) ?></a>';
384
- html += '</li>';
385
- html += '';
386
-
387
- jQuery('#' + field_section ).append(html);
388
- jQuery('.element_' + field_slug + ' .element-file-description').hide();
389
-
390
- // Add Field Options or Value or Placeholder
391
- switch(field_type){
392
-
393
- <?php do_action( 'flexible_checkout_fields_settings_js_options' ); ?>
394
-
395
- default:
396
- jQuery('.element_' + field_slug + ' .field_placeholder label').html('<?php _e( 'Placeholder', 'flexible-checkout-fields' ); ?>');
397
- jQuery('.element_' + field_slug + ' .field_placeholder').show();
398
- break;
 
 
 
 
 
 
 
399
  }
400
 
401
- jQuery(this).find('#woocommerce_checkout_fields_field_name').val('');
402
- }
403
- // Display Alert if Name (label) is NOT filled
404
- else {
405
- alert( '<?php _e( 'Enter field label!', 'flexible-checkout-fields' ) ?>' );
406
- }
407
 
408
- e.preventDefault();
409
- });
 
 
 
 
410
 
411
- // Toggle field settings
412
- jQuery(document).on('click', '.field-item a.more', function (e) {
413
- e.preventDefault();
414
- jQuery(this).closest('.field-item').find('.field-settings').slideToggle('fast');
415
- jQuery(this).closest('.field-item').toggleClass('menu-item-edit-active');
416
- });
417
-
418
- // Toggle between placeholder or value
419
- jQuery(document).on('change', '.field-item .field-settings #woocommerce_checkout_fields_field_type', function (e) {
420
- switch(jQuery(this).val()){
421
-
422
- default:
423
- jQuery(this).closest('.field-item').find('.element-option').removeClass('show');
424
- jQuery(this).closest('.field-item').find('.field_placeholder label').html('<?php _e( 'Placeholder', 'flexible-checkout-fields' ); ?>');
425
- jQuery(this).closest('.field-item').find('.field_placeholder').show();
426
- break;
427
- }
428
- e.preventDefault();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  });
430
 
431
- // Remove field
432
- jQuery(document).on('click', '.field-item a.remove-field', function (e) {
433
- e.preventDefault();
434
- var toRemove = jQuery(this).closest('.field-item');
435
- if(confirm('<?php _e( 'Do you really want to delete this field: ', 'flexible-checkout-fields' ) ?>' + toRemove.find('.field-name').val() + '?') ){
436
- toRemove.remove();
437
- }
 
 
 
 
 
 
 
 
 
 
438
  });
439
 
440
- // When Saving Form Remove disabled from Selects
441
- jQuery('form').bind('submit', function () {
442
- jQuery(this).find('select').prop('disabled', false);
443
- jQuery(this).find('.major-publishing-actions').find('.spinner').css('visibility', 'visible');
444
- jQuery('.flexible_checkout_fields_add_rule select').each(function(){
445
- jQuery(this).attr('disabled','disabled');
446
- });
447
- });
448
-
449
- // Activate Spinner on Save
450
- jQuery('input[type="submit"]').on('click', function() {
451
- jQuery('#inspire_checkout_field [required]').each(function(){
452
- if ( jQuery(this).val() == '' && jQuery(this).is(':hidden') ) {
453
- jQuery(this).closest('li').find('.item-controls>a').click();
454
- }
455
- if ( jQuery(this).hasClass("reset_settings") ) {
456
- if ( !confirm( '<?php _e( 'Please confirm settings reset.', 'flexible-checkout-fields' ); ?>' ) ) {
457
- return false;
458
- }
459
- }
460
- });
461
-
462
-
463
- });
464
- });
465
-
466
- <?php do_action( 'flexible_checkout_fields_java_script' ); ?>
467
-
468
- jQuery(document).on('click', '.nav-tab-wrapper > a', function() {
469
- jQuery(this).parent().find('a').each(function() {
470
- jQuery(this).removeClass('nav-tab-active');
471
- });
472
- jQuery(this).addClass('nav-tab-active');
473
- jQuery(this).parent().parent().find('.field-settings-tab-container').each(function(){
474
- jQuery(this).hide();
475
- });
476
- var href = jQuery(this).attr("href");
477
- var hash = href.substr(href.indexOf("#")+1);
478
- jQuery(this).parent().parent().find('.field-settings-' + hash).each(function(){
479
- jQuery(this).show();
480
- });
481
- jQuery(this).blur();
482
- return false;
483
- });
484
-
485
- function printSelectTypeOptions(selected){
486
- var index;
487
- var select;
488
- var sel = "";
489
-
490
- var type = {
491
  <?php foreach ( $checkout_field_type as $key => $value ) : ?>
492
- <?php echo $key; ?>: '<?php echo $value['name']; ?>',
 
493
  <?php endforeach; ?>
494
- };
 
495
 
496
- jQuery.each( type, function( key, value ) {
497
- if(key == selected) sel = " selected";
498
- select += '<option value="' + key + '"' + sel +'>' + value + '</option>';
499
- sel = "";
500
- });
501
 
502
- return select;
503
- }
504
 
505
- function stringToSlug(str) {
506
- str = str.replace(/^\s+|\s+$/g, '');
507
- str = str.toLowerCase();
508
 
509
- var from = "àáäâèéëêìíïîòóöôùúüûñçęóąśłżźćń·/_,:;";
510
- var to = "aaaaeeeeiiiioooouuuunceoaslzxcn------";
511
- for (var i=0, l=from.length ; i<l ; i++) {
512
- str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
513
- }
514
 
515
- str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
516
- .replace(/\s+/g, '_') // collapse whitespace and replace by -
517
- .replace(/-+/g, '_'); // collapse dashes
518
 
519
- return str;
520
- }
521
 
522
  </script>
1
  <?php
2
+ global $woocommerce;
3
 
4
+ $checkout_fields = $args['checkout_fields'];
5
+ $settings = get_option( 'inspire_checkout_fields_settings' );
6
  /*
7
  $checkout_field_type_name = array(
8
  'billing' => __( 'Billing Fields', 'flexible-checkout-fields' ),
17
  }
18
  */
19
 
20
+ $checkout_field_type = $args['plugin']->get_fields();
21
  ?>
22
 
23
  <div class="wrap">
24
+ <?php if ( ! empty( $_POST['option_page'] ) && $_POST['option_page'] === 'inspire_checkout_fields_settings' ): ?>
25
  <?php if ( isset( $_POST['reset_settings'] ) ) : ?>
26
+ <div id="message" class="updated fade">
27
+ <p><strong><?php _e( 'Settings resetted.', 'flexible-checkout-fields' ); ?></strong></p>
28
+ </div>
29
  <?php endif; ?>
30
+ <div id="message" class="updated fade">
31
+ <p><strong><?php _e( 'Settings saved.', 'flexible-checkout-fields' ); ?></strong></p>
32
+ </div>
33
  <?php endif; ?>
34
 
35
+ <div id="nav-menus-frame" class="wp-clearfix">
36
+ <div id="menu-settings-column" class="metabox-holder add-new-field-box">
37
+ <div id="side-sortables" class="accordion-container">
38
+ <form method="post" action="" id="add-new-field">
39
+ <h3><?php _e( 'Add New Field', 'flexible-checkout-fields' ); ?></h3>
40
+
41
+ <div class="add-new-field-content accordion-section-content" style="display:block;">
42
+ <div>
43
+ <label for="woocommerce_checkout_fields_field_type"><?php _e( 'Field Type', 'flexible-checkout-fields' ); ?></label>
44
+
45
+ <select id="woocommerce_checkout_fields_field_type"
46
+ name="woocommerce_checkout_fields_field_type">
47
+ <?php foreach ( $checkout_field_type as $key => $value ): ?>
48
+ <option value="<?php echo $key ?>"><?php echo $value['name'] ?></option>
49
+ <?php endforeach; ?>
50
+ </select>
51
+ </div>
52
+
53
+ <div>
54
+ <label for="woocommerce_checkout_fields_field_name"><?php _e( 'Label', 'flexible-checkout-fields' ); ?></label>
55
+
56
+ <textarea id="woocommerce_checkout_fields_field_name"
57
+ name="woocommerce_checkout_fields_field_name"></textarea>
58
+
59
+ <p class="description"><?php _e( 'You can use HTML.', 'flexible-checkout-fields' ); ?></p>
60
+ </div>
61
+
62
+ <div style="display:none;">
63
+ <label for="woocommerce_checkout_fields_field_section"><?php _e( 'Section', 'flexible-checkout-fields' ); ?></label>
64
+
65
+ <select id="woocommerce_checkout_fields_field_section"
66
+ name="woocommerce_checkout_fields_field_section">
67
+ <?php foreach ( $this->plugin->sections as $custom_section => $custom_section_data ) : ?>
68
+ <?php $selected = ""; ?>
69
+ <?php if ( $custom_section_data['tab'] == $current_tab ) {
70
+ $selected = " selected";
71
+ } ?>
72
+ <option value="<?php echo $custom_section_data['section']; ?>" <?php echo $selected; ?>><?php echo $custom_section_data['tab_title']; ?></option>
73
+ <?php endforeach; ?>
74
+ </select>
75
+ </div>
76
+
77
+ <p class="list-controls"><?php _e( 'Save changes after adding a field.', 'flexible-checkout-fields' ) ?></p>
78
+
79
+ <p class="button-controls wp-clearfix">
80
  <span class="add-to-menu">
81
+ <input type="submit" name=""
82
+ value="<?php _e( 'Add Field', 'flexible-checkout-fields' ) ?>"
83
+ class="button-secondary right">
84
  </span>
85
+ </p>
86
+ </div>
87
+ </form>
88
+ </div>
89
+
90
+ <?php include( 'settings-ads.php' ); ?>
91
+ </div>
92
+
93
+ <div id="menu-management-liquid">
94
+ <div id="menu-management">
95
+ <form method="post" action="" id="inspire_checkout_field" class="nav-menus-php">
96
+ <?php settings_fields( 'inspire_checkout_fields_settings' ); ?>
97
+
98
+ <div class="menu-edit wp-clearfix">
99
+ <div id="nav-menu-header">
100
+ <div class="major-publishing-actions wp-clearfix">
101
+ <h3><?php _e( 'Edit Section', 'flexible-checkout-fields' ) ?></h3>
102
+
103
+ <div class="publishing-action">
104
+ <span class="spinner"></span>
105
+ <input type="submit" name=""
106
+ value="<?php _e( 'Save Changes', 'flexible-checkout-fields' ) ?>"
107
+ class="button button-primary">
108
+ </div>
109
+ </div>
110
+ </div>
111
 
112
  <?php foreach ( $checkout_fields as $key => $fields ): ?>
113
+ <?php if ( 'fields_' . $key != $current_tab ) {
114
+ continue;
115
+ } ?>
116
+ <input type="hidden" name="inspire_checkout_fields[settings][<?php echo $key ?>]" value=""/>
117
+ <div id="post-body" class="fields-container">
118
+ <h3><?php _e( 'Section Fields', 'flexible-checkout-fields' ) ?><?php //echo $checkout_field_type_name[$key] ?></h3>
119
+
120
+ <ul class="fields menu sortable" id="<?php echo $key; ?>">
121
+ <?php foreach ( $fields as $name => $field ): ?>
122
  <?php
123
+ $field_required = ( ! empty( $settings[ $key ][ $name ]['required'] ) && $settings[ $key ][ $name ]['required'] == '1' ) || ( isset( $field['required'] ) && $field['required'] == 1 && empty( $settings[ $key ][ $name ]['required'] ) );
124
+ $field_visible = empty( $settings[ $key ][ $name ]['visible'] );
125
+ $is_custom_field = ! empty( $settings[ $key ][ $name ]['custom_field'] ) and $settings[ $key ][ $name ]['custom_field'] == 1;
126
  ?>
127
 
128
+ <li class="field-item menu-item<?php if ( ! $field_visible ): ?> field-hidden<?php endif; ?>">
129
+ <div class="menu-item-bar">
130
+ <div class="menu-item-handle field-item-handle">
131
+ <?php if ( ! empty( $settings[ $key ][ $name ]['custom_field'] ) ): ?>
132
+ <input type="hidden"
133
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][custom_field]"
134
+ value="1"/>
135
+ <?php endif; ?>
136
+
137
+ <input type="hidden"
138
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][name]"
139
+ value="<?php echo $name ?>"/>
140
+
141
+ <span class="item-title">
142
+ <?php if ( ! empty( $field['label'] ) ): ?>
143
+ <?php echo wp_strip_all_tags( $field['label'] ); ?>
144
+ <?php else: ?>
145
+ <?php echo $name ?>
146
+ <?php endif; ?>
147
+
148
+ <?php if ( $field_required ): ?> *<?php endif; ?>
149
  </span>
150
 
151
+ <span class="item-controls">
152
+ <a href="#"
153
+ class="item-edit more"><?php _e( 'Edit', 'flexible-checkout-fields' ) ?></a>
154
  </span>
155
+ </div>
156
+ </div>
157
+
158
+ <div class="menu-item-settings field-settings">
159
+ <div style="margin-bottom: -1px ! important;" class="nav-tab-wrapper">
160
+ <a href="#general"
161
+ class="nav-tab nav-tab-active"><?php _e( 'General', 'flexible-checkout-fields' ); ?></a>
162
+ <a class="nav-tab"
163
+ href="#apperance"><?php _e( 'Appearance', 'flexible-checkout-fields' ); ?></a>
164
+ <?php
165
+ $additional_tabs = apply_filters( 'flexible_checkout_fields_field_tabs', array() );
166
+ foreach ( $additional_tabs as $additional_tab ) {
167
+ ?>
168
+ <a class="nav-tab"
169
+ href="#<?php echo $additional_tab['hash']; ?>"><?php echo $additional_tab['title']; ?></a>
170
+ <?php
171
+ }
172
+ ?>
173
+ </div>
174
+ <div class="field-settings-tab-container field-settings-general">
175
+ <?php if ( $is_custom_field ): ?>
176
+ <?php if ( isset( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['description'] ) ) : ?>
177
+ <div class="element-<?php echo $settings[ $key ][ $name ]['type']; ?>-description show">
178
+ <p class="description"><?php echo $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['description']; ?></p>
179
+ </div>
180
+ <?php endif; ?>
181
+ <?php endif; ?>
182
+
183
+
184
+ <div>
185
+ <input type="hidden"
186
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][visible]"
187
+ value="1"/>
188
+
189
+ <label>
190
+ <input type="checkbox"
191
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][visible]"
192
+ value="0" <?php if ( $field_visible ): ?> checked<?php endif; ?>>
193
+ <?php _e( 'Enable Field', 'flexible-checkout-fields' ) ?>
194
+ </label>
195
+ </div>
196
+
197
+ <?php
198
  $checked = '';
199
+ $style = '';
200
+ if ( isset( $settings[ $key ][ $name ]['type'] )
201
+ && isset( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['has_required'] )
202
+ && $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['has_required'] == false
203
  ) {
204
  $style = ' display:none; ';
205
+ } else {
206
+ if ( $field_required ) {
207
+ $checked = ' checked';
208
+ }
209
  }
210
+ ?>
211
+ <div style="<?php echo $style; ?>">
212
+ <input type="hidden"
213
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][required]"
214
+ value="0"/>
215
+
216
+ <label>
217
+ <input type="checkbox"
218
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][required]"
219
+ value="1" <?php echo $checked; ?>>
220
+ <?php _e( 'Required Field', 'flexible-checkout-fields' ) ?>
221
+ </label>
222
+ </div>
223
+
224
+ <div class="field-type-label">
225
+
226
+ <label for="label_<?php echo $name ?>"><?php _e( 'Label', 'flexible-checkout-fields' ) ?></label>
227
+
228
+ <textarea id="label_<?php echo $name ?>" class="field-name"
229
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][label]"><?php if ( isset( $settings[ $key ][ $name ]['label'] ) ): echo stripslashes( $settings[ $key ][ $name ]['label'] );
230
+ elseif ( isset( $field['label'] ) ): echo $field['label']; endif; ?></textarea>
231
+
232
+ <p class="description"><?php _e( 'You can use HTML.', 'flexible-checkout-fields' ); ?></p>
233
+ </div>
234
+
235
+ <?php if ( $is_custom_field ): ?>
236
+ <?php
237
+ $required = '';
238
+ if ( isset( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['has_options'] ) && $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['has_options'] ) {
239
+ $required = ' required';
240
+ }
241
+ ?>
242
+ <div class="element-option<?php if ( isset( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['has_options'] ) && $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['has_options'] )
243
+ echo " show" ?>">
244
+ <label for="option_<?php echo $name ?>"><?php _e( 'Options', 'flexible-checkout-fields' ) ?></label>
245
+
246
+ <textarea id="option_<?php echo $name ?>"
247
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][option]" <?php echo $required; ?>><?php echo isset( $settings[ $key ][ $name ]['option'] ) ? $settings[ $key ][ $name ]['option'] : ''; ?></textarea>
248
+
249
+ <p><?php _e( 'Format: <code>Value : Name</code>. Value will be in the code, name will be visible to the user. One option per line. Example:<br /><code>woman : I am a woman</code><br /><code>man : I am a man</code>', 'flexible-checkout-fields' ) ?></p>
250
+ </div>
251
+ <?php endif; ?>
252
+
253
+ <?php if ( $is_custom_field ): ?>
254
+ <?php do_action( 'flexible_checkout_fields_settings_html', $key, $name, $settings ); ?>
255
+ <div>
256
+ <label for="type_<?php echo $name ?>"><?php _e( 'Field Type', 'flexible-checkout-fields' ) ?></label>
257
+
258
+ <select id="woocommerce_checkout_fields_field_type"
259
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][type]"
260
+ disabled>
261
+ <?php foreach ( $checkout_field_type as $type_key => $value ): ?>
262
+ <option value="<?php echo $type_key ?>"<?php if ( $settings[ $key ][ $name ]['type'] == $type_key ) {
263
+ echo " selected";
264
+ } ?>><?php echo $value['name'] ?></option>
265
+ <?php endforeach; ?>
266
+ </select>
267
+ </div>
268
+ <?php endif; ?>
269
+ </div>
270
+ <div class="field-settings-tab-container field-settings-apperance"
271
+ style="display:none;">
272
+ <?php if ( ! $is_custom_field || empty( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['disable_placeholder'] ) || ! $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['disable_placeholder'] ): ?>
273
+ <div class="field_placeholder">
274
+ <?php
275
+ $required = '';
276
+ if ( isset( $settings[ $key ][ $name ]['type'] ) && isset( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['label_is_required'] ) ) {
277
+ $required = ' required';
278
+ }
279
+ ?>
280
+ <label for="placeholder_<?php echo $name ?>"><?php if ( $is_custom_field && isset( $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['placeholder_label'] ) ): ?><?php echo $checkout_field_type[ $settings[ $key ][ $name ]['type'] ]['placeholder_label']; ?><?php else: ?><?php _e( 'Placeholder', 'flexible-checkout-fields' ) ?><?php endif; ?></label>
281
+
282
+ <input type="text" id="placeholder_<?php echo $name ?>"
283
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][placeholder]"
284
+ value="<?php if ( ! empty( $settings[ $key ][ $name ]['placeholder'] ) ): echo $settings[ $key ][ $name ]['placeholder'];
285
+ else: echo isset( $field['placeholder'] ) ? $field['placeholder'] : ''; endif; ?>" <?php echo $required; ?> />
286
+ </div>
287
+ <?php endif; ?>
288
+ <div>
289
+ <label for="class_<?php echo $name ?>"><?php _e( 'CSS Class', 'flexible-checkout-fields' ) ?></label>
290
+ <input type="text" id="class_<?php echo $name ?>"
291
+ name="inspire_checkout_fields[settings][<?php echo $key ?>][<?php echo $name ?>][class]"
292
+ value="<?php if ( ! empty( $settings[ $key ][ $name ]['class'] ) ): echo $settings[ $key ][ $name ]['class'];
293
+ else: if ( ! empty( $field['class'] ) ) {
294
+ echo implode( ' ', $field['class'] );
295
+ } endif; ?>"/>
296
+ </div>
297
+ </div>
298
+ <?php do_action( 'flexible_checkout_fields_field_tabs_content', $key, $name, $field, $settings ); ?>
299
  <?php if ( $is_custom_field ) : ?>
300
+ <a class="remove-field"
301
+ href="#"><?php _e( 'Delete Field', 'flexible-checkout-fields' ) ?></a>
302
  <?php endif; ?>
303
+ </div>
304
+ </li>
305
  <?php endforeach; ?>
306
+ </ul>
307
+ </div>
308
 
309
  <?php do_action( 'flexible_checkout_fields_section_settings', $key, $settings ); ?>
310
+
311
  <?php endforeach; ?>
312
 
313
+ <div id="nav-menu-footer">
314
+ <div class="major-publishing-actions wp-clearfix">
315
+ <input type="submit" name=""
316
+ value="<?php _e( 'Save Changes', 'flexible-checkout-fields' ) ?>"
317
+ class="button button-primary">
318
+ <input type="submit"
319
+ value="<?php _e( 'Reset Section Settings', 'flexible-checkout-fields' ); ?>"
320
+ class="button reset_settings" id="submit" name="reset_settings">
321
+ <span class="spinner"></span>
322
+ </div>
323
+ </div>
324
+ </div>
325
+ </form>
326
+ </div>
327
+ </div>
328
+ </div>
329
  </div>
330
 
331
  <script type="text/javascript">
332
+ jQuery(document).ready(function () {
333
+ jQuery('.sortable').sortable({
334
+ handle: '.field-item-handle',
335
+ placeholder: 'sortable-placeholder',
336
+ opacity: 0.7,
337
+ activate: function (event, ui) {
338
+ ui.item.find('.field-settings').hide();
339
+ }
340
+ });
341
+
342
+ // Add New Field
343
+ jQuery("#add-new-field").submit(function (e) {
344
+ var field_name = jQuery(this).find('#woocommerce_checkout_fields_field_name').val();
345
+ var field_section = jQuery(this).find('#woocommerce_checkout_fields_field_section').val();
346
+ var field_type = jQuery(this).find('#woocommerce_checkout_fields_field_type').val();
347
+ var field_option = jQuery(this).find('#woocommerce_checkout_fields_field_option').val();
348
+ //var field_slug = stringToSlug(field_section + '_' + field_name + '_' + Math.floor((Math.random() * 100000) + 1));
349
+ var field_slug = field_section + '_' + stringToSlug(field_name).substr(0, 20) + '_' + Math.floor((Math.random() * 100000) + 1);
350
+
351
+ // Proceed if Name (label) is filled
352
+ if (field_name) {
353
+ var html = '';
354
+ html += '<li class="field-item menu-item element_' + field_slug + ' just-added">';
355
+ html += '<div class="menu-item-bar">';
356
+ html += '<div class="menu-item-handle field-item-handle">';
357
+ html += '<input type="hidden" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][custom_field]" value="1">';
358
+ html += '<input type="hidden" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][name]" value="' + field_slug + '">';
359
+ html += '<span class="item-title">';
360
+ html += field_name;
361
+ html += '</span>';
362
+ html += '<span class="item-controls">';
363
+ html += '<a href="#" class="item-edit more"><?php _e( 'Edit', 'flexible-checkout-fields' ) ?></a>';
364
+ html += '</span>';
365
+ html += '</div>';
366
+ html += '</div>';
367
+ html += '<div class="menu-item-settings field-settings">';
368
+
369
+ html += '<div style="margin-bottom: -1px ! important;" class="nav-tab-wrapper">';
370
+ html += '<a href="#general" class="nav-tab nav-tab-active"><?php _e( 'General', 'flexible-checkout-fields' ); ?></a>';
371
+ html += '<a class="nav-tab" href="#apperance"><?php _e( 'Appearance', 'flexible-checkout-fields' ); ?></a>';
372
+ <?php
373
+ $additional_tabs = apply_filters( 'flexible_checkout_fields_field_tabs', array() );
374
+ foreach ( $additional_tabs as $additional_tab ) {
375
+ ?>
376
+ html += '<a class="nav-tab" href="#<?php echo $additional_tab['hash']; ?>"><?php echo $additional_tab['title']; ?></a>';
377
+ <?php
378
+ }
379
+ ?>
380
+ html += '</div>';
381
+ html += '<div class="field-settings-tab-container field-settings-general">';
382
+
383
+ <?php foreach ( $checkout_field_type as $key => $value ) : ?>
384
  <?php if ( isset( $value['description'] ) ) : ?>
385
+ html += '<div class="element-<?php echo $key; ?>-description">';
386
+ html += '<p class="description"><?php echo $value['description']; ?></p>';
387
+ html += '</div>';
388
  <?php endif; ?>
389
+ <?php endforeach; ?>
390
+ html += '<div>';
391
+ html += '<input type="hidden" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][visible]" value="1">';
392
+ html += '<label>';
393
+ html += '<input type="checkbox" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][visible]" value="0" checked>';
394
+ html += '<?php _e( 'Enable Field', 'flexible-checkout-fields' ) ?>';
395
+ html += '</label>';
396
+ html += '</div>';
397
+ html += '<div>';
398
+ html += '<input type="hidden" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][required]" value="0">';
399
+ html += '<label>';
400
+ html += '<input type="checkbox" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][required]" value="1">';
401
+ html += '<?php _e( 'Required Field', 'flexible-checkout-fields' ) ?>';
402
+ html += '</label>';
403
+ html += '</div>';
404
+ html += '<div class="field-type-label">';
405
+ html += '<label for="label_' + field_slug + '"><?php _e( 'Label', 'flexible-checkout-fields' ) ?></label>';
406
+ html += '<textarea id="label_' + field_slug + '" class="field-name" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][label]">' + field_name + '</textarea>';
407
+ html += '<p class="description"><?php _e( 'You can use HTML.', 'flexible-checkout-fields' ); ?></p>';
408
+ html += '</div>';
409
+
410
+ <?php do_action( 'flexible_checkout_fields_settings_js_html' ); ?>
411
+
412
+ html += '<div>';
413
+ html += '<label for="type_' + field_slug + '"><?php _e( 'Field Type', 'flexible-checkout-fields' ) ?></label>';
414
+ html += '<select id="woocommerce_checkout_fields_field_type" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][type]" disabled>' + printSelectTypeOptions(field_type) + '</select>';
415
+ html += '</div>';
416
+
417
+ html += '</div>';
418
+ html += '<div class="field-settings-tab-container field-settings-apperance" style="display:none;">';
419
+
420
+ html += '<div class="field_placeholder">';
421
+ html += '<label for="placeholder_' + field_slug + '"><?php _e( 'Placeholder', 'flexible-checkout-fields' ) ?></label>';
422
+ html += '<input type="text" id="placeholder_' + field_slug + '" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][placeholder]" value="">';
423
+ html += '</div>';
424
+ html += '<div>';
425
+ html += '<label for="class_' + field_slug + '"><?php _e( 'CSS Class', 'flexible-checkout-fields' ) ?></label>';
426
+ html += '<input type="text" id="class_' + field_slug + '" name="inspire_checkout_fields[settings][' + field_section + '][' + field_slug + '][class]" value="">';
427
+ html += '</div>';
428
+
429
+ html += '</div>';
430
+
431
+ <?php do_action( 'flexible_checkout_fields_field_tabs_content_js', $field ); ?>
432
+
433
+ html += '<a class="remove-field" href="#"><?php _e( 'Delete Field', 'flexible-checkout-fields' ) ?></a>';
434
+ html += '</li>';
435
+ html += '';
436
+
437
+ jQuery('#' + field_section).append(html);
438
+ jQuery('.element_' + field_slug + ' .element-file-description').hide();
439
+
440
+ // Add Field Options or Value or Placeholder
441
+ switch (field_type) {
442
+
443
+ <?php do_action( 'flexible_checkout_fields_settings_js_options' ); ?>
444
+
445
+ default:
446
+ jQuery('.element_' + field_slug + ' .field_placeholder label').html('<?php _e( 'Placeholder', 'flexible-checkout-fields' ); ?>');
447
+ jQuery('.element_' + field_slug + ' .field_placeholder').show();
448
+ break;
449
+ }
450
+
451
+ jQuery(this).find('#woocommerce_checkout_fields_field_name').val('');
452
+ }
453
+ // Display Alert if Name (label) is NOT filled
454
+ else {
455
+ alert('<?php _e( 'Enter field label!', 'flexible-checkout-fields' ) ?>');
456
  }
457
 
458
+ e.preventDefault();
459
+ });
 
 
 
 
460
 
461
+ // Toggle field settings
462
+ jQuery(document).on('click', '.field-item a.more', function (e) {
463
+ e.preventDefault();
464
+ jQuery(this).closest('.field-item').find('.field-settings').slideToggle('fast');
465
+ jQuery(this).closest('.field-item').toggleClass('menu-item-edit-active');
466
+ });
467
 
468
+ // Toggle between placeholder or value
469
+ jQuery(document).on('change', '.field-item .field-settings #woocommerce_checkout_fields_field_type', function (e) {
470
+ switch (jQuery(this).val()) {
471
+
472
+ default:
473
+ jQuery(this).closest('.field-item').find('.element-option').removeClass('show');
474
+ jQuery(this).closest('.field-item').find('.field_placeholder label').html('<?php _e( 'Placeholder', 'flexible-checkout-fields' ); ?>');
475
+ jQuery(this).closest('.field-item').find('.field_placeholder').show();
476
+ break;
477
+ }
478
+ e.preventDefault();
479
+ });
480
+
481
+ // Remove field
482
+ jQuery(document).on('click', '.field-item a.remove-field', function (e) {
483
+ e.preventDefault();
484
+ var toRemove = jQuery(this).closest('.field-item');
485
+ if (confirm('<?php _e( 'Do you really want to delete this field: ', 'flexible-checkout-fields' ) ?>' + toRemove.find('.field-name').val() + '?')) {
486
+ toRemove.remove();
487
+ }
488
+ });
489
+
490
+ // When Saving Form Remove disabled from Selects
491
+ jQuery('form').bind('submit', function () {
492
+ jQuery(this).find('select').prop('disabled', false);
493
+ jQuery(this).find('.major-publishing-actions').find('.spinner').css('visibility', 'visible');
494
+ jQuery('.flexible_checkout_fields_add_rule select').each(function () {
495
+ jQuery(this).attr('disabled', 'disabled');
496
+ });
497
+ });
498
+
499
+ // Activate Spinner on Save
500
+ jQuery('input[type="submit"]').on('click', function () {
501
+ jQuery('#inspire_checkout_field [required]').each(function () {
502
+ if (jQuery(this).val() == '' && jQuery(this).is(':hidden')) {
503
+ jQuery(this).closest('li').find('.item-controls>a').click();
504
+ }
505
+ if (jQuery(this).hasClass("reset_settings")) {
506
+ if (!confirm('<?php _e( 'Please confirm settings reset.', 'flexible-checkout-fields' ); ?>')) {
507
+ return false;
508
+ }
509
+ }
510
+ });
511
+
512
+
513
+ });
514
  });
515
 
516
+ <?php do_action( 'flexible_checkout_fields_java_script' ); ?>
517
+
518
+ jQuery(document).on('click', '.nav-tab-wrapper > a', function () {
519
+ jQuery(this).parent().find('a').each(function () {
520
+ jQuery(this).removeClass('nav-tab-active');
521
+ });
522
+ jQuery(this).addClass('nav-tab-active');
523
+ jQuery(this).parent().parent().find('.field-settings-tab-container').each(function () {
524
+ jQuery(this).hide();
525
+ });
526
+ var href = jQuery(this).attr("href");
527
+ var hash = href.substr(href.indexOf("#") + 1);
528
+ jQuery(this).parent().parent().find('.field-settings-' + hash).each(function () {
529
+ jQuery(this).show();
530
+ });
531
+ jQuery(this).blur();
532
+ return false;
533
  });
534
 
535
+ function printSelectTypeOptions(selected) {
536
+ var index;
537
+ var select;
538
+ var sel = "";
539
+
540
+ var type = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  <?php foreach ( $checkout_field_type as $key => $value ) : ?>
542
+ <?php echo $key; ?>:
543
+ '<?php echo $value['name']; ?>',
544
  <?php endforeach; ?>
545
+ }
546
+ ;
547
 
548
+ jQuery.each(type, function (key, value) {
549
+ if (key == selected) sel = " selected";
550
+ select += '<option value="' + key + '"' + sel + '>' + value + '</option>';
551
+ sel = "";
552
+ });
553
 
554
+ return select;
555
+ }
556
 
557
+ function stringToSlug(str) {
558
+ str = str.replace(/^\s+|\s+$/g, '');
559
+ str = str.toLowerCase();
560
 
561
+ var from = "àáäâèéëêìíïîòóöôùúüûñçęóąśłżźćń·/_,:;";
562
+ var to = "aaaaeeeeiiiioooouuuunceoaslzxcn------";
563
+ for (var i = 0, l = from.length; i < l; i++) {
564
+ str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
565
+ }
566
 
567
+ str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
568
+ .replace(/\s+/g, '_') // collapse whitespace and replace by -
569
+ .replace(/-+/g, '_'); // collapse dashes
570
 
571
+ return str;
572
+ }
573
 
574
  </script>
flexible-checkout-fields.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Flexible Checkout Fields
4
  Plugin URI: https://www.wpdesk.net/products/flexible-checkout-fields-pro-woocommerce/
5
  Description: Manage your WooCommerce checkout fields. Change order, labels, placeholders and add new fields.
6
- Version: 1.3.2
7
  Author: WP Desk
8
  Author URI: https://www.wpdesk.net/
9
  Text Domain: flexible-checkout-fields
@@ -29,6 +29,19 @@
29
 
30
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  require_once('class/inspire/plugin3.php');
33
  require_once('class/inspire/pluginDependant3.php');
34
  require_once('class/inspire/pluginPostTypeFactory3.php');
@@ -289,8 +302,9 @@
289
  $fields_found = true;
290
  foreach ( $type as $field_name => $field ) {
291
  if ( apply_filters( 'flexible_checkout_fields_condition', true, $field ) ) {
292
- if( $field['visible'] == 0 or
293
- ( ( isset( $_GET['page'] ) && $_GET['page'] == 'inspire_checkout_fields_settings' ) and $field['visible'] == 1) or $field['name'] == 'billing_country' or $field['name'] == 'shipping_country'){
 
294
  if ( isset( $fields[$key][$field['name']] ) ) {
295
  $new[$key][$field['name']] = $fields[$key][$field['name']];
296
  }
@@ -316,14 +330,14 @@
316
  else {
317
  $new[$key][$field['name']]['class'] = explode( ' ', $field['class'] );
318
  }
319
- if(($field['name'] == 'billing_country' or $field['name'] == 'shipping_country') and $field['visible'] == 1){
320
  $new[$key][$field['name']]['class'][1] = "inspire_checkout_fields_hide";
321
  }
322
 
323
  if( isset( $field['custom_field'] ) && $field['custom_field'] == 1 ){
324
  $new[$key][$field['name']]['type'] = $field['type'];
325
 
326
- if( isset($field['has_options'] ) ){
327
  $array_options = explode("\n", $field['option']);
328
  if(!empty($array_options)){
329
  foreach ($array_options as $option) {
@@ -354,7 +368,7 @@
354
  }
355
  }
356
  if ( $request_type == null ) {
357
- if(!empty($fields['account'])){
358
  $new['account'] = $fields['account'];
359
  }
360
  return $new;
@@ -374,7 +388,7 @@
374
 
375
  $checkout_field_type = $this->get_fields();
376
 
377
- if ( !empty($settings[$request_type] ) ){
378
  foreach ( $settings[$request_type] as $key => $field ) {
379
  if($field['visible'] == 0 or $field['name'] == 'billing_country' or $field['name'] == 'shipping_country' or ( isset($_GET['page']) && $_GET['page'] == 'inspire_checkout_fields_settings' and $field['visible'] == 1)){
380
 
@@ -417,10 +431,10 @@
417
  }
418
 
419
  if( isset( $field['type'] ) && ( !empty( $checkout_field_type[$field['type']]['has_options'] ) ) ) {
420
- $array_options = explode("\n", $field['option']);
421
- if(!empty($array_options)){
422
- foreach ($array_options as $option) {
423
- $tmp = explode(':', $option);
424
  $options[trim($tmp[0])] = wpdesk__( trim($tmp[1]), 'flexible-checkout-fields' );
425
  unset($tmp);
426
  }
@@ -432,7 +446,7 @@
432
  }
433
  return $new;
434
  }
435
- else{
436
  return $fields;
437
  }
438
  }
@@ -797,7 +811,7 @@
797
  *
798
  */
799
  function is_flexible_checkout_fields_pro_active() {
800
- return is_plugin_active( 'flexible-checkout-fields-pro/flexible-checkout-fields-pro.php' );
801
  }
802
 
803
  if ( !function_exists( 'wpdesk__' ) ) {
3
  Plugin Name: Flexible Checkout Fields
4
  Plugin URI: https://www.wpdesk.net/products/flexible-checkout-fields-pro-woocommerce/
5
  Description: Manage your WooCommerce checkout fields. Change order, labels, placeholders and add new fields.
6
+ Version: 1.3.3
7
  Author: WP Desk
8
  Author URI: https://www.wpdesk.net/
9
  Text Domain: flexible-checkout-fields
29
 
30
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
31
 
32
+ if ( !function_exists( 'wpdesk_is_plugin_active' ) ) {
33
+ function wpdesk_is_plugin_active( $plugin_file ) {
34
+
35
+ $active_plugins = (array) get_option( 'active_plugins', array() );
36
+
37
+ if ( is_multisite() ) {
38
+ $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
39
+ }
40
+
41
+ return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins );
42
+ }
43
+ }
44
+
45
  require_once('class/inspire/plugin3.php');
46
  require_once('class/inspire/pluginDependant3.php');
47
  require_once('class/inspire/pluginPostTypeFactory3.php');
302
  $fields_found = true;
303
  foreach ( $type as $field_name => $field ) {
304
  if ( apply_filters( 'flexible_checkout_fields_condition', true, $field ) ) {
305
+ if ( $field['visible'] == 0 or
306
+ ( ( isset( $_GET['page'] ) && $_GET['page'] == 'inspire_checkout_fields_settings' ) and $field['visible'] == 1) or $field['name'] == 'billing_country' or $field['name'] == 'shipping_country')
307
+ {
308
  if ( isset( $fields[$key][$field['name']] ) ) {
309
  $new[$key][$field['name']] = $fields[$key][$field['name']];
310
  }
330
  else {
331
  $new[$key][$field['name']]['class'] = explode( ' ', $field['class'] );
332
  }
333
+ if ( ($field['name'] == 'billing_country' or $field['name'] == 'shipping_country') and $field['visible'] == 1 ){
334
  $new[$key][$field['name']]['class'][1] = "inspire_checkout_fields_hide";
335
  }
336
 
337
  if( isset( $field['custom_field'] ) && $field['custom_field'] == 1 ){
338
  $new[$key][$field['name']]['type'] = $field['type'];
339
 
340
+ if ( isset( $checkout_field_type[$field['type']]['has_options'] ) ){
341
  $array_options = explode("\n", $field['option']);
342
  if(!empty($array_options)){
343
  foreach ($array_options as $option) {
368
  }
369
  }
370
  if ( $request_type == null ) {
371
+ if ( !empty($fields['account'] ) ) {
372
  $new['account'] = $fields['account'];
373
  }
374
  return $new;
388
 
389
  $checkout_field_type = $this->get_fields();
390
 
391
+ if ( !empty($settings[$request_type] ) ) {
392
  foreach ( $settings[$request_type] as $key => $field ) {
393
  if($field['visible'] == 0 or $field['name'] == 'billing_country' or $field['name'] == 'shipping_country' or ( isset($_GET['page']) && $_GET['page'] == 'inspire_checkout_fields_settings' and $field['visible'] == 1)){
394
 
431
  }
432
 
433
  if( isset( $field['type'] ) && ( !empty( $checkout_field_type[$field['type']]['has_options'] ) ) ) {
434
+ $array_options = explode( "\n", $field['option'] );
435
+ if ( !empty( $array_options ) ) {
436
+ foreach ( $array_options as $option ) {
437
+ $tmp = explode( ':', $option );
438
  $options[trim($tmp[0])] = wpdesk__( trim($tmp[1]), 'flexible-checkout-fields' );
439
  unset($tmp);
440
  }
446
  }
447
  return $new;
448
  }
449
+ else {
450
  return $fields;
451
  }
452
  }
811
  *
812
  */
813
  function is_flexible_checkout_fields_pro_active() {
814
+ return wpdesk_is_plugin_active( 'flexible-checkout-fields-pro/flexible-checkout-fields-pro.php' );
815
  }
816
 
817
  if ( !function_exists( 'wpdesk__' ) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.wpdesk.net/flexible-checkout-fields-woocommerce/
4
  Tags: woocommerce checkout, woocommerce checkout fields, flexible checkout fields, woocommerce checkout manager, woocommerce checkout editor, woocommerce fields manager, woocommerce fields editor, woocommerce custom checkout fields, woocommerce checkout options, woocommerce checkout pro, woocommerce custom sections, woocommerce file upload
5
  Requires at least: 4.0
6
  Tested up to: 4.6.1
7
- Stable tag: 1.3.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -142,8 +142,12 @@ If you are upgrading from the old WooCommerce Checkout Fields version (1.1, wooc
142
 
143
  == Changelog ==
144
 
 
 
 
 
145
  = 1.3.2 - 2016-11-23 =
146
- * Limit field name to 20 characters in order to prevent DB problems (this only behind the scenes, labels and user all visible elements remain intact)
147
 
148
  = 1.3.1 - 2016-10-24 =
149
  * Fixed resetting section's settings which blocked ability to edit fields in the order
4
  Tags: woocommerce checkout, woocommerce checkout fields, flexible checkout fields, woocommerce checkout manager, woocommerce checkout editor, woocommerce fields manager, woocommerce fields editor, woocommerce custom checkout fields, woocommerce checkout options, woocommerce checkout pro, woocommerce custom sections, woocommerce file upload
5
  Requires at least: 4.0
6
  Tested up to: 4.6.1
7
+ Stable tag: 1.3.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
142
 
143
  == Changelog ==
144
 
145
+ = 1.3.3 - 2016-11-28 =
146
+ * Fixed radio buttons saving
147
+ * Strip tags from labels when viewing fields settings
148
+
149
  = 1.3.2 - 2016-11-23 =
150
+ * Limit field names to 20 characters in order to prevent DB problems (this is only behind the scenes, labels and all user visible elements remain intact)
151
 
152
  = 1.3.1 - 2016-10-24 =
153
  * Fixed resetting section's settings which blocked ability to edit fields in the order