WooCommerce Checkout Field Editor (Manager) Pro - Version 1.2.8

Version Description

  • Fix for the issue of displaying 'Optional' text for required fields.
Download this release

Release Info

Developer ThemeHigh
Plugin Icon 128x128 WooCommerce Checkout Field Editor (Manager) Pro
Version 1.2.8
Comparing to
See all releases

Code changes from version 1.2.5 to 1.2.8

assets/css/thwcfd-style.css CHANGED
@@ -1,150 +1,154 @@
1
- .woocommerce-message {
2
- margin-top: 10px;
3
- }
4
- #wc_checkout_fields {
5
- margin-top: 10px;
6
- }
7
- #wc_checkout_fields thead th input {
8
- margin: 2px 0 0 0 !important;
9
- }
10
- #wc_checkout_fields tbody .description {
11
- display: none;
12
- color: #999;
13
- }
14
- #wc_checkout_fields tbody td {
15
- overflow: visible !important;
16
- padding: 7px;
17
- cursor: move;
18
- vertical-align: middle;
19
- }
20
- #wc_checkout_fields tbody td:last-child,
21
- #wc_checkout_fields tbody th:last-child {
22
- padding-right: 14px;
23
- }
24
- #wc_checkout_fields tbody input.input-text,
25
- #wc_checkout_fields tbody td select {
26
- width: 100%;
27
- }
28
- #wc_checkout_fields tfoot .description {
29
- color: #999;
30
- }
31
- #wc_checkout_fields .check-column {
32
- padding: 7px 0 7px 14px;
33
- }
34
- #wc_checkout_fields strong.core-field {
35
- color: #a4688d;
36
- }
37
- #wc_checkout_fields .field-type,
38
- #wc_checkout_fields .field-options,
39
- #wc_checkout_fields span.na,
40
- #wc_checkout_fields .field-validation {
41
- text-align: center;
42
- color: #aaa;
43
- }
44
- #wc_checkout_fields .field-type select,
45
- #wc_checkout_fields .field-options select,
46
- #wc_checkout_fields span.na select,
47
- #wc_checkout_fields .field-validation select,
48
- #wc_checkout_fields .field-type div,
49
- #wc_checkout_fields .field-options div,
50
- #wc_checkout_fields span.na div,
51
- #wc_checkout_fields .field-validation div,
52
- #wc_checkout_fields .field-type input,
53
- #wc_checkout_fields .field-options input,
54
- #wc_checkout_fields span.na input,
55
- #wc_checkout_fields .field-validation input {
56
- text-align: left;
57
- }
58
- #wc_checkout_fields span.na {
59
- display: block;
60
- }
61
- #wc_checkout_fields .clear {
62
- text-align: center;
63
- }
64
- #wc_checkout_fields tr.disabled td {
65
- opacity: 0.3;
66
- text-decoration: line-through;
67
- }
68
- #wc_checkout_fields tr.disabled td:first-child {
69
- opacity:1;
70
- }
71
- tr.strikeout1 td:before {
72
- content: " ";
73
- position: absolute;
74
- top: 50%;
75
- left: 0;
76
- border-bottom: 1px solid #FF0000;
77
- width: 100%;
78
- }
79
-
80
- #wcfd_checkout_fields tr.strikeout td {
81
- background: rgba(255, 0, 0, .4)!important;
82
- opacity: 0.6;
83
- text-decoration: line-through;
84
- }
85
-
86
- #wcfd_checkout_fields tr.thwcfd-disabled td {
87
- opacity: 0.4;
88
- }
89
- #wcfd_checkout_fields tr.thwcfd-disabled td.td_select {
90
- opacity: 1;
91
- }
92
-
93
- .err_msgs{
94
- color: #FF0000;
95
- }
96
-
97
- .thwcfd-sections {
98
- list-style: outside none none;
99
- margin: 8px 0 0;
100
- padding: 0;
101
- font-size: 13px;
102
- color: #666;
103
- }
104
- .thwcfd-sections li {
105
- display: inline-block;
106
- margin: 0px;
107
- padding: 0px;
108
- white-space: nowrap;
109
- }
110
- .thwcfd-sections a.current {
111
- font-weight: 600;
112
- border: medium none;
113
- color: #000;
114
- }
115
- .thwcfd-sections a {
116
- line-height: 2;
117
- padding: 0.2em;
118
- text-decoration: none;
119
- }
120
-
121
- .thwcfd-notice a {
122
- display:block;
123
- padding:0;
124
- height: 63px;
125
- }
126
- .thwcfd-notice p {
127
- margin-bottom:0px;
128
- }
129
- .thwcfd-notice ul {
130
- list-style-type: none;
131
- margin: 0px;
132
- }
133
- .thwcfd-notice ul li {
134
- background:url("tick.png") no-repeat 0 50%;
135
- padding-left: 20px;
136
- }
137
-
138
- .wcfd_popup_wrapper input[type="text"]:disabled, .wcfd_popup_wrapper select:disabled {
139
- background: #f6f6f6;
140
- }
141
-
142
- h1.nav-tab-wrapper, h2.nav-tab-wrapper, h3.nav-tab-wrapper {
143
- border-bottom: 1px solid #CCC;
144
- padding-bottom: 0px;
145
- padding-left: 10px;
146
- }
147
-
148
- /*.select2-drop {
149
- z-index: 999999!important;
 
 
 
 
150
  }*/
1
+ .woocommerce-message {
2
+ margin-top: 10px;
3
+ }
4
+ #wc_checkout_fields {
5
+ margin-top: 10px;
6
+ }
7
+ #wc_checkout_fields thead th input {
8
+ margin: 2px 0 0 0 !important;
9
+ }
10
+ #wc_checkout_fields tbody .description {
11
+ display: none;
12
+ color: #999;
13
+ }
14
+ #wc_checkout_fields tbody td {
15
+ overflow: visible !important;
16
+ padding: 7px;
17
+ cursor: move;
18
+ vertical-align: middle;
19
+ }
20
+ #wc_checkout_fields tbody td:last-child,
21
+ #wc_checkout_fields tbody th:last-child {
22
+ padding-right: 14px;
23
+ }
24
+ #wc_checkout_fields tbody input.input-text,
25
+ #wc_checkout_fields tbody td select {
26
+ width: 100%;
27
+ }
28
+ #wc_checkout_fields tfoot .description {
29
+ color: #999;
30
+ }
31
+ #wc_checkout_fields .check-column {
32
+ padding: 7px 0 7px 14px;
33
+ }
34
+ #wc_checkout_fields strong.core-field {
35
+ color: #a4688d;
36
+ }
37
+ #wc_checkout_fields .field-type,
38
+ #wc_checkout_fields .field-options,
39
+ #wc_checkout_fields span.na,
40
+ #wc_checkout_fields .field-validation {
41
+ text-align: center;
42
+ color: #aaa;
43
+ }
44
+ #wc_checkout_fields .field-type select,
45
+ #wc_checkout_fields .field-options select,
46
+ #wc_checkout_fields span.na select,
47
+ #wc_checkout_fields .field-validation select,
48
+ #wc_checkout_fields .field-type div,
49
+ #wc_checkout_fields .field-options div,
50
+ #wc_checkout_fields span.na div,
51
+ #wc_checkout_fields .field-validation div,
52
+ #wc_checkout_fields .field-type input,
53
+ #wc_checkout_fields .field-options input,
54
+ #wc_checkout_fields span.na input,
55
+ #wc_checkout_fields .field-validation input {
56
+ text-align: left;
57
+ }
58
+ #wc_checkout_fields span.na {
59
+ display: block;
60
+ }
61
+ #wc_checkout_fields .clear {
62
+ text-align: center;
63
+ }
64
+ #wc_checkout_fields tr.disabled td {
65
+ opacity: 0.3;
66
+ text-decoration: line-through;
67
+ }
68
+ #wc_checkout_fields tr.disabled td:first-child {
69
+ opacity:1;
70
+ }
71
+ tr.strikeout1 td:before {
72
+ content: " ";
73
+ position: absolute;
74
+ top: 50%;
75
+ left: 0;
76
+ border-bottom: 1px solid #FF0000;
77
+ width: 100%;
78
+ }
79
+
80
+ #wcfd_checkout_fields tr.strikeout td {
81
+ background: rgba(255, 0, 0, .4)!important;
82
+ opacity: 0.6;
83
+ text-decoration: line-through;
84
+ }
85
+
86
+ #wcfd_checkout_fields tr.thwcfd-disabled td {
87
+ opacity: 0.4;
88
+ }
89
+ #wcfd_checkout_fields tr.thwcfd-disabled td.td_select {
90
+ opacity: 1;
91
+ }
92
+
93
+ .err_msgs{
94
+ color: #FF0000;
95
+ }
96
+
97
+ .thwcfd-sections {
98
+ list-style: outside none none;
99
+ margin: 8px 0 0;
100
+ padding: 0;
101
+ font-size: 13px;
102
+ color: #666;
103
+ }
104
+ .thwcfd-sections li {
105
+ display: inline-block;
106
+ margin: 0px;
107
+ padding: 0px;
108
+ white-space: nowrap;
109
+ }
110
+ .thwcfd-sections a.current {
111
+ font-weight: 600;
112
+ border: medium none;
113
+ color: #000;
114
+ }
115
+ .thwcfd-sections a {
116
+ line-height: 2;
117
+ padding: 0.2em;
118
+ text-decoration: none;
119
+ }
120
+
121
+ .thwcfd-notice a {
122
+ display:block;
123
+ padding:0;
124
+ height: 63px;
125
+ }
126
+ .thwcfd-notice p {
127
+ margin-bottom:0px;
128
+ }
129
+ .thwcfd-notice ul {
130
+ list-style-type: none;
131
+ margin: 0px;
132
+ }
133
+ .thwcfd-notice ul li {
134
+ background:url("tick.png") no-repeat 0 50%;
135
+ padding-left: 20px;
136
+ }
137
+
138
+ .wcfd_popup_wrapper input[type="text"]:disabled, .wcfd_popup_wrapper select:disabled {
139
+ background: #f6f6f6;
140
+ }
141
+
142
+ h1.nav-tab-wrapper, h2.nav-tab-wrapper, h3.nav-tab-wrapper {
143
+ border-bottom: 1px solid #CCC;
144
+ padding-bottom: 0px;
145
+ padding-left: 10px;
146
+ }
147
+
148
+ .woocommerce_page_checkout_form_designer .ui-dialog .ui-dialog-title {
149
+ line-height: 20px;
150
+ }
151
+
152
+ /*.select2-drop {
153
+ z-index: 999999!important;
154
  }*/
assets/js/thwcfd-admin.js CHANGED
@@ -1,458 +1,458 @@
1
- var wcfd_settings = (function($, window, document) {
2
- var MSG_INVALID_NAME = 'NAME/ID must begin with a lowercase letter ([a-z]) and may be followed by any number of lowercase letters, digits ([0-9]) and underscores ("_")';
3
-
4
- $( "#wcfd_new_field_form_pp" ).dialog({
5
- modal: true,
6
- width: 500,
7
- //height: 400,
8
- resizable: false,
9
- autoOpen: false,
10
- buttons: [{
11
- text: "Add New Field",
12
- click: function() {
13
- var result = wcfd_add_new_row( this );
14
- if(result){
15
- $( this ).dialog( "close" );
16
- }
17
- }
18
- }]
19
- });
20
-
21
- $( "#wcfd_edit_field_form_pp" ).dialog({
22
- modal: true,
23
- width: 500,
24
- //height: 400,
25
- resizable: false,
26
- autoOpen: false,
27
- buttons: [{
28
- text: "Edit Field",
29
- click: function() {
30
- var result = wcfd_update_row( this );
31
- if(result){
32
- $( this ).dialog( "close" );
33
- }
34
- }
35
- }]
36
- });
37
-
38
- $('select.thwcfd-enhanced-multi-select').select2({
39
- minimumResultsForSearch: 10,
40
- allowClear : true,
41
- placeholder: $(this).data('placeholder')
42
- }).addClass('enhanced');
43
-
44
- $( ".wcfd_remove_field_btn" ).click( function() {
45
- var form = $(this.form);
46
-
47
- $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
48
- $(this).closest('tr').remove();
49
- });
50
- });
51
-
52
- $('#wcfd_checkout_fields tbody').sortable({
53
- items:'tr',
54
- cursor:'move',
55
- axis:'y',
56
- handle: 'td.sort',
57
- scrollSensitivity:40,
58
- helper:function(e,ui){
59
- ui.children().each(function(){
60
- $(this).width($(this).width());
61
- });
62
- ui.css('left', '0');
63
- return ui;
64
- }
65
- });
66
-
67
- $("#wcfd_checkout_fields tbody").on("sortstart", function( event, ui ){
68
- ui.item.css('background-color','#f6f6f6');
69
- });
70
- $("#wcfd_checkout_fields tbody").on("sortstop", function( event, ui ){
71
- ui.item.removeAttr('style');
72
- wcfd_prepare_field_order_indexes();
73
- });
74
-
75
- _openNewFieldForm = function openNewFieldForm(tabName){
76
- if(tabName == 'billing' || tabName == 'shipping' || tabName == 'additional'){
77
- tabName = tabName+'_';
78
- }
79
-
80
- var form = $("#wcfd_new_field_form_pp");
81
- wcfd_clear_form(form);
82
- form.find("input[name=fname]").val(tabName);
83
- form.find("select[name=ftype]").change();
84
- form.find("input[name=fclass]").val('form-row-wide');
85
-
86
- $( "#wcfd_new_field_form_pp" ).dialog( "open" );
87
- }
88
-
89
- function wcfd_add_new_row(form){
90
- var name = $(form).find("input[name=fname]").val();
91
- var type = $(form).find("select[name=ftype]").val();
92
- var label = $(form).find("input[name=flabel]").val();
93
- var placeholder = $(form).find("input[name=fplaceholder]").val();
94
- var optionsList = $(form).find("input[name=foptions]").val();
95
-
96
- var fieldClass = $(form).find("input[name=fclass]").val();
97
- var labelClass = $(form).find("input[name=flabelclass]").val();
98
-
99
- var required = $(form).find("input[name=frequired]").prop('checked');
100
- var clearRow = $(form).find("input[name=fclearRow]").prop('checked');
101
- var enabled = $(form).find("input[name=fenabled]").prop('checked');
102
-
103
- var showinemail = $(form).find("input[name=fshowinemail]").prop('checked');
104
- var showinorder = $(form).find("input[name=fshowinorder]").prop('checked');
105
-
106
- var validations = $(form).find("select[name=fvalidate]").val();
107
-
108
- var err_msgs = '';
109
- if(name == ''){
110
- err_msgs = 'Name is required';
111
- }else if(!isHtmlIdValid(name)){
112
- err_msgs = MSG_INVALID_NAME;
113
- }else if(type == ''){
114
- err_msgs = 'Type is required';
115
- }
116
-
117
- if(err_msgs != ''){
118
- $(form).find('.err_msgs').html(err_msgs);
119
- return false;
120
- }
121
-
122
- required = required ? 1 : 0;
123
- clearRow = clearRow ? 1 : 0;
124
- enabled = enabled ? 1 : 0;
125
-
126
- showinemail = showinemail ? 1 : 0;
127
- showinorder = showinorder ? 1 : 0;
128
-
129
- validations = validations ? validations : '';
130
-
131
- var index = $('#wcfd_checkout_fields tbody tr').size();
132
-
133
- var newRow = '<tr class="row_'+index+'">';
134
- newRow += '<td width="1%" class="sort ui-sortable-handle">';
135
- newRow += '<input type="hidden" name="f_order['+index+']" class="f_order" value="'+index+'" />';
136
- newRow += '<input type="hidden" name="f_name['+index+']" class="f_name" value="" />';
137
- newRow += '<input type="hidden" name="f_name_new['+index+']" class="f_name_new" value="'+name+'" />';
138
- newRow += '<input type="hidden" name="f_type['+index+']" class="f_type" value="'+type+'" />';
139
- newRow += '<input type="hidden" name="f_label['+index+']" class="f_label" value="'+label+'" />';
140
- newRow += '<input type="hidden" name="f_placeholder['+index+']" class="f_placeholder" value="'+placeholder+'" />';
141
- newRow += '<input type="hidden" name="f_options['+index+']" class="f_options" value="'+optionsList+'" />';
142
-
143
- newRow += '<input type="hidden" name="f_class['+index+']" class="f_class" value="'+fieldClass+'" />';
144
- newRow += '<input type="hidden" name="f_label_class['+index+']" class="f_label_class" value="'+labelClass+'" />';
145
-
146
- newRow += '<input type="hidden" name="f_required['+index+']" class="f_required" value="'+required+'" />';
147
- newRow += '<input type="hidden" name="f_clear['+index+']" class="f_clear" value="'+clearRow+'" />';
148
- newRow += '<input type="hidden" name="f_enabled['+index+']" class="f_enabled" value="'+enabled+'" />';
149
-
150
- newRow += '<input type="hidden" name="f_show_in_email['+index+']" class="f_show_in_email" value="'+showinemail+'" />';
151
- newRow += '<input type="hidden" name="f_show_in_order['+index+']" class="f_show_in_order" value="'+showinorder+'" />';
152
-
153
- newRow += '<input type="hidden" name="f_validation['+index+']" class="f_validation" value="'+validations+'" />';
154
- newRow += '<input type="hidden" name="f_deleted['+index+']" class="f_deleted" value="0" />';
155
- newRow += '</td>';
156
- newRow += '<td ><input type="checkbox" /></td>';
157
- newRow += '<td class="name">'+name+'</td>';
158
- newRow += '<td class="id">'+type+'</td>';
159
- newRow += '<td>'+label+'</td>';
160
- newRow += '<td>'+placeholder+'</td>';
161
- newRow += '<td>'+validations+'</td>';
162
- if(required == true){
163
- newRow += '<td class="status"><span class="status-enabled tips">Yes</span></td>';
164
- }else{
165
- newRow += '<td class="status">-</td>';
166
- }
167
- if(clearRow == true){
168
- newRow += '<td class="status"><span class="status-enabled tips">Yes</span></td>';
169
- }else{
170
- newRow += '<td class="status">-</td>';
171
- }
172
- if(enabled == true){
173
- newRow += '<td class="status"><span class="status-enabled tips">Yes</span></td>';
174
- }else{
175
- newRow += '<td class="status">-</td>';
176
- }
177
-
178
- newRow += '<td><button type="button" onclick="openEditFieldForm(this)">Edit</button></td>';
179
- newRow += '</tr>';
180
-
181
- $('#wcfd_checkout_fields tbody tr:last').after(newRow);
182
- return true;
183
- }
184
-
185
- _openEditFieldForm = function openEditFieldForm(elm, rowId){
186
- var row = $(elm).closest('tr')
187
-
188
- var is_custom = row.find(".f_custom").val();
189
- var name = row.find(".f_name").val();
190
- var type = row.find(".f_type").val();
191
- var label = row.find(".f_label").val();
192
- var placeholder = row.find(".f_placeholder").val();
193
- var optionsList = row.find(".f_options").val();
194
-
195
- var field_classes = row.find(".f_class").val();
196
- var label_classes = row.find(".f_label_class").val();
197
-
198
- var required = row.find(".f_required").val();
199
- var clearRow = row.find(".f_clear").val();
200
-
201
- var enabled = row.find(".f_enabled").val();
202
- var validations = row.find(".f_validation").val();
203
-
204
- var showinemail = row.find(".f_show_in_email").val();
205
- var showinorder = row.find(".f_show_in_order").val();
206
-
207
- is_custom = is_custom == 1 ? true : false;
208
-
209
- required = required == 1 ? true : false;
210
- clearRow = clearRow == 1 ? true : false;
211
- enabled = enabled == 1 ? true : false;
212
-
213
- validations = validations.split(",");
214
-
215
- showinemail = showinemail == 1 ? true : false;
216
- showinorder = showinorder == 1 ? true : false;
217
-
218
- showinemail = is_custom == true ? showinemail : true;
219
- showinorder = is_custom == true ? showinorder : true;
220
-
221
- var form = $("#wcfd_edit_field_form_pp");
222
- form.find('.err_msgs').html('');
223
- form.find("input[name=rowId]").val(rowId);
224
- form.find("input[name=fname]").val(name);
225
- form.find("input[name=fnameNew]").val(name);
226
- form.find("select[name=ftype]").val(type);
227
- form.find("input[name=flabel]").val(label);
228
- form.find("input[name=fplaceholder]").val(placeholder);
229
- form.find("input[name=foptions]").val(optionsList);
230
-
231
- form.find("input[name=fclass]").val(field_classes);
232
- form.find("input[name=flabelclass]").val(label_classes);
233
- form.find("select[name=fvalidate]").val(validations).trigger("change");
234
-
235
- form.find("input[name=frequired]").prop('checked', required);
236
- form.find("input[name=fclearRow]").prop('checked', clearRow);
237
- form.find("input[name=fenabled]").prop('checked', enabled);
238
-
239
- form.find("input[name=fshowinemail]").prop('checked', showinemail);
240
- form.find("input[name=fshowinorder]").prop('checked', showinorder);
241
-
242
- form.find("select[name=ftype]").change();
243
- $( "#wcfd_edit_field_form_pp" ).dialog( "open" );
244
-
245
- /*if(type == 'email' || type == 'tel' || type == 'country' || type == 'state'){
246
-
247
- }*/
248
-
249
- if(is_custom == false){
250
- form.find("input[name=fnameNew]").prop('disabled', true);
251
- form.find("select[name=ftype]").prop('disabled', true);
252
- form.find("input[name=fshowinemail]").prop('disabled', true);
253
- form.find("input[name=fshowinorder]").prop('disabled', true);
254
- form.find("input[name=flabel]").focus();
255
- }else{
256
- form.find("input[name=fnameNew]").prop('disabled', false);
257
- form.find("select[name=ftype]").prop('disabled', false);
258
- form.find("input[name=fshowinemail]").prop('disabled', false);
259
- form.find("input[name=fshowinorder]").prop('disabled', false);
260
- }
261
- }
262
-
263
- function wcfd_update_row(form){
264
- var rowId = $(form).find("input[name=rowId]").val();
265
-
266
- var name = $(form).find("input[name=fnameNew]").val();
267
- var type = $(form).find("select[name=ftype]").val();
268
- var label = $(form).find("input[name=flabel]").val();
269
- var placeholder = $(form).find("input[name=fplaceholder]").val();
270
- var optionsList = $(form).find("input[name=foptions]").val();
271
-
272
- var fieldClass = $(form).find("input[name=fclass]").val();
273
- var labelClass = $(form).find("input[name=flabelclass]").val();
274
-
275
- var required = $(form).find("input[name=frequired]").prop('checked');
276
- var clearRow = $(form).find("input[name=fclearRow]").prop('checked');
277
- var enabled = $(form).find("input[name=fenabled]").prop('checked');
278
-
279
- var showinemail = $(form).find("input[name=fshowinemail]").prop('checked');
280
- var showinorder = $(form).find("input[name=fshowinorder]").prop('checked');
281
-
282
- var validations = $(form).find("select[name=fvalidate]").val();
283
-
284
- var err_msgs = '';
285
- if(name == ''){
286
- err_msgs = 'Name is required';
287
- }else if(!isHtmlIdValid(name)){
288
- err_msgs = MSG_INVALID_NAME;
289
- }else if(type == ''){
290
- err_msgs = 'Type is required';
291
- }
292
-
293
- if(err_msgs != ''){
294
- $(form).find('.err_msgs').html(err_msgs);
295
- return false;
296
- }
297
-
298
- required = required ? 1 : 0;
299
- clearRow = clearRow ? 1 : 0;
300
- enabled = enabled ? 1 : 0;
301
-
302
- showinemail = showinemail ? 1 : 0;
303
- showinorder = showinorder ? 1 : 0;
304
-
305
- validations = validations ? validations : '';
306
-
307
- var row = $('#wcfd_checkout_fields tbody').find('.row_'+rowId);
308
- row.find(".f_name").val(name);
309
- row.find(".f_type").val(type);
310
- row.find(".f_label").val(label);
311
- row.find(".f_placeholder").val(placeholder);
312
- row.find(".f_options").val(optionsList);
313
-
314
- row.find(".f_class").val(fieldClass);
315
- row.find(".f_label_class").val(labelClass);
316
-
317
- row.find(".f_required").val(required);
318
- row.find(".f_clear").val(clearRow);
319
- row.find(".f_enabled").val(enabled);
320
-
321
- row.find(".f_show_in_email").val(showinemail);
322
- row.find(".f_show_in_order").val(showinorder);
323
- row.find(".f_validation").val(validations);
324
-
325
- row.find(".td_name").html(name);
326
- row.find(".td_type").html(type);
327
- row.find(".td_label").html(label);
328
- row.find(".td_placeholder").html(placeholder);
329
- row.find(".td_validate").html(""+validations+"");
330
- row.find(".td_required").html(required == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
331
- row.find(".td_clear").html(clearRow == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
332
- row.find(".td_enabled").html(enabled == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
333
- return true;
334
- }
335
-
336
- _removeSelectedFields = function removeSelectedFields(){
337
- $('#wcfd_checkout_fields tbody tr').removeClass('strikeout');
338
- $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
339
- //$(this).closest('tr').remove();
340
- var row = $(this).closest('tr');
341
- if(!row.hasClass("strikeout")){
342
- row.addClass("strikeout");
343
- }
344
- row.find(".f_deleted").val(1);
345
- row.find(".f_edit_btn").prop('disabled', true);
346
- //row.find('.sort').removeClass('sort');
347
- });
348
- }
349
-
350
- _enableDisableSelectedFields = function enableDisableSelectedFields(enabled){
351
- $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
352
- var row = $(this).closest('tr');
353
- if(enabled == 0){
354
- if(!row.hasClass("thwcfd-disabled")){
355
- row.addClass("thwcfd-disabled");
356
- }
357
- }else{
358
- row.removeClass("thwcfd-disabled");
359
- }
360
-
361
- row.find(".f_edit_btn").prop('disabled', enabled == 1 ? false : true);
362
- row.find(".td_enabled").html(enabled == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
363
- row.find(".f_enabled").val(enabled);
364
- });
365
- }
366
-
367
- function wcfd_clear_form( form ){
368
- form.find('.err_msgs').html('');
369
- form.find("input[name=fname]").val('');
370
- form.find("input[name=fnameNew]").val('');
371
- form.find("select[name=ftype]").prop('selectedIndex',0);
372
- form.find("input[name=flabel]").val('');
373
- form.find("input[name=fplaceholder]").val('');
374
- form.find("input[name=foptions]").val('');
375
-
376
- form.find("input[name=fclass]").val('');
377
- form.find("input[name=flabelclass]").val('');
378
- form.find("select[name=fvalidate] option:selected").removeProp('selected');
379
-
380
- form.find("input[name=frequired]").prop('checked', true);
381
- form.find("input[name=fclearRow]").prop('checked', true);
382
- form.find("input[name=fenabled]").prop('checked', true);
383
- form.find("input[name=fshowinemail]").prop('checked', true);
384
- form.find("input[name=fshowinorder]").prop('checked', true);
385
- }
386
-
387
- function wcfd_prepare_field_order_indexes() {
388
- $('#wcfd_checkout_fields tbody tr').each(function(index, el){
389
- $('input.f_order', el).val( parseInt( $(el).index('#wcfd_checkout_fields tbody tr') ) );
390
- });
391
- };
392
-
393
- _fieldTypeChangeListner = function fieldTypeChangeListner(elm){
394
- var type = $(elm).val();
395
- var form = $(elm).closest('form');
396
-
397
- showAllFields(form);
398
- if(type === 'select'){
399
- //form.find('.rowPlaceholder').hide();
400
- form.find('.rowValidate').hide();
401
- }else{
402
- form.find('.rowOptions').hide();
403
- }
404
- }
405
-
406
- function showAllFields(form){
407
- form.find('.rowOptions').show();
408
- form.find('.rowPlaceholder').show();
409
- form.find('.rowValidate').show();
410
- }
411
-
412
- _selectAllCheckoutFields = function selectAllCheckoutFields(elm){
413
- var checkAll = $(elm).prop('checked');
414
- $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]').prop('checked', checkAll);
415
- }
416
-
417
- function isHtmlIdValid(id) {
418
- var re = /^[a-z\_]+[a-z0-9\_]*$/;
419
- return re.test(id.trim());
420
- }
421
-
422
- return {
423
- openNewFieldForm : _openNewFieldForm,
424
- openEditFieldForm : _openEditFieldForm,
425
- removeSelectedFields : _removeSelectedFields,
426
- enableDisableSelectedFields : _enableDisableSelectedFields,
427
- fieldTypeChangeListner : _fieldTypeChangeListner,
428
- selectAllCheckoutFields : _selectAllCheckoutFields,
429
- };
430
- }(window.jQuery, window, document));
431
-
432
- function openNewFieldForm(tabName){
433
- wcfd_settings.openNewFieldForm(tabName);
434
- }
435
-
436
- function openEditFieldForm(elm, rowId){
437
- wcfd_settings.openEditFieldForm(elm, rowId);
438
- }
439
-
440
- function removeSelectedFields(){
441
- wcfd_settings.removeSelectedFields();
442
- }
443
-
444
- function enableSelectedFields(){
445
- wcfd_settings.enableDisableSelectedFields(1);
446
- }
447
-
448
- function disableSelectedFields(){
449
- wcfd_settings.enableDisableSelectedFields(0);
450
- }
451
-
452
- function fieldTypeChangeListner(elm){
453
- wcfd_settings.fieldTypeChangeListner(elm);
454
- }
455
-
456
- function thwcfdSelectAllCheckoutFields(elm){
457
- wcfd_settings.selectAllCheckoutFields(elm);
458
  }
1
+ var wcfd_settings = (function($, window, document) {
2
+ var MSG_INVALID_NAME = 'NAME/ID must begin with a lowercase letter ([a-z]) and may be followed by any number of lowercase letters, digits ([0-9]) and underscores ("_")';
3
+
4
+ $( "#wcfd_new_field_form_pp" ).dialog({
5
+ modal: true,
6
+ width: 500,
7
+ //height: 400,
8
+ resizable: false,
9
+ autoOpen: false,
10
+ buttons: [{
11
+ text: "Add New Field",
12
+ click: function() {
13
+ var result = wcfd_add_new_row( this );
14
+ if(result){
15
+ $( this ).dialog( "close" );
16
+ }
17
+ }
18
+ }]
19
+ });
20
+
21
+ $( "#wcfd_edit_field_form_pp" ).dialog({
22
+ modal: true,
23
+ width: 500,
24
+ //height: 400,
25
+ resizable: false,
26
+ autoOpen: false,
27
+ buttons: [{
28
+ text: "Edit Field",
29
+ click: function() {
30
+ var result = wcfd_update_row( this );
31
+ if(result){
32
+ $( this ).dialog( "close" );
33
+ }
34
+ }
35
+ }]
36
+ });
37
+
38
+ $('select.thwcfd-enhanced-multi-select').select2({
39
+ minimumResultsForSearch: 10,
40
+ allowClear : true,
41
+ placeholder: $(this).data('placeholder')
42
+ }).addClass('enhanced');
43
+
44
+ $( ".wcfd_remove_field_btn" ).click( function() {
45
+ var form = $(this.form);
46
+
47
+ $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
48
+ $(this).closest('tr').remove();
49
+ });
50
+ });
51
+
52
+ $('#wcfd_checkout_fields tbody').sortable({
53
+ items:'tr',
54
+ cursor:'move',
55
+ axis:'y',
56
+ handle: 'td.sort',
57
+ scrollSensitivity:40,
58
+ helper:function(e,ui){
59
+ ui.children().each(function(){
60
+ $(this).width($(this).width());
61
+ });
62
+ ui.css('left', '0');
63
+ return ui;
64
+ }
65
+ });
66
+
67
+ $("#wcfd_checkout_fields tbody").on("sortstart", function( event, ui ){
68
+ ui.item.css('background-color','#f6f6f6');
69
+ });
70
+ $("#wcfd_checkout_fields tbody").on("sortstop", function( event, ui ){
71
+ ui.item.removeAttr('style');
72
+ wcfd_prepare_field_order_indexes();
73
+ });
74
+
75
+ _openNewFieldForm = function openNewFieldForm(tabName){
76
+ if(tabName == 'billing' || tabName == 'shipping' || tabName == 'additional'){
77
+ tabName = tabName+'_';
78
+ }
79
+
80
+ var form = $("#wcfd_new_field_form_pp");
81
+ wcfd_clear_form(form);
82
+ form.find("input[name=fname]").val(tabName);
83
+ form.find("select[name=ftype]").change();
84
+ form.find("input[name=fclass]").val('form-row-wide');
85
+
86
+ $( "#wcfd_new_field_form_pp" ).dialog( "open" );
87
+ }
88
+
89
+ function wcfd_add_new_row(form){
90
+ var name = $(form).find("input[name=fname]").val();
91
+ var type = $(form).find("select[name=ftype]").val();
92
+ var label = $(form).find("input[name=flabel]").val();
93
+ var placeholder = $(form).find("input[name=fplaceholder]").val();
94
+ var optionsList = $(form).find("input[name=foptions]").val();
95
+
96
+ var fieldClass = $(form).find("input[name=fclass]").val();
97
+ var labelClass = $(form).find("input[name=flabelclass]").val();
98
+
99
+ var required = $(form).find("input[name=frequired]").prop('checked');
100
+ var clearRow = $(form).find("input[name=fclearRow]").prop('checked');
101
+ var enabled = $(form).find("input[name=fenabled]").prop('checked');
102
+
103
+ var showinemail = $(form).find("input[name=fshowinemail]").prop('checked');
104
+ var showinorder = $(form).find("input[name=fshowinorder]").prop('checked');
105
+
106
+ var validations = $(form).find("select[name=fvalidate]").val();
107
+
108
+ var err_msgs = '';
109
+ if(name == ''){
110
+ err_msgs = 'Name is required';
111
+ }else if(!isHtmlIdValid(name)){
112
+ err_msgs = MSG_INVALID_NAME;
113
+ }else if(type == ''){
114
+ err_msgs = 'Type is required';
115
+ }
116
+
117
+ if(err_msgs != ''){
118
+ $(form).find('.err_msgs').html(err_msgs);
119
+ return false;
120
+ }
121
+
122
+ required = required ? 1 : 0;
123
+ clearRow = clearRow ? 1 : 0;
124
+ enabled = enabled ? 1 : 0;
125
+
126
+ showinemail = showinemail ? 1 : 0;
127
+ showinorder = showinorder ? 1 : 0;
128
+
129
+ validations = validations ? validations : '';
130
+
131
+ var index = $('#wcfd_checkout_fields tbody tr').size();
132
+
133
+ var newRow = '<tr class="row_'+index+'">';
134
+ newRow += '<td width="1%" class="sort ui-sortable-handle">';
135
+ newRow += '<input type="hidden" name="f_order['+index+']" class="f_order" value="'+index+'" />';
136
+ newRow += '<input type="hidden" name="f_name['+index+']" class="f_name" value="" />';
137
+ newRow += '<input type="hidden" name="f_name_new['+index+']" class="f_name_new" value="'+name+'" />';
138
+ newRow += '<input type="hidden" name="f_type['+index+']" class="f_type" value="'+type+'" />';
139
+ newRow += '<input type="hidden" name="f_label['+index+']" class="f_label" value="'+label+'" />';
140
+ newRow += '<input type="hidden" name="f_placeholder['+index+']" class="f_placeholder" value="'+placeholder+'" />';
141
+ newRow += '<input type="hidden" name="f_options['+index+']" class="f_options" value="'+optionsList+'" />';
142
+
143
+ newRow += '<input type="hidden" name="f_class['+index+']" class="f_class" value="'+fieldClass+'" />';
144
+ newRow += '<input type="hidden" name="f_label_class['+index+']" class="f_label_class" value="'+labelClass+'" />';
145
+
146
+ newRow += '<input type="hidden" name="f_required['+index+']" class="f_required" value="'+required+'" />';
147
+ newRow += '<input type="hidden" name="f_clear['+index+']" class="f_clear" value="'+clearRow+'" />';
148
+ newRow += '<input type="hidden" name="f_enabled['+index+']" class="f_enabled" value="'+enabled+'" />';
149
+
150
+ newRow += '<input type="hidden" name="f_show_in_email['+index+']" class="f_show_in_email" value="'+showinemail+'" />';
151
+ newRow += '<input type="hidden" name="f_show_in_order['+index+']" class="f_show_in_order" value="'+showinorder+'" />';
152
+
153
+ newRow += '<input type="hidden" name="f_validation['+index+']" class="f_validation" value="'+validations+'" />';
154
+ newRow += '<input type="hidden" name="f_deleted['+index+']" class="f_deleted" value="0" />';
155
+ newRow += '</td>';
156
+ newRow += '<td ><input type="checkbox" /></td>';
157
+ newRow += '<td class="name">'+name+'</td>';
158
+ newRow += '<td class="id">'+type+'</td>';
159
+ newRow += '<td>'+label+'</td>';
160
+ newRow += '<td>'+placeholder+'</td>';
161
+ newRow += '<td>'+validations+'</td>';
162
+ if(required == true){
163
+ newRow += '<td class="status"><span class="status-enabled tips">Yes</span></td>';
164
+ }else{
165
+ newRow += '<td class="status">-</td>';
166
+ }
167
+ if(clearRow == true){
168
+ newRow += '<td class="status"><span class="status-enabled tips">Yes</span></td>';
169
+ }else{
170
+ newRow += '<td class="status">-</td>';
171
+ }
172
+ if(enabled == true){
173
+ newRow += '<td class="status"><span class="status-enabled tips">Yes</span></td>';
174
+ }else{
175
+ newRow += '<td class="status">-</td>';
176
+ }
177
+
178
+ newRow += '<td><button type="button" onclick="openEditFieldForm(this)">Edit</button></td>';
179
+ newRow += '</tr>';
180
+
181
+ $('#wcfd_checkout_fields tbody tr:last').after(newRow);
182
+ return true;
183
+ }
184
+
185
+ _openEditFieldForm = function openEditFieldForm(elm, rowId){
186
+ var row = $(elm).closest('tr')
187
+
188
+ var is_custom = row.find(".f_custom").val();
189
+ var name = row.find(".f_name").val();
190
+ var type = row.find(".f_type").val();
191
+ var label = row.find(".f_label").val();
192
+ var placeholder = row.find(".f_placeholder").val();
193
+ var optionsList = row.find(".f_options").val();
194
+
195
+ var field_classes = row.find(".f_class").val();
196
+ var label_classes = row.find(".f_label_class").val();
197
+
198
+ var required = row.find(".f_required").val();
199
+ var clearRow = row.find(".f_clear").val();
200
+
201
+ var enabled = row.find(".f_enabled").val();
202
+ var validations = row.find(".f_validation").val();
203
+
204
+ var showinemail = row.find(".f_show_in_email").val();
205
+ var showinorder = row.find(".f_show_in_order").val();
206
+
207
+ is_custom = is_custom == 1 ? true : false;
208
+
209
+ required = required == 1 ? true : false;
210
+ clearRow = clearRow == 1 ? true : false;
211
+ enabled = enabled == 1 ? true : false;
212
+
213
+ validations = validations.split(",");
214
+
215
+ showinemail = showinemail == 1 ? true : false;
216
+ showinorder = showinorder == 1 ? true : false;
217
+
218
+ showinemail = is_custom == true ? showinemail : true;
219
+ showinorder = is_custom == true ? showinorder : true;
220
+
221
+ var form = $("#wcfd_edit_field_form_pp");
222
+ form.find('.err_msgs').html('');
223
+ form.find("input[name=rowId]").val(rowId);
224
+ form.find("input[name=fname]").val(name);
225
+ form.find("input[name=fnameNew]").val(name);
226
+ form.find("select[name=ftype]").val(type);
227
+ form.find("input[name=flabel]").val(label);
228
+ form.find("input[name=fplaceholder]").val(placeholder);
229
+ form.find("input[name=foptions]").val(optionsList);
230
+
231
+ form.find("input[name=fclass]").val(field_classes);
232
+ form.find("input[name=flabelclass]").val(label_classes);
233
+ form.find("select[name=fvalidate]").val(validations).trigger("change");
234
+
235
+ form.find("input[name=frequired]").prop('checked', required);
236
+ form.find("input[name=fclearRow]").prop('checked', clearRow);
237
+ form.find("input[name=fenabled]").prop('checked', enabled);
238
+
239
+ form.find("input[name=fshowinemail]").prop('checked', showinemail);
240
+ form.find("input[name=fshowinorder]").prop('checked', showinorder);
241
+
242
+ form.find("select[name=ftype]").change();
243
+ $( "#wcfd_edit_field_form_pp" ).dialog( "open" );
244
+
245
+ /*if(type == 'email' || type == 'tel' || type == 'country' || type == 'state'){
246
+
247
+ }*/
248
+
249
+ if(is_custom == false){
250
+ form.find("input[name=fnameNew]").prop('disabled', true);
251
+ form.find("select[name=ftype]").prop('disabled', true);
252
+ form.find("input[name=fshowinemail]").prop('disabled', true);
253
+ form.find("input[name=fshowinorder]").prop('disabled', true);
254
+ form.find("input[name=flabel]").focus();
255
+ }else{
256
+ form.find("input[name=fnameNew]").prop('disabled', false);
257
+ form.find("select[name=ftype]").prop('disabled', false);
258
+ form.find("input[name=fshowinemail]").prop('disabled', false);
259
+ form.find("input[name=fshowinorder]").prop('disabled', false);
260
+ }
261
+ }
262
+
263
+ function wcfd_update_row(form){
264
+ var rowId = $(form).find("input[name=rowId]").val();
265
+
266
+ var name = $(form).find("input[name=fnameNew]").val();
267
+ var type = $(form).find("select[name=ftype]").val();
268
+ var label = $(form).find("input[name=flabel]").val();
269
+ var placeholder = $(form).find("input[name=fplaceholder]").val();
270
+ var optionsList = $(form).find("input[name=foptions]").val();
271
+
272
+ var fieldClass = $(form).find("input[name=fclass]").val();
273
+ var labelClass = $(form).find("input[name=flabelclass]").val();
274
+
275
+ var required = $(form).find("input[name=frequired]").prop('checked');
276
+ var clearRow = $(form).find("input[name=fclearRow]").prop('checked');
277
+ var enabled = $(form).find("input[name=fenabled]").prop('checked');
278
+
279
+ var showinemail = $(form).find("input[name=fshowinemail]").prop('checked');
280
+ var showinorder = $(form).find("input[name=fshowinorder]").prop('checked');
281
+
282
+ var validations = $(form).find("select[name=fvalidate]").val();
283
+
284
+ var err_msgs = '';
285
+ if(name == ''){
286
+ err_msgs = 'Name is required';
287
+ }else if(!isHtmlIdValid(name)){
288
+ err_msgs = MSG_INVALID_NAME;
289
+ }else if(type == ''){
290
+ err_msgs = 'Type is required';
291
+ }
292
+
293
+ if(err_msgs != ''){
294
+ $(form).find('.err_msgs').html(err_msgs);
295
+ return false;
296
+ }
297
+
298
+ required = required ? 1 : 0;
299
+ clearRow = clearRow ? 1 : 0;
300
+ enabled = enabled ? 1 : 0;
301
+
302
+ showinemail = showinemail ? 1 : 0;
303
+ showinorder = showinorder ? 1 : 0;
304
+
305
+ validations = validations ? validations : '';
306
+
307
+ var row = $('#wcfd_checkout_fields tbody').find('.row_'+rowId);
308
+ row.find(".f_name").val(name);
309
+ row.find(".f_type").val(type);
310
+ row.find(".f_label").val(label);
311
+ row.find(".f_placeholder").val(placeholder);
312
+ row.find(".f_options").val(optionsList);
313
+
314
+ row.find(".f_class").val(fieldClass);
315
+ row.find(".f_label_class").val(labelClass);
316
+
317
+ row.find(".f_required").val(required);
318
+ row.find(".f_clear").val(clearRow);
319
+ row.find(".f_enabled").val(enabled);
320
+
321
+ row.find(".f_show_in_email").val(showinemail);
322
+ row.find(".f_show_in_order").val(showinorder);
323
+ row.find(".f_validation").val(validations);
324
+
325
+ row.find(".td_name").html(name);
326
+ row.find(".td_type").html(type);
327
+ row.find(".td_label").html(label);
328
+ row.find(".td_placeholder").html(placeholder);
329
+ row.find(".td_validate").html(""+validations+"");
330
+ row.find(".td_required").html(required == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
331
+ row.find(".td_clear").html(clearRow == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
332
+ row.find(".td_enabled").html(enabled == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
333
+ return true;
334
+ }
335
+
336
+ _removeSelectedFields = function removeSelectedFields(){
337
+ $('#wcfd_checkout_fields tbody tr').removeClass('strikeout');
338
+ $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
339
+ //$(this).closest('tr').remove();
340
+ var row = $(this).closest('tr');
341
+ if(!row.hasClass("strikeout")){
342
+ row.addClass("strikeout");
343
+ }
344
+ row.find(".f_deleted").val(1);
345
+ row.find(".f_edit_btn").prop('disabled', true);
346
+ //row.find('.sort').removeClass('sort');
347
+ });
348
+ }
349
+
350
+ _enableDisableSelectedFields = function enableDisableSelectedFields(enabled){
351
+ $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]:checked').each(function () {
352
+ var row = $(this).closest('tr');
353
+ if(enabled == 0){
354
+ if(!row.hasClass("thwcfd-disabled")){
355
+ row.addClass("thwcfd-disabled");
356
+ }
357
+ }else{
358
+ row.removeClass("thwcfd-disabled");
359
+ }
360
+
361
+ row.find(".f_edit_btn").prop('disabled', enabled == 1 ? false : true);
362
+ row.find(".td_enabled").html(enabled == 1 ? '<span class="status-enabled tips">Yes</span>' : '-');
363
+ row.find(".f_enabled").val(enabled);
364
+ });
365
+ }
366
+
367
+ function wcfd_clear_form( form ){
368
+ form.find('.err_msgs').html('');
369
+ form.find("input[name=fname]").val('');
370
+ form.find("input[name=fnameNew]").val('');
371
+ form.find("select[name=ftype]").prop('selectedIndex',0);
372
+ form.find("input[name=flabel]").val('');
373
+ form.find("input[name=fplaceholder]").val('');
374
+ form.find("input[name=foptions]").val('');
375
+
376
+ form.find("input[name=fclass]").val('');
377
+ form.find("input[name=flabelclass]").val('');
378
+ form.find("select[name=fvalidate] option:selected").removeProp('selected');
379
+
380
+ form.find("input[name=frequired]").prop('checked', true);
381
+ form.find("input[name=fclearRow]").prop('checked', true);
382
+ form.find("input[name=fenabled]").prop('checked', true);
383
+ form.find("input[name=fshowinemail]").prop('checked', true);
384
+ form.find("input[name=fshowinorder]").prop('checked', true);
385
+ }
386
+
387
+ function wcfd_prepare_field_order_indexes() {
388
+ $('#wcfd_checkout_fields tbody tr').each(function(index, el){
389
+ $('input.f_order', el).val( parseInt( $(el).index('#wcfd_checkout_fields tbody tr') ) );
390
+ });
391
+ };
392
+
393
+ _fieldTypeChangeListner = function fieldTypeChangeListner(elm){
394
+ var type = $(elm).val();
395
+ var form = $(elm).closest('form');
396
+
397
+ showAllFields(form);
398
+ if(type === 'select'){
399
+ //form.find('.rowPlaceholder').hide();
400
+ form.find('.rowValidate').hide();
401
+ }else{
402
+ form.find('.rowOptions').hide();
403
+ }
404
+ }
405
+
406
+ function showAllFields(form){
407
+ form.find('.rowOptions').show();
408
+ form.find('.rowPlaceholder').show();
409
+ form.find('.rowValidate').show();
410
+ }
411
+
412
+ _selectAllCheckoutFields = function selectAllCheckoutFields(elm){
413
+ var checkAll = $(elm).prop('checked');
414
+ $('#wcfd_checkout_fields tbody input:checkbox[name=select_field]').prop('checked', checkAll);
415
+ }
416
+
417
+ function isHtmlIdValid(id) {
418
+ var re = /^[a-z\_]+[a-z0-9\_]*$/;
419
+ return re.test(id.trim());
420
+ }
421
+
422
+ return {
423
+ openNewFieldForm : _openNewFieldForm,
424
+ openEditFieldForm : _openEditFieldForm,
425
+ removeSelectedFields : _removeSelectedFields,
426
+ enableDisableSelectedFields : _enableDisableSelectedFields,
427
+ fieldTypeChangeListner : _fieldTypeChangeListner,
428
+ selectAllCheckoutFields : _selectAllCheckoutFields,
429
+ };
430
+ }(window.jQuery, window, document));
431
+
432
+ function openNewFieldForm(tabName){
433
+ wcfd_settings.openNewFieldForm(tabName);
434
+ }
435
+
436
+ function openEditFieldForm(elm, rowId){
437
+ wcfd_settings.openEditFieldForm(elm, rowId);
438
+ }
439
+
440
+ function removeSelectedFields(){
441
+ wcfd_settings.removeSelectedFields();
442
+ }
443
+
444
+ function enableSelectedFields(){
445
+ wcfd_settings.enableDisableSelectedFields(1);
446
+ }
447
+
448
+ function disableSelectedFields(){
449
+ wcfd_settings.enableDisableSelectedFields(0);
450
+ }
451
+
452
+ function fieldTypeChangeListner(elm){
453
+ wcfd_settings.fieldTypeChangeListner(elm);
454
+ }
455
+
456
+ function thwcfdSelectAllCheckoutFields(elm){
457
+ wcfd_settings.selectAllCheckoutFields(elm);
458
  }
assets/js/thwcfd-checkout-field-editor-frontend.js CHANGED
@@ -1,7 +1,7 @@
1
- jQuery(document).ready(function($) {
2
- $('select.thwcfd-enhanced-select').select2({
3
- minimumResultsForSearch: 10,
4
- allowClear : true,
5
- placeholder: $(this).data('placeholder')
6
- }).addClass('enhanced');
7
  });
1
+ jQuery(document).ready(function($) {
2
+ $('select.thwcfd-enhanced-select').select2({
3
+ minimumResultsForSearch: 10,
4
+ allowClear : true,
5
+ placeholder: $(this).data('placeholder')
6
+ }).addClass('enhanced');
7
  });
checkout-form-designer.php CHANGED
@@ -1,455 +1,461 @@
1
- <?php
2
- /**
3
- * Plugin Name: Woo Checkout Field Editor Pro
4
- * Description: Customize WooCommerce checkout fields(Add, Edit, Delete and re-arrange fields).
5
- * Author: ThemeHiGH
6
- * Version: 1.2.5
7
- * Author URI: https://www.themehigh.com
8
- * Plugin URI: https://www.themehigh.com
9
- * Text Domain: thwcfd
10
- * Domain Path: /languages
11
- * WC requires at least: 3.0.0
12
- * WC tested up to: 3.3.0
13
- */
14
-
15
- if(!defined( 'ABSPATH' )) exit;
16
-
17
- if (!function_exists('is_woocommerce_active')){
18
- function is_woocommerce_active(){
19
- $active_plugins = (array) get_option('active_plugins', array());
20
- if(is_multisite()){
21
- $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
22
- }
23
- return in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
24
- }
25
- }
26
-
27
- if(is_woocommerce_active()) {
28
- load_plugin_textdomain( 'thwcfd', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
29
-
30
- /**
31
- * woocommerce_init_checkout_field_editor function.
32
- */
33
- function thwcfd_init_checkout_field_editor_lite() {
34
- global $supress_field_modification;
35
- $supress_field_modification = false;
36
-
37
- define('TH_WCFD_VERSION', '1.2.5');
38
- !defined('TH_WCFD_BASE_NAME') && define('TH_WCFD_BASE_NAME', plugin_basename( __FILE__ ));
39
- !defined('TH_WCFD_URL') && define('TH_WCFD_URL', plugins_url( '/', __FILE__ ));
40
- !defined('TH_WCFD_ASSETS_URL') && define('TH_WCFD_ASSETS_URL', TH_WCFD_URL . 'assets/');
41
-
42
- if(!class_exists('WC_Checkout_Field_Editor')){
43
- require_once('classes/class-wc-checkout-field-editor.php');
44
- }
45
-
46
- if (!class_exists('WC_Checkout_Field_Editor_Export_Handler')){
47
- require_once('classes/class-wc-checkout-field-editor-export-handler.php');
48
- }
49
- new WC_Checkout_Field_Editor_Export_Handler();
50
-
51
- $GLOBALS['WC_Checkout_Field_Editor'] = new WC_Checkout_Field_Editor();
52
- }
53
- add_action('init', 'thwcfd_init_checkout_field_editor_lite');
54
-
55
- function thwcfd_is_locale_field( $field_name ){
56
- if(!empty($field_name) && in_array($field_name, array(
57
- 'billing_address_1', 'billing_address_2', 'billing_state', 'billing_postcode', 'billing_city',
58
- 'shipping_address_1', 'shipping_address_2', 'shipping_state', 'shipping_postcode', 'shipping_city',
59
- ))){
60
- return true;
61
- }
62
- return false;
63
- }
64
-
65
- function thwcfd_woocommerce_version_check( $version = '3.0' ) {
66
- if(function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) {
67
- global $woocommerce;
68
- if( version_compare( $woocommerce->version, $version, ">=" ) ) {
69
- return true;
70
- }
71
- }
72
- return false;
73
- }
74
-
75
- function thwcfd_enqueue_scripts(){
76
- global $wp_scripts;
77
-
78
- if(is_checkout()){
79
- $in_footer = apply_filters( 'thwcfd_enqueue_script_in_footer', true );
80
-
81
- wp_register_script('thwcfd-field-editor-script', TH_WCFD_ASSETS_URL.'js/thwcfd-checkout-field-editor-frontend.js',
82
- array('jquery', 'select2'), TH_WCFD_VERSION, $in_footer);
83
-
84
- wp_enqueue_script('thwcfd-field-editor-script');
85
- }
86
- }
87
- add_action('wp_enqueue_scripts', 'thwcfd_enqueue_scripts');
88
-
89
- /**
90
- * Hide Additional Fields title if no fields available.
91
- *
92
- * @param mixed $old
93
- */
94
- function thwcfd_enable_order_notes_field() {
95
- global $supress_field_modification;
96
-
97
- if($supress_field_modification){
98
- return $fields;
99
- }
100
-
101
- $additional_fields = get_option('wc_fields_additional');
102
- if(is_array($additional_fields)){
103
- $enabled = 0;
104
- foreach($additional_fields as $field){
105
- if($field['enabled']){
106
- $enabled++;
107
- }
108
- }
109
- return $enabled > 0 ? true : false;
110
- }
111
- return true;
112
- }
113
- add_filter('woocommerce_enable_order_notes_field', 'thwcfd_enable_order_notes_field', 1000);
114
-
115
- function thwcfd_woo_default_address_fields( $fields ) {
116
- $sname = apply_filters('thwcfd_address_field_override_with', 'billing');
117
-
118
- if($sname === 'billing' || $sname === 'shipping'){
119
- $address_fields = get_option('wc_fields_'.$sname);
120
-
121
- if(is_array($address_fields) && !empty($address_fields) && !empty($fields)){
122
- $override_required = apply_filters( 'thwcfd_address_field_override_required', true );
123
-
124
- foreach($fields as $name => $field) {
125
- $fname = $sname.'_'.$name;
126
-
127
- if(thwcfd_is_locale_field($fname) && $override_required){
128
- $custom_field = isset($address_fields[$fname]) ? $address_fields[$fname] : false;
129
-
130
- if($custom_field && !( isset($custom_field['enabled']) && $custom_field['enabled'] == false )){
131
- $fields[$name]['required'] = isset($custom_field['required']) && $custom_field['required'] ? true : false;
132
- }
133
- }
134
- }
135
- }
136
- }
137
-
138
- return $fields;
139
- }
140
- add_filter('woocommerce_default_address_fields' , 'thwcfd_woo_default_address_fields' );
141
-
142
- function thwcfd_prepare_country_locale($fields) {
143
- if(is_array($fields)){
144
- foreach($fields as $key => $props){
145
- $override_ph = apply_filters('thwcfd_address_field_override_placeholder', true);
146
- $override_label = apply_filters('thwcfd_address_field_override_label', true);
147
- $override_required = apply_filters('thwcfd_address_field_override_required', false);
148
- $override_priority = apply_filters('thwcfd_address_field_override_priority', true);
149
-
150
- if($override_ph && isset($props['placeholder'])){
151
- unset($fields[$key]['placeholder']);
152
- }
153
- if($override_label && isset($props['label'])){
154
- unset($fields[$key]['label']);
155
- }
156
- if($override_required && isset($props['required'])){
157
- unset($fields[$key]['required']);
158
- }
159
-
160
- if($override_priority && isset($props['priority'])){
161
- unset($fields[$key]['priority']);
162
- //unset($fields[$key]['order']);
163
- }
164
- }
165
- }
166
- return $fields;
167
- }
168
- add_filter('woocommerce_get_country_locale_default', 'thwcfd_prepare_country_locale');
169
- add_filter('woocommerce_get_country_locale_base', 'thwcfd_prepare_country_locale');
170
-
171
- function thwcfd_woo_get_country_locale($locale) {
172
- if(is_array($locale)){
173
- foreach($locale as $country => $fields){
174
- $locale[$country] = thwcfd_prepare_country_locale($fields);
175
- }
176
- }
177
- return $locale;
178
- }
179
- add_filter('woocommerce_get_country_locale', 'thwcfd_woo_get_country_locale');
180
-
181
- /**
182
- * wc_checkout_fields_modify_billing_fields function.
183
- *
184
- * @param mixed $fields
185
- */
186
- function thwcfd_billing_fields_lite($fields, $country){
187
- global $supress_field_modification;
188
-
189
- if($supress_field_modification){
190
- return $fields;
191
- }
192
- if(is_wc_endpoint_url('edit-address')){
193
- return $fields;
194
- }else{
195
- return thwcfd_prepare_address_fields(get_option('wc_fields_billing'), $fields, 'billing', $country);
196
- }
197
- }
198
- add_filter('woocommerce_billing_fields', 'thwcfd_billing_fields_lite', 1000, 2);
199
-
200
- /**
201
- * wc_checkout_fields_modify_shipping_fields function.
202
- *
203
- * @param mixed $old
204
- */
205
- function thwcfd_shipping_fields_lite($fields, $country){
206
- global $supress_field_modification;
207
-
208
- if ($supress_field_modification){
209
- return $fields;
210
- }
211
- if(is_wc_endpoint_url('edit-address')){
212
- return $fields;
213
- }else{
214
- return thwcfd_prepare_address_fields(get_option('wc_fields_shipping'), $fields, 'shipping', $country);
215
- }
216
- }
217
- add_filter('woocommerce_shipping_fields', 'thwcfd_shipping_fields_lite', 1000, 2);
218
-
219
- /**
220
- * wc_checkout_fields_modify_shipping_fields function.
221
- *
222
- * @param mixed $old
223
- */
224
- function thwcfd_checkout_fields_lite( $fields ) {
225
- global $supress_field_modification;
226
-
227
- if($supress_field_modification){
228
- return $fields;
229
- }
230
-
231
- if($additional_fields = get_option('wc_fields_additional')){
232
- if( isset($fields['order']) && is_array($fields['order']) ){
233
- $fields['order'] = $additional_fields + $fields['order'];
234
- }
235
-
236
- // check if order_comments is enabled/disabled
237
- if(isset($additional_fields) && !$additional_fields['order_comments']['enabled']){
238
- unset($fields['order']['order_comments']);
239
- }
240
- }
241
-
242
- if(isset($fields['order']) && is_array($fields['order'])){
243
- $fields['order'] = thwcfd_prepare_checkout_fields_lite($fields['order'], false);
244
- }
245
-
246
- return $fields;
247
- }
248
- add_filter('woocommerce_checkout_fields', 'thwcfd_checkout_fields_lite', 1000);
249
-
250
- /**
251
- *
252
- */
253
- function thwcfd_prepare_address_fields($fieldset, $original_fieldset = false, $sname = 'billing', $country){
254
- if(is_array($fieldset) && !empty($fieldset)) {
255
- $locale = WC()->countries->get_country_locale();
256
- if(isset($locale[ $country ]) && is_array($locale[ $country ])) {
257
- foreach($locale[ $country ] as $key => $value){
258
- if(is_array($value) && isset($fieldset[$sname.'_'.$key])){
259
- if(isset($value['required'])){
260
- $fieldset[$sname.'_'.$key]['required'] = $value['required'];
261
- }
262
- }
263
- }
264
- }
265
- $fieldset = thwcfd_prepare_checkout_fields_lite($fieldset, $original_fieldset);
266
- return $fieldset;
267
- }else {
268
- return $original_fieldset;
269
- }
270
- }
271
-
272
- /**
273
- * checkout_fields_modify_fields function.
274
- *
275
- * @param mixed $data
276
- * @param mixed $old
277
- */
278
- function thwcfd_prepare_checkout_fields_lite($fields, $original_fields) {
279
- if(is_array($fields) && !empty($fields)) {
280
- foreach($fields as $name => $field) {
281
- if(isset($field['enabled']) && $field['enabled'] == false ) {
282
- unset($fields[$name]);
283
- }else{
284
- $new_field = false;
285
-
286
- if($original_fields && isset($original_fields[$name])){
287
- $new_field = $original_fields[$name];
288
-
289
- $new_field['label'] = isset($field['label']) ? $field['label'] : '';
290
- $new_field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : '';
291
-
292
- $new_field['class'] = isset($field['class']) && is_array($field['class']) ? $field['class'] : array();
293
- $new_field['label_class'] = isset($field['label_class']) && is_array($field['label_class']) ? $field['label_class'] : array();
294
- $new_field['validate'] = isset($field['validate']) && is_array($field['validate']) ? $field['validate'] : array();
295
-
296
- /*if(!thwcfd_is_locale_field($name)){
297
- $new_field['required'] = isset($field['required']) ? $field['required'] : 0;
298
- }*/
299
- $new_field['required'] = isset($field['required']) ? $field['required'] : 0;
300
- $new_field['clear'] = isset($field['clear']) ? $field['clear'] : 0;
301
- }else{
302
- $new_field = $field;
303
- }
304
-
305
- if(isset($new_field['type']) && $new_field['type'] === 'select'){
306
- if(apply_filters('thwcfd_enable_select2_for_select_fields', true)){
307
- $new_field['input_class'][] = 'thwcfd-enhanced-select';
308
- }
309
- }
310
-
311
- $new_field['order'] = isset($field['order']) && is_numeric($field['order']) ? $field['order'] : 0;
312
- if(isset($new_field['order']) && is_numeric($new_field['order'])){
313
- $priority = ($new_field['order']+1)*10;
314
- $new_field['priority'] = $priority;
315
- //$new_field['priority'] = $new_field['order'];
316
- }
317
-
318
- if(isset($new_field['label'])){
319
- $new_field['label'] = __($new_field['label'], 'woocommerce');
320
- }
321
- if(isset($new_field['placeholder'])){
322
- $new_field['placeholder'] = __($new_field['placeholder'], 'woocommerce');
323
- }
324
-
325
- $fields[$name] = $new_field;
326
- }
327
- }
328
- return $fields;
329
- }else {
330
- return $original_fields;
331
- }
332
- }
333
-
334
- /*****************************************
335
- ----- Display Field Values - START ------
336
- *****************************************/
337
-
338
- /**
339
- * Display custom fields in emails
340
- *
341
- * @param array $keys
342
- * @return array
343
- */
344
- function thwcfd_display_custom_fields_in_emails_lite($ofields, $sent_to_admin, $order){
345
- $custom_fields = array();
346
- $fields = array_merge(WC_Checkout_Field_Editor::get_fields('billing'), WC_Checkout_Field_Editor::get_fields('shipping'),
347
- WC_Checkout_Field_Editor::get_fields('additional'));
348
-
349
- // Loop through all custom fields to see if it should be added
350
- foreach( $fields as $key => $options ) {
351
- if(isset($options['show_in_email']) && $options['show_in_email']){
352
- $value = '';
353
- if(thwcfd_woo_version_check()){
354
- $value = get_post_meta( $order->get_id(), $key, true );
355
- }else{
356
- $value = get_post_meta( $order->id, $key, true );
357
- }
358
-
359
- if(!empty($value)){
360
- $label = isset($options['label']) && $options['label'] ? $options['label'] : $key;
361
- $label = esc_attr($label);
362
-
363
- $custom_field = array();
364
- $custom_field['label'] = $label;
365
- $custom_field['value'] = $value;
366
-
367
- $custom_fields[$key] = $custom_field;
368
- }
369
- }
370
- }
371
-
372
- return array_merge($ofields, $custom_fields);
373
- }
374
- add_filter('woocommerce_email_order_meta_fields', 'thwcfd_display_custom_fields_in_emails_lite', 10, 3);
375
-
376
- /**
377
- * Display custom checkout fields on view order pages
378
- *
379
- * @param object $order
380
- */
381
- function thwcfd_order_details_after_customer_details_lite($order){
382
- if(thwcfd_woocommerce_version_check()){
383
- $order_id = $order->get_id();
384
- }else{
385
- $order_id = $order->id;
386
- }
387
-
388
- $fields = array();
389
- if(!wc_ship_to_billing_address_only() && $order->needs_shipping_address()){
390
- $fields = array_merge(WC_Checkout_Field_Editor::get_fields('billing'), WC_Checkout_Field_Editor::get_fields('shipping'),
391
- WC_Checkout_Field_Editor::get_fields('additional'));
392
- }else{
393
- $fields = array_merge(WC_Checkout_Field_Editor::get_fields('billing'), WC_Checkout_Field_Editor::get_fields('additional'));
394
- }
395
-
396
- if(is_array($fields) && !empty($fields)){
397
- $fields_html = '';
398
- // Loop through all custom fields to see if it should be added
399
- foreach($fields as $name => $options){
400
- $enabled = (isset($options['enabled']) && $options['enabled'] == false) ? false : true;
401
- $is_custom_field = (isset($options['custom']) && $options['custom'] == true) ? true : false;
402
-
403
- if(isset($options['show_in_order']) && $options['show_in_order'] && $enabled && $is_custom_field){
404
- $value = get_post_meta($order_id, $name, true);
405
-
406
- if(!empty($value)){
407
- $label = isset($options['label']) && !empty($options['label']) ? __( $options['label'], 'woocommerce' ) : $name;
408
-
409
- if(is_account_page()){
410
- if(apply_filters( 'thwcfd_view_order_customer_details_table_view', true )){
411
- $fields_html .= '<tr><th>'. esc_attr($label) .':</th><td>'. wptexturize($value) .'</td></tr>';
412
- }else{
413
- $fields_html .= '<br/><dt>'. esc_attr($label) .':</dt><dd>'. wptexturize($value) .'</dd>';
414
- }
415
- }else{
416
- if(apply_filters( 'thwcfd_thankyou_customer_details_table_view', true )){
417
- $fields_html .= '<tr><th>'. esc_attr($label) .':</th><td>'. wptexturize($value) .'</td></tr>';
418
- }else{
419
- $fields_html .= '<br/><dt>'. esc_attr($label) .':</dt><dd>'. wptexturize($value) .'</dd>';
420
- }
421
- }
422
- }
423
- }
424
- }
425
-
426
- if($fields_html){
427
- do_action( 'thwcfd_order_details_before_custom_fields_table', $order );
428
- ?>
429
- <table class="woocommerce-table woocommerce-table--custom-fields shop_table custom-fields">
430
- <?php
431
- echo $fields_html;
432
- ?>
433
- </table>
434
- <?php
435
- do_action( 'thwcfd_order_details_after_custom_fields_table', $order );
436
- }
437
- }
438
- }
439
- add_action('woocommerce_order_details_after_order_table', 'thwcfd_order_details_after_customer_details_lite', 20, 1);
440
-
441
- /*****************************************
442
- ----- Display Field Values - END --------
443
- *****************************************/
444
-
445
- function thwcfd_woo_version_check( $version = '3.0' ) {
446
- if(function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) {
447
- global $woocommerce;
448
- if( version_compare( $woocommerce->version, $version, ">=" ) ) {
449
- return true;
450
- }
451
- }
452
- return false;
453
- }
454
-
455
- }
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Woo Checkout Field Editor Pro
4
+ * Description: Customize WooCommerce checkout fields(Add, Edit, Delete and re-arrange fields).
5
+ * Author: ThemeHiGH
6
+ * Version: 1.2.8
7
+ * Author URI: https://www.themehigh.com
8
+ * Plugin URI: https://www.themehigh.com
9
+ * Text Domain: thwcfd
10
+ * Domain Path: /languages
11
+ * WC requires at least: 3.0.0
12
+ * WC tested up to: 3.4.3
13
+ */
14
+
15
+ if(!defined( 'ABSPATH' )) exit;
16
+
17
+ if (!function_exists('is_woocommerce_active')){
18
+ function is_woocommerce_active(){
19
+ $active_plugins = (array) get_option('active_plugins', array());
20
+ if(is_multisite()){
21
+ $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
22
+ }
23
+ return in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
24
+ }
25
+ }
26
+
27
+ if(is_woocommerce_active()) {
28
+ load_plugin_textdomain( 'thwcfd', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
29
+
30
+ /**
31
+ * woocommerce_init_checkout_field_editor function.
32
+ */
33
+ function thwcfd_init_checkout_field_editor_lite() {
34
+ global $supress_field_modification;
35
+ $supress_field_modification = false;
36
+
37
+ define('TH_WCFD_VERSION', '1.2.8');
38
+ !defined('TH_WCFD_BASE_NAME') && define('TH_WCFD_BASE_NAME', plugin_basename( __FILE__ ));
39
+ !defined('TH_WCFD_URL') && define('TH_WCFD_URL', plugins_url( '/', __FILE__ ));
40
+ !defined('TH_WCFD_ASSETS_URL') && define('TH_WCFD_ASSETS_URL', TH_WCFD_URL . 'assets/');
41
+
42
+ if(!class_exists('WC_Checkout_Field_Editor')){
43
+ require_once('classes/class-wc-checkout-field-editor.php');
44
+ }
45
+
46
+ $GLOBALS['WC_Checkout_Field_Editor'] = new WC_Checkout_Field_Editor();
47
+ }
48
+ add_action('init', 'thwcfd_init_checkout_field_editor_lite');
49
+
50
+ function thwcfd_is_locale_field( $field_name ){
51
+ if(!empty($field_name) && in_array($field_name, array(
52
+ 'billing_address_1', 'billing_address_2', 'billing_state', 'billing_postcode', 'billing_city',
53
+ 'shipping_address_1', 'shipping_address_2', 'shipping_state', 'shipping_postcode', 'shipping_city',
54
+ ))){
55
+ return true;
56
+ }
57
+ return false;
58
+ }
59
+
60
+ function thwcfd_woocommerce_version_check( $version = '3.0' ) {
61
+ if(function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) {
62
+ global $woocommerce;
63
+ if( version_compare( $woocommerce->version, $version, ">=" ) ) {
64
+ return true;
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+
70
+ function thwcfd_enqueue_scripts(){
71
+ global $wp_scripts;
72
+
73
+ if(is_checkout()){
74
+ $in_footer = apply_filters( 'thwcfd_enqueue_script_in_footer', true );
75
+
76
+ wp_register_script('thwcfd-field-editor-script', TH_WCFD_ASSETS_URL.'js/thwcfd-checkout-field-editor-frontend.js',
77
+ array('jquery', 'select2'), TH_WCFD_VERSION, $in_footer);
78
+
79
+ wp_enqueue_script('thwcfd-field-editor-script');
80
+ }
81
+ }
82
+ add_action('wp_enqueue_scripts', 'thwcfd_enqueue_scripts');
83
+
84
+ /**
85
+ * Hide Additional Fields title if no fields available.
86
+ *
87
+ * @param mixed $old
88
+ */
89
+ function thwcfd_enable_order_notes_field() {
90
+ global $supress_field_modification;
91
+
92
+ if($supress_field_modification){
93
+ return $fields;
94
+ }
95
+
96
+ $additional_fields = get_option('wc_fields_additional');
97
+ if(is_array($additional_fields)){
98
+ $enabled = 0;
99
+ foreach($additional_fields as $field){
100
+ if($field['enabled']){
101
+ $enabled++;
102
+ }
103
+ }
104
+ return $enabled > 0 ? true : false;
105
+ }
106
+ return true;
107
+ }
108
+ add_filter('woocommerce_enable_order_notes_field', 'thwcfd_enable_order_notes_field', 1000);
109
+
110
+ function thwcfd_woo_default_address_fields( $fields ) {
111
+ $sname = apply_filters('thwcfd_address_field_override_with', 'billing');
112
+
113
+ if($sname === 'billing' || $sname === 'shipping'){
114
+ $address_fields = get_option('wc_fields_'.$sname);
115
+
116
+ if(is_array($address_fields) && !empty($address_fields) && !empty($fields)){
117
+ $override_required = apply_filters( 'thwcfd_address_field_override_required', true );
118
+
119
+ foreach($fields as $name => $field) {
120
+ $fname = $sname.'_'.$name;
121
+
122
+ if(thwcfd_is_locale_field($fname) && $override_required){
123
+ $custom_field = isset($address_fields[$fname]) ? $address_fields[$fname] : false;
124
+
125
+ if($custom_field && !( isset($custom_field['enabled']) && $custom_field['enabled'] == false )){
126
+ $fields[$name]['required'] = isset($custom_field['required']) && $custom_field['required'] ? true : false;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ return $fields;
134
+ }
135
+ add_filter('woocommerce_default_address_fields' , 'thwcfd_woo_default_address_fields' );
136
+
137
+ function thwcfd_prepare_country_locale($fields) {
138
+ if(is_array($fields)){
139
+ $sname = apply_filters('thwcfd_address_field_override_with', 'billing');
140
+ $address_fields = get_option('wc_fields_'.$sname);
141
+
142
+ foreach($fields as $key => $props){
143
+ $override_ph = apply_filters('thwcfd_address_field_override_placeholder', true);
144
+ $override_label = apply_filters('thwcfd_address_field_override_label', true);
145
+ $override_required = apply_filters('thwcfd_address_field_override_required', false);
146
+ $override_priority = apply_filters('thwcfd_address_field_override_priority', true);
147
+
148
+ if($override_ph && isset($props['placeholder'])){
149
+ unset($fields[$key]['placeholder']);
150
+ }
151
+ if($override_label && isset($props['label'])){
152
+ unset($fields[$key]['label']);
153
+ }
154
+ if($override_required && isset($props['required'])){
155
+ $fkey = $sname.'_'.$key;
156
+ if(is_array($address_fields) && isset($address_fields[$fkey])){
157
+ $cf_props = $address_fields[$fkey];
158
+ if(is_array($cf_props) && isset($cf_props['required'])){
159
+ $fields[$key]['required'] = $cf_props['required'] ? true : false;
160
+ }
161
+ }
162
+ //unset($fields[$key]['required']);
163
+ }
164
+
165
+ if($override_priority && isset($props['priority'])){
166
+ unset($fields[$key]['priority']);
167
+ //unset($fields[$key]['order']);
168
+ }
169
+ }
170
+ }
171
+ return $fields;
172
+ }
173
+ add_filter('woocommerce_get_country_locale_default', 'thwcfd_prepare_country_locale');
174
+ add_filter('woocommerce_get_country_locale_base', 'thwcfd_prepare_country_locale');
175
+
176
+ function thwcfd_woo_get_country_locale($locale) {
177
+ if(is_array($locale)){
178
+ foreach($locale as $country => $fields){
179
+ $locale[$country] = thwcfd_prepare_country_locale($fields);
180
+ }
181
+ }
182
+ return $locale;
183
+ }
184
+ add_filter('woocommerce_get_country_locale', 'thwcfd_woo_get_country_locale');
185
+
186
+ /**
187
+ * wc_checkout_fields_modify_billing_fields function.
188
+ *
189
+ * @param mixed $fields
190
+ */
191
+ function thwcfd_billing_fields_lite($fields, $country){
192
+ global $supress_field_modification;
193
+
194
+ if($supress_field_modification){
195
+ return $fields;
196
+ }
197
+ if(is_wc_endpoint_url('edit-address')){
198
+ return $fields;
199
+ }else{
200
+ return thwcfd_prepare_address_fields(get_option('wc_fields_billing'), $fields, 'billing', $country);
201
+ }
202
+ }
203
+ add_filter('woocommerce_billing_fields', 'thwcfd_billing_fields_lite', apply_filters('thwcfd_billing_fields_priority', 1000), 2);
204
+
205
+ /**
206
+ * wc_checkout_fields_modify_shipping_fields function.
207
+ *
208
+ * @param mixed $old
209
+ */
210
+ function thwcfd_shipping_fields_lite($fields, $country){
211
+ global $supress_field_modification;
212
+
213
+ if ($supress_field_modification){
214
+ return $fields;
215
+ }
216
+ if(is_wc_endpoint_url('edit-address')){
217
+ return $fields;
218
+ }else{
219
+ return thwcfd_prepare_address_fields(get_option('wc_fields_shipping'), $fields, 'shipping', $country);
220
+ }
221
+ }
222
+ add_filter('woocommerce_shipping_fields', 'thwcfd_shipping_fields_lite', apply_filters('thwcfd_shipping_fields_priority', 1000), 2);
223
+
224
+ /**
225
+ * wc_checkout_fields_modify_shipping_fields function.
226
+ *
227
+ * @param mixed $old
228
+ */
229
+ function thwcfd_checkout_fields_lite( $fields ) {
230
+ global $supress_field_modification;
231
+
232
+ if($supress_field_modification){
233
+ return $fields;
234
+ }
235
+
236
+ if($additional_fields = get_option('wc_fields_additional')){
237
+ if( isset($fields['order']) && is_array($fields['order']) ){
238
+ $fields['order'] = $additional_fields + $fields['order'];
239
+ }
240
+
241
+ // check if order_comments is enabled/disabled
242
+ if(isset($additional_fields) && !$additional_fields['order_comments']['enabled']){
243
+ unset($fields['order']['order_comments']);
244
+ }
245
+ }
246
+
247
+ if(isset($fields['order']) && is_array($fields['order'])){
248
+ $fields['order'] = thwcfd_prepare_checkout_fields_lite($fields['order'], false);
249
+ }
250
+
251
+ return $fields;
252
+ }
253
+ add_filter('woocommerce_checkout_fields', 'thwcfd_checkout_fields_lite', apply_filters('thwcfd_checkout_fields_priority', 1000));
254
+
255
+ /**
256
+ *
257
+ */
258
+ function thwcfd_prepare_address_fields($fieldset, $original_fieldset = false, $sname = 'billing', $country){
259
+ if(is_array($fieldset) && !empty($fieldset)) {
260
+ $locale = WC()->countries->get_country_locale();
261
+ if(isset($locale[ $country ]) && is_array($locale[ $country ])) {
262
+ foreach($locale[ $country ] as $key => $value){
263
+ if(is_array($value) && isset($fieldset[$sname.'_'.$key])){
264
+ if(isset($value['required'])){
265
+ $fieldset[$sname.'_'.$key]['required'] = $value['required'];
266
+ }
267
+ }
268
+ }
269
+ }
270
+ $fieldset = thwcfd_prepare_checkout_fields_lite($fieldset, $original_fieldset);
271
+ return $fieldset;
272
+ }else {
273
+ return $original_fieldset;
274
+ }
275
+ }
276
+
277
+ /**
278
+ * checkout_fields_modify_fields function.
279
+ *
280
+ * @param mixed $data
281
+ * @param mixed $old
282
+ */
283
+ function thwcfd_prepare_checkout_fields_lite($fields, $original_fields) {
284
+ if(is_array($fields) && !empty($fields)) {
285
+ foreach($fields as $name => $field) {
286
+ if(isset($field['enabled']) && $field['enabled'] == false ) {
287
+ unset($fields[$name]);
288
+ }else{
289
+ $new_field = false;
290
+ $allow_override = apply_filters('thwcfd_allow_default_field_override_'.$name, false);
291
+
292
+ if($original_fields && isset($original_fields[$name]) && !$allow_override){
293
+ $new_field = $original_fields[$name];
294
+
295
+ $new_field['label'] = isset($field['label']) ? $field['label'] : '';
296
+ $new_field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : '';
297
+
298
+ $new_field['class'] = isset($field['class']) && is_array($field['class']) ? $field['class'] : array();
299
+ $new_field['label_class'] = isset($field['label_class']) && is_array($field['label_class']) ? $field['label_class'] : array();
300
+ $new_field['validate'] = isset($field['validate']) && is_array($field['validate']) ? $field['validate'] : array();
301
+
302
+ /*if(!thwcfd_is_locale_field($name)){
303
+ $new_field['required'] = isset($field['required']) ? $field['required'] : 0;
304
+ }*/
305
+ $new_field['required'] = isset($field['required']) ? $field['required'] : 0;
306
+ $new_field['clear'] = isset($field['clear']) ? $field['clear'] : 0;
307
+ }else{
308
+ $new_field = $field;
309
+ }
310
+
311
+ if(isset($new_field['type']) && $new_field['type'] === 'select'){
312
+ if(apply_filters('thwcfd_enable_select2_for_select_fields', true)){
313
+ $new_field['input_class'][] = 'thwcfd-enhanced-select';
314
+ }
315
+ }
316
+
317
+ $new_field['order'] = isset($field['order']) && is_numeric($field['order']) ? $field['order'] : 0;
318
+ if(isset($new_field['order']) && is_numeric($new_field['order'])){
319
+ $priority = ($new_field['order']+1)*10;
320
+ $new_field['priority'] = $priority;
321
+ //$new_field['priority'] = $new_field['order'];
322
+ }
323
+
324
+ if(isset($new_field['label'])){
325
+ $new_field['label'] = __($new_field['label'], 'woocommerce');
326
+ }
327
+ if(isset($new_field['placeholder'])){
328
+ $new_field['placeholder'] = __($new_field['placeholder'], 'woocommerce');
329
+ }
330
+
331
+ $fields[$name] = $new_field;
332
+ }
333
+ }
334
+ return $fields;
335
+ }else {
336
+ return $original_fields;
337
+ }
338
+ }
339
+
340
+ /*****************************************
341
+ ----- Display Field Values - START ------
342
+ *****************************************/
343
+
344
+ /**
345
+ * Display custom fields in emails
346
+ *
347
+ * @param array $keys
348
+ * @return array
349
+ */
350
+ function thwcfd_display_custom_fields_in_emails_lite($ofields, $sent_to_admin, $order){
351
+ $custom_fields = array();
352
+ $fields = array_merge(WC_Checkout_Field_Editor::get_fields('billing'), WC_Checkout_Field_Editor::get_fields('shipping'),
353
+ WC_Checkout_Field_Editor::get_fields('additional'));
354
+
355
+ // Loop through all custom fields to see if it should be added
356
+ foreach( $fields as $key => $options ) {
357
+ if(isset($options['show_in_email']) && $options['show_in_email']){
358
+ $value = '';
359
+ if(thwcfd_woo_version_check()){
360
+ $value = get_post_meta( $order->get_id(), $key, true );
361
+ }else{
362
+ $value = get_post_meta( $order->id, $key, true );
363
+ }
364
+
365
+ if(!empty($value)){
366
+ $label = isset($options['label']) && $options['label'] ? $options['label'] : $key;
367
+ $label = esc_attr($label);
368
+
369
+ $custom_field = array();
370
+ $custom_field['label'] = $label;
371
+ $custom_field['value'] = $value;
372
+
373
+ $custom_fields[$key] = $custom_field;
374
+ }
375
+ }
376
+ }
377
+
378
+ return array_merge($ofields, $custom_fields);
379
+ }
380
+ add_filter('woocommerce_email_order_meta_fields', 'thwcfd_display_custom_fields_in_emails_lite', 10, 3);
381
+
382
+ /**
383
+ * Display custom checkout fields on view order pages
384
+ *
385
+ * @param object $order
386
+ */
387
+ function thwcfd_order_details_after_customer_details_lite($order){
388
+ if(thwcfd_woocommerce_version_check()){
389
+ $order_id = $order->get_id();
390
+ }else{
391
+ $order_id = $order->id;
392
+ }
393
+
394
+ $fields = array();
395
+ if(!wc_ship_to_billing_address_only() && $order->needs_shipping_address()){
396
+ $fields = array_merge(WC_Checkout_Field_Editor::get_fields('billing'), WC_Checkout_Field_Editor::get_fields('shipping'),
397
+ WC_Checkout_Field_Editor::get_fields('additional'));
398
+ }else{
399
+ $fields = array_merge(WC_Checkout_Field_Editor::get_fields('billing'), WC_Checkout_Field_Editor::get_fields('additional'));
400
+ }
401
+
402
+ if(is_array($fields) && !empty($fields)){
403
+ $fields_html = '';
404
+ // Loop through all custom fields to see if it should be added
405
+ foreach($fields as $name => $options){
406
+ $enabled = (isset($options['enabled']) && $options['enabled'] == false) ? false : true;
407
+ $is_custom_field = (isset($options['custom']) && $options['custom'] == true) ? true : false;
408
+
409
+ if(isset($options['show_in_order']) && $options['show_in_order'] && $enabled && $is_custom_field){
410
+ $value = get_post_meta($order_id, $name, true);
411
+
412
+ if(!empty($value)){
413
+ $label = isset($options['label']) && !empty($options['label']) ? __( $options['label'], 'woocommerce' ) : $name;
414
+
415
+ if(is_account_page()){
416
+ if(apply_filters( 'thwcfd_view_order_customer_details_table_view', true )){
417
+ $fields_html .= '<tr><th>'. esc_attr($label) .':</th><td>'. wptexturize($value) .'</td></tr>';
418
+ }else{
419
+ $fields_html .= '<br/><dt>'. esc_attr($label) .':</dt><dd>'. wptexturize($value) .'</dd>';
420
+ }
421
+ }else{
422
+ if(apply_filters( 'thwcfd_thankyou_customer_details_table_view', true )){
423
+ $fields_html .= '<tr><th>'. esc_attr($label) .':</th><td>'. wptexturize($value) .'</td></tr>';
424
+ }else{
425
+ $fields_html .= '<br/><dt>'. esc_attr($label) .':</dt><dd>'. wptexturize($value) .'</dd>';
426
+ }
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ if($fields_html){
433
+ do_action( 'thwcfd_order_details_before_custom_fields_table', $order );
434
+ ?>
435
+ <table class="woocommerce-table woocommerce-table--custom-fields shop_table custom-fields">
436
+ <?php
437
+ echo $fields_html;
438
+ ?>
439
+ </table>
440
+ <?php
441
+ do_action( 'thwcfd_order_details_after_custom_fields_table', $order );
442
+ }
443
+ }
444
+ }
445
+ add_action('woocommerce_order_details_after_order_table', 'thwcfd_order_details_after_customer_details_lite', 20, 1);
446
+
447
+ /*****************************************
448
+ ----- Display Field Values - END --------
449
+ *****************************************/
450
+
451
+ function thwcfd_woo_version_check( $version = '3.0' ) {
452
+ if(function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) {
453
+ global $woocommerce;
454
+ if( version_compare( $woocommerce->version, $version, ">=" ) ) {
455
+ return true;
456
+ }
457
+ }
458
+ return false;
459
+ }
460
+
461
+ }
classes/class-wc-checkout-field-editor-export-handler.php DELETED
@@ -1,74 +0,0 @@
1
- <?php
2
- if(!defined( 'ABSPATH' )) exit;
3
-
4
- class WC_Checkout_Field_Editor_Export_Handler {
5
- private $fields;
6
-
7
- public function __construct() {
8
- $this->fields = $this->get_fields();
9
-
10
- // Customer / Order CSV Export column headers/data
11
- //add_filter( 'wc_customer_order_csv_export_order_headers', array( $this, 'thwcfd_order_csv_export_order_headers' ), 10, 2 );
12
- //add_filter( 'wc_customer_order_csv_export_order_row', array( $this, 'thwcfd_customer_order_csv_export_order_row' ), 10, 4 );
13
- }
14
-
15
- /**
16
- * Adds support for Customer/Order CSV Export by adding a vendor column header
17
- */
18
- public function thwcfd_order_csv_export_order_headers($headers, $csv_generator) {
19
- $field_headers = array();
20
-
21
- foreach ( $this->fields as $name => $options ) {
22
- $field_headers[ $name ] = $name;
23
- }
24
-
25
- return array_merge( $headers, $field_headers );
26
- }
27
-
28
- /**
29
- * Adds support for Customer/Order CSV Export by adding checkout editor field data
30
- */
31
- public function thwcfd_customer_order_csv_export_order_row( $order_data, $order, $csv_generator ) {
32
- $field_data = array();
33
-
34
- foreach ( $this->fields as $name => $options ) {
35
- $field_data[ $name ] = get_post_meta( $order->id, $name, true );
36
- }
37
-
38
- $new_order_data = array();
39
-
40
- if(isset($csv_generator->order_format) && ($csv_generator->order_format == 'default_one_row_per_item' || $csv_generator->order_format == 'legacy_one_row_per_item')){
41
- foreach($order_data as $data){
42
- $new_order_data[] = array_merge( $field_data, (array) $data );
43
- }
44
- } else {
45
- $new_order_data = array_merge( $field_data, $order_data );
46
- }
47
-
48
- return $new_order_data;
49
- }
50
-
51
- /**
52
- * Get all checkout fields
53
- */
54
- private function get_fields() {
55
- $fields = array();
56
-
57
- $billing_fields = get_option( 'wc_fields_billing' );
58
- if($billing_fields !== false){
59
- $fields = array_merge( $fields, $billing_fields );
60
- }
61
-
62
- $shipping_fields = get_option( 'wc_fields_shipping' );
63
- if($shipping_fields !== false){
64
- $fields = array_merge( $fields, $shipping_fields );
65
- }
66
-
67
- $additional_fields = get_option( 'wc_fields_additional' );
68
- if($additional_fields !== false){
69
- $fields = array_merge( $fields, $additional_fields );
70
- }
71
-
72
- return $fields;
73
- }
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wc-checkout-field-editor.php CHANGED
@@ -1,722 +1,723 @@
1
- <?php
2
- if(!defined( 'ABSPATH' )) exit;
3
-
4
- /**
5
- * WC_Checkout_Field_Editor class.
6
- */
7
- class WC_Checkout_Field_Editor {
8
-
9
- /**
10
- * __construct function.
11
- */
12
- public function __construct() {
13
- // Validation rules are controlled by the local fields and can't be changed
14
- $this->locale_fields = array(
15
- 'billing_address_1', 'billing_address_2', 'billing_state', 'billing_postcode', 'billing_city',
16
- 'shipping_address_1', 'shipping_address_2', 'shipping_state', 'shipping_postcode', 'shipping_city',
17
- 'order_comments'
18
- );
19
-
20
- add_action('admin_menu', array($this, 'admin_menu'));
21
- add_filter('woocommerce_screen_ids', array($this, 'add_screen_id'));
22
- add_filter('plugin_action_links_'.TH_WCFD_BASE_NAME, array($this, 'add_settings_link'));
23
- add_action('woocommerce_checkout_update_order_meta', array($this, 'save_data'), 10, 2);
24
- }
25
-
26
- /**
27
- * menu function.
28
- */
29
- public function admin_menu() {
30
- $this->screen_id = add_submenu_page('woocommerce', __('WooCommerce Checkout Form Designer', 'thwcfd'), __('Checkout Form', 'thwcfd'),
31
- 'manage_woocommerce', 'checkout_form_designer', array($this, 'the_designer'));
32
-
33
- add_action('admin_print_scripts-'. $this->screen_id, array($this, 'enqueue_admin_scripts'));
34
- }
35
-
36
- /**
37
- * add_screen_id function.
38
- */
39
- public function add_screen_id($ids){
40
- $ids[] = 'woocommerce_page_checkout_form_designer';
41
- $ids[] = strtolower(__('WooCommerce', 'thwcfd')) .'_page_checkout_form_designer';
42
-
43
- return $ids;
44
- }
45
-
46
- public function add_settings_link($links) {
47
- $settings_link = '<a href="'.admin_url('admin.php?page=checkout_form_designer').'">'. __('Settings') .'</a>';
48
- array_unshift($links, $settings_link);
49
- return $links;
50
- }
51
-
52
- /**
53
- * scripts function.
54
- */
55
- public function enqueue_admin_scripts() {
56
- wp_enqueue_style ('thwcfd-style', plugins_url('/assets/css/thwcfd-style.css', dirname(__FILE__)));
57
- wp_enqueue_script('thwcfd-admin-script', plugins_url('/assets/js/thwcfd-admin.js', dirname(__FILE__)), array('jquery', 'jquery-ui-dialog', 'jquery-ui-sortable',
58
- 'woocommerce_admin', 'select2', 'jquery-tiptip'), TH_WCFD_VERSION, true);
59
- }
60
-
61
- public function output_premium_version_notice(){
62
- ?>
63
- <div id="message" class="wc-connect updated thwcfd-notice">
64
- <div class="squeezer">
65
- <table>
66
- <tr>
67
- <td width="70%">
68
- <p><strong><i>WooCommerce Checkout Field Editor Pro</i></strong> premium version provides more features to design your checkout page.</p>
69
- <ul>
70
- <li>12 field types available,<br/>(<i>Text, Hidden, Password, Textarea, Radio, Checkbox, Select, Multi-select, Date Picker, Time Picker, Heading, Label</i>).</li>
71
- <li>Conditionally display fields based on cart items and other field(s) values.</li>
72
- <li>Add an extra cost to the cart total based on field selection.</li>
73
- <li>Option to add more sections in addition to the core sections (billing, shipping and additional) in checkout page.</li>
74
- </ul>
75
- </td>
76
- <td>
77
- <a target="_blank" href="https://www.themehigh.com/product/woocommerce-checkout-field-editor-pro/" class="">
78
- <img src="<?php echo plugins_url( '../assets/css/upgrade-btn.png', __FILE__ ); ?>" />
79
- </a>
80
- </td>
81
- </tr>
82
- </table>
83
- </div>
84
- </div>
85
- <?php
86
- }
87
-
88
- /**
89
- * Reset checkout fields.
90
- */
91
- public function reset_checkout_fields() {
92
- delete_option('wc_fields_billing');
93
- delete_option('wc_fields_shipping');
94
- delete_option('wc_fields_additional');
95
- echo '<div class="updated"><p>'. __('SUCCESS: Checkout fields successfully reset', 'thwcfd') .'</p></div>';
96
- }
97
-
98
- public function is_reserved_field_name( $field_name ){
99
- if($field_name && in_array($field_name, array(
100
- 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state',
101
- 'billing_country', 'billing_postcode', 'billing_phone', 'billing_email',
102
- 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_state',
103
- 'shipping_country', 'shipping_postcode', 'customer_note', 'order_comments'
104
- ))){
105
- return true;
106
- }
107
- return false;
108
- }
109
-
110
- public function is_default_field_name($field_name){
111
- if($field_name && in_array($field_name, array(
112
- 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state',
113
- 'billing_country', 'billing_postcode', 'billing_phone', 'billing_email',
114
- 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_state',
115
- 'shipping_country', 'shipping_postcode', 'customer_note', 'order_comments'
116
- ))){
117
- return true;
118
- }
119
- return false;
120
- }
121
-
122
- /**
123
- * Save Data function.
124
- */
125
- public function save_data($order_id, $posted){
126
- $types = array('billing', 'shipping', 'additional');
127
-
128
- foreach($types as $type){
129
- $fields = $this->get_fields($type);
130
-
131
- foreach($fields as $name => $field){
132
- if(isset($field['custom']) && $field['custom'] && isset($posted[$name])){
133
- $value = wc_clean($posted[$name]);
134
- if($value){
135
- update_post_meta($order_id, $name, $value);
136
- }
137
- }
138
- }
139
- }
140
- }
141
-
142
- public static function get_fields($key){
143
- $fields = array_filter(get_option('wc_fields_'. $key, array()));
144
-
145
- if(empty($fields) || sizeof($fields) == 0){
146
- if($key === 'billing' || $key === 'shipping'){
147
- $fields = WC()->countries->get_address_fields(WC()->countries->get_base_country(), $key . '_');
148
-
149
- } else if($key === 'additional'){
150
- $fields = array(
151
- 'order_comments' => array(
152
- 'type' => 'textarea',
153
- 'class' => array('notes'),
154
- 'label' => __('Order Notes', 'woocommerce'),
155
- 'placeholder' => _x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')
156
- )
157
- );
158
- }
159
- }
160
- return $fields;
161
- }
162
-
163
- public function sort_fields_by_order($a, $b){
164
- if(!isset($a['order']) || $a['order'] == $b['order']){
165
- return 0;
166
- }
167
- return ($a['order'] < $b['order']) ? -1 : 1;
168
- }
169
-
170
- public function get_field_types(){
171
- return array(
172
- 'text' => 'Text',
173
- 'select' => 'Select',
174
- );
175
- }
176
-
177
- /*
178
- * New field form popup
179
- */
180
- public function wcfd_new_field_form_pp(){
181
- $field_types = $this->get_field_types();
182
- ?>
183
- <div id="wcfd_new_field_form_pp" title="New Checkout Field" class="wcfd_popup_wrapper">
184
- <form>
185
- <table>
186
- <tr>
187
- <td colspan="2" class="err_msgs"></td>
188
- </tr>
189
- <tr>
190
- <td width="40%">Type</td>
191
- <td>
192
- <select name="ftype" style="width:150px;" onchange="fieldTypeChangeListner(this)">
193
- <?php foreach($field_types as $value=>$label){ ?>
194
- <option value="<?php echo trim($value); ?>"><?php echo $label; ?></option>
195
- <?php } ?>
196
- </select>
197
- </td>
198
- </tr>
199
- <tr>
200
- <td>Name</td>
201
- <td><input type="text" name="fname" style="width:250px;"/></td>
202
- </tr>
203
- <tr>
204
- <td>Label</td>
205
- <td><input type="text" name="flabel" style="width:250px;"/></td>
206
- </tr>
207
- <tr class="rowPlaceholder">
208
- <td>Placeholder</td>
209
- <td><input type="text" name="fplaceholder" style="width:250px;"/></td>
210
- </tr>
211
- <tr class="rowOptions">
212
- <td>Options</td>
213
- <td><input type="text" name="foptions" placeholder="Seperate options with pipe(|)" style="width:250px;"/></td>
214
- </tr>
215
- <tr class="rowClass">
216
- <td>Class</td>
217
- <td><input type="text" name="fclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
218
- </tr>
219
- <!--<tr class="rowLabelClass">
220
- <td>Label Class</td>
221
- <td><input type="text" name="flabelclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
222
- </tr>-->
223
- <tr class="rowValidate">
224
- <td>Validation</td>
225
- <td>
226
- <select multiple="multiple" name="fvalidate" placeholder="Select validations" class="thwcfd-enhanced-multi-select"
227
- style="width: 250px; height:30px;">
228
- <option value="email">Email</option>
229
- <option value="phone">Phone</option>
230
- <option value="postcode">Postcode</option>
231
- <option value="state">State</option>
232
- </select>
233
- </td>
234
- </tr>
235
- <tr class="rowRequired">
236
- <td>&nbsp;</td>
237
- <td>
238
- <input type="checkbox" name="frequired" value="yes" checked/>
239
- <label>Required</label><br/>
240
-
241
- <input type="checkbox" name="fclearRow" value="yes" checked/>
242
- <label>Clear Row</label><br/>
243
-
244
- <input type="checkbox" name="fenabled" value="yes" checked/>
245
- <label>Enabled</label>
246
- </td>
247
- </tr>
248
- <tr class="rowShowInEmail">
249
- <td>&nbsp;</td>
250
- <td>
251
- <input type="checkbox" name="fshowinemail" value="email" checked/>
252
- <label>Display in Emails</label>
253
- </td>
254
- </tr>
255
- <tr class="rowShowInOrder">
256
- <td>&nbsp;</td>
257
- <td>
258
- <input type="checkbox" name="fshowinorder" value="order-review" checked/>
259
- <label>Display in Order Detail Pages</label>
260
- </td>
261
- </tr>
262
- </table>
263
- </form>
264
- </div>
265
- <?php
266
- }
267
-
268
- /*
269
- * New field form popup
270
- */
271
- public function wcfd_edit_field_form_pp(){
272
- $field_types = $this->get_field_types();
273
- ?>
274
- <div id="wcfd_edit_field_form_pp" title="Edit Checkout Field" class="wcfd_popup_wrapper">
275
- <form>
276
- <table>
277
- <tr>
278
- <td colspan="2" class="err_msgs"></td>
279
- </tr>
280
- <tr>
281
- <td width="40%">Name</td>
282
- <td>
283
- <input type="hidden" name="rowId"/>
284
- <input type="hidden" name="fname"/>
285
- <input type="text" name="fnameNew" style="width:250px;"/>
286
- </td>
287
- </tr>
288
- <tr>
289
- <td>Type</td>
290
- <td>
291
- <select name="ftype" style="width:150px;" onchange="fieldTypeChangeListner(this)">
292
- <?php foreach($field_types as $value=>$label){ ?>
293
- <option value="<?php echo trim($value); ?>"><?php echo $label; ?></option>
294
- <?php } ?>
295
- </select>
296
- </td>
297
- </tr>
298
- <tr>
299
- <td>Label</td>
300
- <td><input type="text" name="flabel" style="width:250px;"/></td>
301
- </tr>
302
- <tr class="rowPlaceholder">
303
- <td>Placeholder</td>
304
- <td><input type="text" name="fplaceholder" style="width:250px;"/></td>
305
- </tr>
306
- <tr class="rowOptions">
307
- <td>Options</td>
308
- <td><input type="text" name="foptions" placeholder="Seperate options with pipe(|)" style="width:250px;"/></td>
309
- </tr>
310
- <tr class="rowClass">
311
- <td>Class</td>
312
- <td><input type="text" name="fclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
313
- </tr>
314
- <!--<tr class="rowLabelClass">
315
- <td>Label Class</td>
316
- <td><input type="text" name="flabelclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
317
- </tr>-->
318
- <tr class="rowValidate">
319
- <td>Validation</td>
320
- <td>
321
- <select multiple="multiple" name="fvalidate" placeholder="Select validations" class="thwcfd-enhanced-multi-select"
322
- style="width: 250px; height:30px;">
323
- <option value="email">Email</option>
324
- <option value="phone">Phone</option>
325
- <option value="postcode">Postcode</option>
326
- <option value="state">State</option>
327
- </select>
328
- </td>
329
- </tr>
330
- <tr class="rowRequired">
331
- <td>&nbsp;</td>
332
- <td>
333
- <input type="checkbox" name="frequired" value="yes" checked/>
334
- <label>Required</label><br/>
335
-
336
- <input type="checkbox" name="fclearRow" value="yes" checked/>
337
- <label>Clear Row</label><br/>
338
-
339
- <input type="checkbox" name="fenabled" value="yes" checked/>
340
- <label>Enabled</label>
341
- </td>
342
- </tr>
343
- <tr class="rowShowInEmail">
344
- <td>&nbsp;</td>
345
- <td>
346
- <input type="checkbox" name="fshowinemail" value="email" checked/>
347
- <label>Display in Emails</label>
348
- </td>
349
- </tr>
350
- <tr class="rowShowInOrder">
351
- <td>&nbsp;</td>
352
- <td>
353
- <input type="checkbox" name="fshowinorder" value="order-review" checked/>
354
- <label>Display in Order Detail Pages</label>
355
- </td>
356
- </tr>
357
- </table>
358
- </form>
359
- </div>
360
- <?php
361
- }
362
-
363
- public function render_tabs_and_sections(){
364
- $tabs = array( 'fields' => 'Checkout Fields' );
365
- $tab = isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'fields';
366
-
367
- $sections = ''; $section = '';
368
- if($tab === 'fields'){
369
- $sections = array( 'billing', 'shipping', 'additional' );
370
- $section = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : 'billing';
371
- }
372
-
373
- echo '<h2 class="nav-tab-wrapper woo-nav-tab-wrapper">';
374
- foreach( $tabs as $key => $value ) {
375
- $active = ( $key == $tab ) ? 'nav-tab-active' : '';
376
- echo '<a class="nav-tab '.$active.'" href="'.admin_url('admin.php?page=checkout_form_designer&tab='.$key).'">'.$value.'</a>';
377
- }
378
- echo '</h2>';
379
-
380
- if(!empty($sections)){
381
- echo '<ul class="thwcfd-sections">';
382
- $size = sizeof($sections); $i = 0;
383
- foreach( $sections as $key ) {
384
- $i++;
385
- $active = ( $key == $section ) ? 'current' : '';
386
- $url = 'admin.php?page=checkout_form_designer&tab=fields&section='.$key;
387
- echo '<li>';
388
- echo '<a href="'.admin_url($url).'" class="'.$active.'" >'.ucwords($key).' '.__('Fields', 'thwcfd').'</a>';
389
- echo ($size > $i) ? ' | ' : '';
390
- echo '</li>';
391
- }
392
- echo '</ul>';
393
- }
394
-
395
- $this->output_premium_version_notice();
396
- }
397
-
398
- public function get_current_tab(){
399
- return isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'fields';
400
- }
401
-
402
- public function get_current_section(){
403
- $tab = $this->get_current_tab();
404
- $section = '';
405
- if($tab === 'fields'){
406
- $section = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : 'billing';
407
- }
408
- return $section;
409
- }
410
-
411
- public function render_checkout_fields_heading_row(){
412
- ?>
413
- <th class="sort"></th>
414
- <th class="check-column" style="padding-left:0px !important;"><input type="checkbox" style="margin-left:7px;" onclick="thwcfdSelectAllCheckoutFields(this)"/></th>
415
- <th class="name">Name</th>
416
- <th class="id">Type</th>
417
- <th>Label</th>
418
- <th>Placeholder</th>
419
- <th>Validation Rules</th>
420
- <th class="status">Required</th>
421
- <th class="status">Clear Row</th>
422
- <th class="status">Enabled</th>
423
- <th class="status">Edit</th>
424
- <?php
425
- }
426
-
427
- public function render_actions_row($section){
428
- ?>
429
- <th colspan="7">
430
- <button type="button" class="button button-primary" onclick="openNewFieldForm('<?php echo $section; ?>')"><?php _e( '+ Add field', 'thwcfd' ); ?></button>
431
- <button type="button" class="button" onclick="removeSelectedFields()"><?php _e( 'Remove', 'thwcfd' ); ?></button>
432
- <button type="button" class="button" onclick="enableSelectedFields()"><?php _e( 'Enable', 'thwcfd' ); ?></button>
433
- <button type="button" class="button" onclick="disableSelectedFields()"><?php _e( 'Disable', 'thwcfd' ); ?></button>
434
- </th>
435
- <th colspan="4">
436
- <input type="submit" name="save_fields" class="button-primary" value="<?php _e( 'Save changes', 'thwcfd' ) ?>" style="float:right" />
437
- <input type="submit" name="reset_fields" class="button" value="<?php _e( 'Reset to default fields', 'thwcfd' ) ?>" style="float:right; margin-right: 5px;"
438
- onclick="return confirm('Are you sure you want to reset to default fields? all your changes will be deleted.');"/>
439
- </th>
440
- <?php
441
- }
442
-
443
- public function the_designer() {
444
- $tab = $this->get_current_tab();
445
- if($tab === 'fields'){
446
- $this->checkout_form_field_editor();
447
- }
448
- }
449
-
450
- public function checkout_form_field_editor() {
451
- $section = $this->get_current_section();
452
-
453
- echo '<div class="wrap woocommerce"><div class="icon32 icon32-attributes" id="icon-woocommerce"><br /></div>';
454
- $this->render_tabs_and_sections();
455
-
456
- if ( isset( $_POST['save_fields'] ) )
457
- echo $this->save_options( $section );
458
-
459
- if ( isset( $_POST['reset_fields'] ) )
460
- echo $this->reset_checkout_fields();
461
-
462
- global $supress_field_modification;
463
- $supress_field_modification = false;
464
- ?>
465
-
466
- <form method="post" id="wcfd_checkout_fields_form" action="">
467
- <table id="wcfd_checkout_fields" class="wc_gateways widefat" cellspacing="0">
468
- <thead>
469
- <tr><?php $this->render_actions_row($section); ?></tr>
470
- <tr><?php $this->render_checkout_fields_heading_row(); ?></tr>
471
- </thead>
472
- <tfoot>
473
- <tr><?php $this->render_checkout_fields_heading_row(); ?></tr>
474
- <tr><?php $this->render_actions_row($section); ?></tr>
475
- </tfoot>
476
- <tbody class="ui-sortable">
477
- <?php
478
- $i=0;
479
- foreach( $this->get_fields( $section ) as $name => $options ) :
480
- if ( isset( $options['custom'] ) && $options['custom'] == 1 ) {
481
- $options['custom'] = '1';
482
- } else {
483
- $options['custom'] = '0';
484
- }
485
-
486
- if ( !isset( $options['label'] ) ) {
487
- $options['label'] = '';
488
- }
489
-
490
- if ( !isset( $options['placeholder'] ) ) {
491
- $options['placeholder'] = '';
492
- }
493
-
494
- if( isset( $options['options'] ) && is_array($options['options']) ) {
495
- $options['options'] = implode("|", $options['options']);
496
- }else{
497
- $options['options'] = '';
498
- }
499
-
500
- if( isset( $options['class'] ) && is_array($options['class']) ) {
501
- $options['class'] = implode(",", $options['class']);
502
- }else{
503
- $options['class'] = '';
504
- }
505
-
506
- if( isset( $options['label_class'] ) && is_array($options['label_class']) ) {
507
- $options['label_class'] = implode(",", $options['label_class']);
508
- }else{
509
- $options['label_class'] = '';
510
- }
511
-
512
- if( isset( $options['validate'] ) && is_array($options['validate']) ) {
513
- $options['validate'] = implode(",", $options['validate']);
514
- }else{
515
- $options['validate'] = '';
516
- }
517
-
518
- if ( isset( $options['required'] ) && $options['required'] == 1 ) {
519
- $options['required'] = '1';
520
- } else {
521
- $options['required'] = '0';
522
- }
523
-
524
- if ( isset( $options['clear'] ) && $options['clear'] == 1 ) {
525
- $options['clear'] = '1';
526
- } else {
527
- $options['clear'] = '0';
528
- }
529
-
530
- if ( !isset( $options['enabled'] ) || $options['enabled'] == 1 ) {
531
- $options['enabled'] = '1';
532
- } else {
533
- $options['enabled'] = '0';
534
- }
535
-
536
- if ( !isset( $options['type'] ) ) {
537
- $options['type'] = 'text';
538
- }
539
-
540
- if ( isset( $options['show_in_email'] ) && $options['show_in_email'] == 1 ) {
541
- $options['show_in_email'] = '1';
542
- } else {
543
- $options['show_in_email'] = '0';
544
- }
545
-
546
- if ( isset( $options['show_in_order'] ) && $options['show_in_order'] == 1 ) {
547
- $options['show_in_order'] = '1';
548
- } else {
549
- $options['show_in_order'] = '0';
550
- }
551
- ?>
552
- <tr class="row_<?php echo $i; echo($options['enabled'] == 1 ? '' : ' thwcfd-disabled') ?>">
553
- <td width="1%" class="sort ui-sortable-handle">
554
- <input type="hidden" name="f_custom[<?php echo $i; ?>]" class="f_custom" value="<?php echo $options['custom']; ?>" />
555
- <input type="hidden" name="f_order[<?php echo $i; ?>]" class="f_order" value="<?php echo $i; ?>" />
556
-
557
- <input type="hidden" name="f_name[<?php echo $i; ?>]" class="f_name" value="<?php echo esc_attr( $name ); ?>" />
558
- <input type="hidden" name="f_name_new[<?php echo $i; ?>]" class="f_name_new" value="" />
559
- <input type="hidden" name="f_type[<?php echo $i; ?>]" class="f_type" value="<?php echo $options['type']; ?>" />
560
- <input type="hidden" name="f_label[<?php echo $i; ?>]" class="f_label" value="<?php echo $options['label']; ?>" />
561
- <input type="hidden" name="f_placeholder[<?php echo $i; ?>]" class="f_placeholder" value="<?php echo $options['placeholder']; ?>" />
562
- <input type="hidden" name="f_options[<?php echo $i; ?>]" class="f_options" value="<?php echo($options['options']) ?>" />
563
-
564
- <input type="hidden" name="f_class[<?php echo $i; ?>]" class="f_class" value="<?php echo $options['class']; ?>" />
565
- <input type="hidden" name="f_label_class[<?php echo $i; ?>]" class="f_label_class" value="<?php echo $options['label_class']; ?>" />
566
-
567
- <input type="hidden" name="f_required[<?php echo $i; ?>]" class="f_required" value="<?php echo($options['required']) ?>" />
568
- <input type="hidden" name="f_clear[<?php echo $i; ?>]" class="f_clear" value="<?php echo($options['clear']) ?>" />
569
-
570
- <input type="hidden" name="f_enabled[<?php echo $i; ?>]" class="f_enabled" value="<?php echo($options['enabled']) ?>" />
571
- <input type="hidden" name="f_validation[<?php echo $i; ?>]" class="f_validation" value="<?php echo($options['validate']) ?>" />
572
- <input type="hidden" name="f_show_in_email[<?php echo $i; ?>]" class="f_show_in_email" value="<?php echo($options['show_in_email']) ?>" />
573
- <input type="hidden" name="f_show_in_order[<?php echo $i; ?>]" class="f_show_in_order" value="<?php echo($options['show_in_order']) ?>" />
574
- <input type="hidden" name="f_deleted[<?php echo $i; ?>]" class="f_deleted" value="0" />
575
-
576
- <!--$properties = array('type', 'label', 'placeholder', 'class', 'required', 'clear', 'label_class', 'options');-->
577
- </td>
578
- <td class="td_select"><input type="checkbox" name="select_field"/></td>
579
- <td class="td_name"><?php echo esc_attr( $name ); ?></td>
580
- <td class="td_type"><?php echo $options['type']; ?></td>
581
- <td class="td_label"><?php echo $options['label']; ?></td>
582
- <td class="td_placeholder"><?php echo $options['placeholder']; ?></td>
583
- <td class="td_validate"><?php echo $options['validate']; ?></td>
584
- <td class="td_required status"><?php echo($options['required'] == 1 ? '<span class="status-enabled tips">Yes</span>' : '-' ) ?></td>
585
- <td class="td_clear status"><?php echo($options['clear'] == 1 ? '<span class="status-enabled tips">Yes</span>' : '-' ) ?></td>
586
- <td class="td_enabled status"><?php echo($options['enabled'] == 1 ? '<span class="status-enabled tips">Yes</span>' : '-' ) ?></td>
587
- <td class="td_edit">
588
- <button type="button" class="f_edit_btn" <?php echo($options['enabled'] == 1 ? '' : 'disabled') ?>
589
- onclick="openEditFieldForm(this,<?php echo $i; ?>)"><?php _e( 'Edit', 'thwcfd' ); ?></button>
590
- </td>
591
- </tr>
592
- <?php $i++; endforeach; ?>
593
- </tbody>
594
- </table>
595
- </form>
596
- <?php
597
- $this->wcfd_new_field_form_pp();
598
- $this->wcfd_edit_field_form_pp();
599
- ?>
600
- </div>
601
- <?php
602
- }
603
-
604
- public function save_options( $section ) {
605
- $o_fields = $this->get_fields( $section );
606
- $fields = $o_fields;
607
- //$core_fields = array_keys( WC()->countries->get_address_fields( WC()->countries->get_base_country(), $section . '_' ) );
608
- //$core_fields[] = 'order_comments';
609
-
610
- $f_order = ! empty( $_POST['f_order'] ) ? $_POST['f_order'] : array();
611
-
612
- $f_names = ! empty( $_POST['f_name'] ) ? $_POST['f_name'] : array();
613
- $f_names_new = ! empty( $_POST['f_name_new'] ) ? $_POST['f_name_new'] : array();
614
- $f_types = ! empty( $_POST['f_type'] ) ? $_POST['f_type'] : array();
615
- $f_labels = ! empty( $_POST['f_label'] ) ? $_POST['f_label'] : array();
616
- $f_placeholder = ! empty( $_POST['f_placeholder'] ) ? $_POST['f_placeholder'] : array();
617
- $f_options = ! empty( $_POST['f_options'] ) ? $_POST['f_options'] : array();
618
-
619
- $f_class = ! empty( $_POST['f_class'] ) ? $_POST['f_class'] : array();
620
- $f_label_class = ! empty( $_POST['f_label_class'] ) ? $_POST['f_label_class'] : array();
621
-
622
- $f_required = ! empty( $_POST['f_required'] ) ? $_POST['f_required'] : array();
623
- $f_clear = ! empty( $_POST['f_clear'] ) ? $_POST['f_clear'] : array();
624
- $f_enabled = ! empty( $_POST['f_enabled'] ) ? $_POST['f_enabled'] : array();
625
-
626
- $f_show_in_email = ! empty( $_POST['f_show_in_email'] ) ? $_POST['f_show_in_email'] : array();
627
- $f_show_in_order = ! empty( $_POST['f_show_in_order'] ) ? $_POST['f_show_in_order'] : array();
628
-
629
- $f_validation = ! empty( $_POST['f_validation'] ) ? $_POST['f_validation'] : array();
630
- $f_deleted = ! empty( $_POST['f_deleted'] ) ? $_POST['f_deleted'] : array();
631
-
632
- $f_position = ! empty( $_POST['f_position'] ) ? $_POST['f_position'] : array();
633
- $f_display_options = ! empty( $_POST['f_display_options'] ) ? $_POST['f_display_options'] : array();
634
- $max = max( array_map( 'absint', array_keys( $f_names ) ) );
635
-
636
- for ( $i = 0; $i <= $max; $i ++ ) {
637
- $name = empty( $f_names[$i] ) ? '' : urldecode( sanitize_title( wc_clean( stripslashes( $f_names[$i] ) ) ) );
638
- $new_name = empty( $f_names_new[$i] ) ? '' : urldecode( sanitize_title( wc_clean( stripslashes( $f_names_new[$i] ) ) ) );
639
-
640
- if(!empty($f_deleted[$i]) && $f_deleted[$i] == 1){
641
- unset( $fields[$name] );
642
- continue;
643
- }
644
-
645
- // Check reserved names
646
- if($this->is_reserved_field_name( $new_name )){
647
- continue;
648
- }
649
-
650
- //if update field
651
- if( $name && $new_name && $new_name !== $name ){
652
- if ( isset( $fields[$name] ) ) {
653
- $fields[$new_name] = $fields[$name];
654
- } else {
655
- $fields[$new_name] = array();
656
- }
657
-
658
- unset( $fields[$name] );
659
- $name = $new_name;
660
- } else {
661
- $name = $name ? $name : $new_name;
662
- }
663
-
664
- if(!$name){
665
- continue;
666
- }
667
-
668
- //if new field
669
- if ( !isset( $fields[$name] ) ) {
670
- $fields[$name] = array();
671
- }
672
-
673
- $o_type = isset( $o_fields[$name]['type'] ) ? $o_fields[$name]['type'] : 'text';
674
-
675
- //$o_class = isset( $o_fields[$name]['class'] ) ? $o_fields[$name]['class'] : array();
676
- //$classes = array_diff( $o_class, array( 'form-row-first', 'form-row-last', 'form-row-wide' ) );
677
-
678
- $fields[$name]['type'] = empty( $f_types[$i] ) ? $o_type : wc_clean( $f_types[$i] );
679
- $fields[$name]['label'] = empty( $f_labels[$i] ) ? '' : wp_kses_post( trim( stripslashes( $f_labels[$i] ) ) );
680
- $fields[$name]['placeholder'] = empty( $f_placeholder[$i] ) ? '' : wc_clean( stripslashes( $f_placeholder[$i] ) );
681
- $fields[$name]['options'] = empty( $f_options[$i] ) ? array() : array_map( 'wc_clean', explode( '|', trim(stripslashes($f_options[$i])) ) );
682
-
683
- $fields[$name]['class'] = empty( $f_class[$i] ) ? array() : array_map( 'wc_clean', explode( ',', $f_class[$i] ) );
684
- $fields[$name]['label_class'] = empty( $f_label_class[$i] ) ? array() : array_map( 'wc_clean', explode( ',', $f_label_class[$i] ) );
685
-
686
- $fields[$name]['required'] = empty( $f_required[$i] ) ? false : true;
687
- $fields[$name]['clear'] = empty( $f_clear[$i] ) ? false : true;
688
-
689
- $fields[$name]['enabled'] = empty( $f_enabled[$i] ) ? false : true;
690
- $fields[$name]['order'] = isset($f_order[$i]) && is_numeric($f_order[$i]) ? wc_clean( $f_order[$i] ) : '';
691
-
692
- if (!empty( $fields[$name]['options'] )) {
693
- $fields[$name]['options'] = array_combine( $fields[$name]['options'], $fields[$name]['options'] );
694
- }
695
-
696
- if (!in_array( $name, $this->locale_fields ) || apply_filters('thwcfd_allow_address_field_validation_override', false, $name)){
697
- $fields[$name]['validate'] = empty( $f_validation[$i] ) ? array() : explode( ',', $f_validation[$i] );
698
- }
699
-
700
- if (!$this->is_default_field_name( $name )){
701
- $fields[$name]['custom'] = true;
702
- $fields[$name]['show_in_email'] = empty( $f_show_in_email[$i] ) ? false : true;
703
- $fields[$name]['show_in_order'] = empty( $f_show_in_order[$i] ) ? false : true;
704
- } else {
705
- $fields[$name]['custom'] = false;
706
- }
707
-
708
- $fields[$name]['label'] = __($fields[$name]['label'], 'woocommerce');
709
- $fields[$name]['placeholder'] = __($fields[$name]['placeholder'], 'woocommerce');
710
- }
711
-
712
- uasort( $fields, array( $this, 'sort_fields_by_order' ) );
713
- $result = update_option( 'wc_fields_' . $section, $fields );
714
-
715
- if ( $result == true ) {
716
- echo '<div class="updated"><p>' . __( 'Your changes were saved.', 'thwcfd' ) . '</p></div>';
717
- } else {
718
- echo '<div class="error"><p> ' . __( 'Your changes were not saved due to an error (or you made none!).', 'thwcfd' ) . '</p></div>';
719
- }
720
- }
721
-
722
- }
 
1
+ <?php
2
+ if(!defined( 'ABSPATH' )) exit;
3
+
4
+ /**
5
+ * WC_Checkout_Field_Editor class.
6
+ */
7
+ class WC_Checkout_Field_Editor {
8
+
9
+ /**
10
+ * __construct function.
11
+ */
12
+ public function __construct() {
13
+ // Validation rules are controlled by the local fields and can't be changed
14
+ $this->locale_fields = array(
15
+ 'billing_address_1', 'billing_address_2', 'billing_state', 'billing_postcode', 'billing_city',
16
+ 'shipping_address_1', 'shipping_address_2', 'shipping_state', 'shipping_postcode', 'shipping_city',
17
+ 'order_comments'
18
+ );
19
+
20
+ add_action('admin_menu', array($this, 'admin_menu'));
21
+ add_filter('woocommerce_screen_ids', array($this, 'add_screen_id'));
22
+ add_filter('plugin_action_links_'.TH_WCFD_BASE_NAME, array($this, 'add_settings_link'));
23
+ add_action('woocommerce_checkout_update_order_meta', array($this, 'save_data'), 10, 2);
24
+ }
25
+
26
+ /**
27
+ * menu function.
28
+ */
29
+ public function admin_menu() {
30
+ $this->screen_id = add_submenu_page('woocommerce', __('WooCommerce Checkout Form Designer', 'thwcfd'), __('Checkout Form', 'thwcfd'),
31
+ 'manage_woocommerce', 'checkout_form_designer', array($this, 'the_designer'));
32
+
33
+ add_action('admin_print_scripts-'. $this->screen_id, array($this, 'enqueue_admin_scripts'));
34
+ }
35
+
36
+ /**
37
+ * add_screen_id function.
38
+ */
39
+ public function add_screen_id($ids){
40
+ $ids[] = 'woocommerce_page_checkout_form_designer';
41
+ $ids[] = strtolower(__('WooCommerce', 'thwcfd')) .'_page_checkout_form_designer';
42
+
43
+ return $ids;
44
+ }
45
+
46
+ public function add_settings_link($links) {
47
+ $settings_link = '<a href="'.admin_url('admin.php?page=checkout_form_designer').'">'. __('Settings') .'</a>';
48
+ array_unshift($links, $settings_link);
49
+ return $links;
50
+ }
51
+
52
+ /**
53
+ * scripts function.
54
+ */
55
+ public function enqueue_admin_scripts() {
56
+ wp_enqueue_style ('thwcfd-style', plugins_url('/assets/css/thwcfd-style.css', dirname(__FILE__)));
57
+ wp_enqueue_script('thwcfd-admin-script', plugins_url('/assets/js/thwcfd-admin.js', dirname(__FILE__)), array('jquery', 'jquery-ui-dialog', 'jquery-ui-sortable',
58
+ 'woocommerce_admin', 'select2', 'jquery-tiptip'), TH_WCFD_VERSION, true);
59
+ }
60
+
61
+ public function output_premium_version_notice(){
62
+ ?>
63
+ <div id="message" class="wc-connect updated thwcfd-notice">
64
+ <div class="squeezer">
65
+ <table>
66
+ <tr>
67
+ <td width="70%">
68
+ <p><strong><i>WooCommerce Checkout Field Editor Pro</i></strong> premium version provides more features to design your checkout page.</p>
69
+ <ul>
70
+ <li>12 field types available,<br/>(<i>Text, Hidden, Password, Textarea, Radio, Checkbox, Select, Multi-select, Date Picker, Time Picker, Heading, Label</i>).</li>
71
+ <li>Conditionally display fields based on cart items and other field(s) values.</li>
72
+ <li>Add an extra cost to the cart total based on field selection.</li>
73
+ <li>Option to add more sections in addition to the core sections (billing, shipping and additional) in checkout page.</li>
74
+ </ul>
75
+ </td>
76
+ <td>
77
+ <a target="_blank" href="https://www.themehigh.com/product/woocommerce-checkout-field-editor-pro/" class="">
78
+ <img src="<?php echo plugins_url( '../assets/css/upgrade-btn.png', __FILE__ ); ?>" />
79
+ </a>
80
+ </td>
81
+ </tr>
82
+ </table>
83
+ </div>
84
+ </div>
85
+ <?php
86
+ }
87
+
88
+ /**
89
+ * Reset checkout fields.
90
+ */
91
+ public function reset_checkout_fields() {
92
+ delete_option('wc_fields_billing');
93
+ delete_option('wc_fields_shipping');
94
+ delete_option('wc_fields_additional');
95
+ echo '<div class="updated"><p>'. __('SUCCESS: Checkout fields successfully reset', 'thwcfd') .'</p></div>';
96
+ }
97
+
98
+ public function is_reserved_field_name( $field_name ){
99
+ if($field_name && in_array($field_name, array(
100
+ 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state',
101
+ 'billing_country', 'billing_postcode', 'billing_phone', 'billing_email',
102
+ 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_state',
103
+ 'shipping_country', 'shipping_postcode', 'customer_note', 'order_comments'
104
+ ))){
105
+ return true;
106
+ }
107
+ return false;
108
+ }
109
+
110
+ public function is_default_field_name($field_name){
111
+ if($field_name && in_array($field_name, array(
112
+ 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_state',
113
+ 'billing_country', 'billing_postcode', 'billing_phone', 'billing_email',
114
+ 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_state',
115
+ 'shipping_country', 'shipping_postcode', 'customer_note', 'order_comments'
116
+ ))){
117
+ return true;
118
+ }
119
+ return false;
120
+ }
121
+
122
+ /**
123
+ * Save Data function.
124
+ */
125
+ public function save_data($order_id, $posted){
126
+ $types = array('billing', 'shipping', 'additional');
127
+
128
+ foreach($types as $type){
129
+ $fields = $this->get_fields($type);
130
+
131
+ foreach($fields as $name => $field){
132
+ if(isset($field['custom']) && $field['custom'] && isset($posted[$name])){
133
+ $value = wc_clean($posted[$name]);
134
+ if($value){
135
+ update_post_meta($order_id, $name, $value);
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ public static function get_fields($key){
143
+ $fields = array_filter(get_option('wc_fields_'. $key, array()));
144
+
145
+ if(empty($fields) || sizeof($fields) == 0){
146
+ if($key === 'billing' || $key === 'shipping'){
147
+ $fields = WC()->countries->get_address_fields(WC()->countries->get_base_country(), $key . '_');
148
+
149
+ } else if($key === 'additional'){
150
+ $fields = array(
151
+ 'order_comments' => array(
152
+ 'type' => 'textarea',
153
+ 'class' => array('notes'),
154
+ 'label' => __('Order Notes', 'woocommerce'),
155
+ 'placeholder' => _x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')
156
+ )
157
+ );
158
+ }
159
+ }
160
+ return $fields;
161
+ }
162
+
163
+ public function sort_fields_by_order($a, $b){
164
+ if(!isset($a['order']) || $a['order'] == $b['order']){
165
+ return 0;
166
+ }
167
+ return ($a['order'] < $b['order']) ? -1 : 1;
168
+ }
169
+
170
+ public function get_field_types(){
171
+ return array(
172
+ 'text' => 'Text',
173
+ 'select' => 'Select',
174
+ );
175
+ }
176
+
177
+ /*
178
+ * New field form popup
179
+ */
180
+ public function wcfd_new_field_form_pp(){
181
+ $field_types = $this->get_field_types();
182
+ ?>
183
+ <div id="wcfd_new_field_form_pp" title="New Checkout Field" class="wcfd_popup_wrapper">
184
+ <form>
185
+ <table>
186
+ <tr>
187
+ <td colspan="2" class="err_msgs"></td>
188
+ </tr>
189
+ <tr>
190
+ <td width="40%">Type</td>
191
+ <td>
192
+ <select name="ftype" style="width:150px;" onchange="fieldTypeChangeListner(this)">
193
+ <?php foreach($field_types as $value=>$label){ ?>
194
+ <option value="<?php echo trim($value); ?>"><?php echo $label; ?></option>
195
+ <?php } ?>
196
+ </select>
197
+ </td>
198
+ </tr>
199
+ <tr>
200
+ <td>Name</td>
201
+ <td><input type="text" name="fname" style="width:250px;"/></td>
202
+ </tr>
203
+ <tr>
204
+ <td>Label</td>
205
+ <td><input type="text" name="flabel" style="width:250px;"/></td>
206
+ </tr>
207
+ <tr class="rowPlaceholder">
208
+ <td>Placeholder</td>
209
+ <td><input type="text" name="fplaceholder" style="width:250px;"/></td>
210
+ </tr>
211
+ <tr class="rowOptions">
212
+ <td>Options</td>
213
+ <td><input type="text" name="foptions" placeholder="Seperate options with pipe(|)" style="width:250px;"/></td>
214
+ </tr>
215
+ <tr class="rowClass">
216
+ <td>Class</td>
217
+ <td><input type="text" name="fclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
218
+ </tr>
219
+ <!--<tr class="rowLabelClass">
220
+ <td>Label Class</td>
221
+ <td><input type="text" name="flabelclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
222
+ </tr>-->
223
+ <tr class="rowValidate">
224
+ <td>Validation</td>
225
+ <td>
226
+ <select multiple="multiple" name="fvalidate" placeholder="Select validations" class="thwcfd-enhanced-multi-select"
227
+ style="width: 250px; height:30px;">
228
+ <option value="email">Email</option>
229
+ <option value="phone">Phone</option>
230
+ <option value="postcode">Postcode</option>
231
+ <option value="state">State</option>
232
+ </select>
233
+ </td>
234
+ </tr>
235
+ <tr class="rowRequired">
236
+ <td>&nbsp;</td>
237
+ <td>
238
+ <input type="checkbox" name="frequired" value="yes" checked/>
239
+ <label>Required</label><br/>
240
+
241
+ <input type="checkbox" name="fclearRow" value="yes" checked/>
242
+ <label>Clear Row</label><br/>
243
+
244
+ <input type="checkbox" name="fenabled" value="yes" checked/>
245
+ <label>Enabled</label>
246
+ </td>
247
+ </tr>
248
+ <tr class="rowShowInEmail">
249
+ <td>&nbsp;</td>
250
+ <td>
251
+ <input type="checkbox" name="fshowinemail" value="email" checked/>
252
+ <label>Display in Emails</label>
253
+ </td>
254
+ </tr>
255
+ <tr class="rowShowInOrder">
256
+ <td>&nbsp;</td>
257
+ <td>
258
+ <input type="checkbox" name="fshowinorder" value="order-review" checked/>
259
+ <label>Display in Order Detail Pages</label>
260
+ </td>
261
+ </tr>
262
+ </table>
263
+ </form>
264
+ </div>
265
+ <?php
266
+ }
267
+
268
+ /*
269
+ * New field form popup
270
+ */
271
+ public function wcfd_edit_field_form_pp(){
272
+ $field_types = $this->get_field_types();
273
+ ?>
274
+ <div id="wcfd_edit_field_form_pp" title="Edit Checkout Field" class="wcfd_popup_wrapper">
275
+ <form>
276
+ <table>
277
+ <tr>
278
+ <td colspan="2" class="err_msgs"></td>
279
+ </tr>
280
+ <tr>
281
+ <td width="40%">Name</td>
282
+ <td>
283
+ <input type="hidden" name="rowId"/>
284
+ <input type="hidden" name="fname"/>
285
+ <input type="text" name="fnameNew" style="width:250px;"/>
286
+ </td>
287
+ </tr>
288
+ <tr>
289
+ <td>Type</td>
290
+ <td>
291
+ <select name="ftype" style="width:150px;" onchange="fieldTypeChangeListner(this)">
292
+ <?php foreach($field_types as $value=>$label){ ?>
293
+ <option value="<?php echo trim($value); ?>"><?php echo $label; ?></option>
294
+ <?php } ?>
295
+ </select>
296
+ </td>
297
+ </tr>
298
+ <tr>
299
+ <td>Label</td>
300
+ <td><input type="text" name="flabel" style="width:250px;"/></td>
301
+ </tr>
302
+ <tr class="rowPlaceholder">
303
+ <td>Placeholder</td>
304
+ <td><input type="text" name="fplaceholder" style="width:250px;"/></td>
305
+ </tr>
306
+ <tr class="rowOptions">
307
+ <td>Options</td>
308
+ <td><input type="text" name="foptions" placeholder="Seperate options with pipe(|)" style="width:250px;"/></td>
309
+ </tr>
310
+ <tr class="rowClass">
311
+ <td>Class</td>
312
+ <td><input type="text" name="fclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
313
+ </tr>
314
+ <!--<tr class="rowLabelClass">
315
+ <td>Label Class</td>
316
+ <td><input type="text" name="flabelclass" placeholder="Seperate classes with comma" style="width:250px;"/></td>
317
+ </tr>-->
318
+ <tr class="rowValidate">
319
+ <td>Validation</td>
320
+ <td>
321
+ <select multiple="multiple" name="fvalidate" placeholder="Select validations" class="thwcfd-enhanced-multi-select"
322
+ style="width: 250px; height:30px;">
323
+ <option value="email">Email</option>
324
+ <option value="phone">Phone</option>
325
+ <option value="postcode">Postcode</option>
326
+ <option value="state">State</option>
327
+ </select>
328
+ </td>
329
+ </tr>
330
+ <tr class="rowRequired">
331
+ <td>&nbsp;</td>
332
+ <td>
333
+ <input type="checkbox" name="frequired" value="yes" checked/>
334
+ <label>Required</label><br/>
335
+
336
+ <input type="checkbox" name="fclearRow" value="yes" checked/>
337
+ <label>Clear Row</label><br/>
338
+
339
+ <input type="checkbox" name="fenabled" value="yes" checked/>
340
+ <label>Enabled</label>
341
+ </td>
342
+ </tr>
343
+ <tr class="rowShowInEmail">
344
+ <td>&nbsp;</td>
345
+ <td>
346
+ <input type="checkbox" name="fshowinemail" value="email" checked/>
347
+ <label>Display in Emails</label>
348
+ </td>
349
+ </tr>
350
+ <tr class="rowShowInOrder">
351
+ <td>&nbsp;</td>
352
+ <td>
353
+ <input type="checkbox" name="fshowinorder" value="order-review" checked/>
354
+ <label>Display in Order Detail Pages</label>
355
+ </td>
356
+ </tr>
357
+ </table>
358
+ </form>
359
+ </div>
360
+ <?php
361
+ }
362
+
363
+ public function render_tabs_and_sections(){
364
+ $tabs = array( 'fields' => 'Checkout Fields' );
365
+ $tab = isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'fields';
366
+
367
+ $sections = ''; $section = '';
368
+ if($tab === 'fields'){
369
+ $sections = array( 'billing', 'shipping', 'additional' );
370
+ $section = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : 'billing';
371
+ }
372
+
373
+ echo '<h2 class="nav-tab-wrapper woo-nav-tab-wrapper">';
374
+ foreach( $tabs as $key => $value ) {
375
+ $active = ( $key == $tab ) ? 'nav-tab-active' : '';
376
+ echo '<a class="nav-tab '.$active.'" href="'.admin_url('admin.php?page=checkout_form_designer&tab='.$key).'">'.$value.'</a>';
377
+ }
378
+ echo '</h2>';
379
+
380
+ if(!empty($sections)){
381
+ echo '<ul class="thwcfd-sections">';
382
+ $size = sizeof($sections); $i = 0;
383
+ foreach( $sections as $key ) {
384
+ $i++;
385
+ $active = ( $key == $section ) ? 'current' : '';
386
+ $url = 'admin.php?page=checkout_form_designer&tab=fields&section='.$key;
387
+ echo '<li>';
388
+ echo '<a href="'.admin_url($url).'" class="'.$active.'" >'.ucwords($key).' '.__('Fields', 'thwcfd').'</a>';
389
+ echo ($size > $i) ? ' | ' : '';
390
+ echo '</li>';
391
+ }
392
+ echo '</ul>';
393
+ }
394
+
395
+ $this->output_premium_version_notice();
396
+ }
397
+
398
+ public function get_current_tab(){
399
+ return isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'fields';
400
+ }
401
+
402
+ public function get_current_section(){
403
+ $tab = $this->get_current_tab();
404
+ $section = '';
405
+ if($tab === 'fields'){
406
+ $section = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : 'billing';
407
+ }
408
+ return $section;
409
+ }
410
+
411
+ public function render_checkout_fields_heading_row(){
412
+ ?>
413
+ <th class="sort"></th>
414
+ <th class="check-column" style="padding-left:0px !important;"><input type="checkbox" style="margin-left:7px;" onclick="thwcfdSelectAllCheckoutFields(this)"/></th>
415
+ <th class="name">Name</th>
416
+ <th class="id">Type</th>
417
+ <th>Label</th>
418
+ <th>Placeholder</th>
419
+ <th>Validation Rules</th>
420
+ <th class="status">Required</th>
421
+ <th class="status">Clear Row</th>
422
+ <th class="status">Enabled</th>
423
+ <th class="status">Edit</th>
424
+ <?php
425
+ }
426
+
427
+ public function render_actions_row($section){
428
+ ?>
429
+ <th colspan="7">
430
+ <button type="button" class="button button-primary" onclick="openNewFieldForm('<?php echo $section; ?>')"><?php _e( '+ Add field', 'thwcfd' ); ?></button>
431
+ <button type="button" class="button" onclick="removeSelectedFields()"><?php _e( 'Remove', 'thwcfd' ); ?></button>
432
+ <button type="button" class="button" onclick="enableSelectedFields()"><?php _e( 'Enable', 'thwcfd' ); ?></button>
433
+ <button type="button" class="button" onclick="disableSelectedFields()"><?php _e( 'Disable', 'thwcfd' ); ?></button>
434
+ </th>
435
+ <th colspan="4">
436
+ <input type="submit" name="save_fields" class="button-primary" value="<?php _e( 'Save changes', 'thwcfd' ) ?>" style="float:right" />
437
+ <input type="submit" name="reset_fields" class="button" value="<?php _e( 'Reset to default fields', 'thwcfd' ) ?>" style="float:right; margin-right: 5px;"
438
+ onclick="return confirm('Are you sure you want to reset to default fields? all your changes will be deleted.');"/>
439
+ </th>
440
+ <?php
441
+ }
442
+
443
+ public function the_designer() {
444
+ $tab = $this->get_current_tab();
445
+ if($tab === 'fields'){
446
+ $this->checkout_form_field_editor();
447
+ }
448
+ }
449
+
450
+ public function checkout_form_field_editor() {
451
+ $section = $this->get_current_section();
452
+
453
+ echo '<div class="wrap woocommerce"><div class="icon32 icon32-attributes" id="icon-woocommerce"><br /></div>';
454
+ $this->render_tabs_and_sections();
455
+
456
+ if ( isset( $_POST['save_fields'] ) )
457
+ echo $this->save_options( $section );
458
+
459
+ if ( isset( $_POST['reset_fields'] ) )
460
+ echo $this->reset_checkout_fields();
461
+
462
+ global $supress_field_modification;
463
+ $supress_field_modification = false;
464
+ ?>
465
+
466
+ <form method="post" id="wcfd_checkout_fields_form" action="">
467
+ <table id="wcfd_checkout_fields" class="wc_gateways widefat" cellspacing="0">
468
+ <thead>
469
+ <tr><?php $this->render_actions_row($section); ?></tr>
470
+ <tr><?php $this->render_checkout_fields_heading_row(); ?></tr>
471
+ </thead>
472
+ <tfoot>
473
+ <tr><?php $this->render_checkout_fields_heading_row(); ?></tr>
474
+ <tr><?php $this->render_actions_row($section); ?></tr>
475
+ </tfoot>
476
+ <tbody class="ui-sortable">
477
+ <?php
478
+ $i=0;
479
+ foreach( $this->get_fields( $section ) as $name => $options ) :
480
+ if ( isset( $options['custom'] ) && $options['custom'] == 1 ) {
481
+ $options['custom'] = '1';
482
+ } else {
483
+ $options['custom'] = '0';
484
+ }
485
+
486
+ if ( !isset( $options['label'] ) ) {
487
+ $options['label'] = '';
488
+ }
489
+
490
+ if ( !isset( $options['placeholder'] ) ) {
491
+ $options['placeholder'] = '';
492
+ }
493
+
494
+ if( isset( $options['options'] ) && is_array($options['options']) ) {
495
+ $options['options'] = implode("|", $options['options']);
496
+ }else{
497
+ $options['options'] = '';
498
+ }
499
+
500
+ if( isset( $options['class'] ) && is_array($options['class']) ) {
501
+ $options['class'] = implode(",", $options['class']);
502
+ }else{
503
+ $options['class'] = '';
504
+ }
505
+
506
+ if( isset( $options['label_class'] ) && is_array($options['label_class']) ) {
507
+ $options['label_class'] = implode(",", $options['label_class']);
508
+ }else{
509
+ $options['label_class'] = '';
510
+ }
511
+
512
+ if( isset( $options['validate'] ) && is_array($options['validate']) ) {
513
+ $options['validate'] = implode(",", $options['validate']);
514
+ }else{
515
+ $options['validate'] = '';
516
+ }
517
+
518
+ if ( isset( $options['required'] ) && $options['required'] == 1 ) {
519
+ $options['required'] = '1';
520
+ } else {
521
+ $options['required'] = '0';
522
+ }
523
+
524
+ if ( isset( $options['clear'] ) && $options['clear'] == 1 ) {
525
+ $options['clear'] = '1';
526
+ } else {
527
+ $options['clear'] = '0';
528
+ }
529
+
530
+ if ( !isset( $options['enabled'] ) || $options['enabled'] == 1 ) {
531
+ $options['enabled'] = '1';
532
+ } else {
533
+ $options['enabled'] = '0';
534
+ }
535
+
536
+ if ( !isset( $options['type'] ) ) {
537
+ $options['type'] = 'text';
538
+ }
539
+
540
+ if ( isset( $options['show_in_email'] ) && $options['show_in_email'] == 1 ) {
541
+ $options['show_in_email'] = '1';
542
+ } else {
543
+ $options['show_in_email'] = '0';
544
+ }
545
+
546
+ if ( isset( $options['show_in_order'] ) && $options['show_in_order'] == 1 ) {
547
+ $options['show_in_order'] = '1';
548
+ } else {
549
+ $options['show_in_order'] = '0';
550
+ }
551
+ ?>
552
+ <tr class="row_<?php echo $i; echo($options['enabled'] == 1 ? '' : ' thwcfd-disabled') ?>">
553
+ <td width="1%" class="sort ui-sortable-handle">
554
+ <input type="hidden" name="f_custom[<?php echo $i; ?>]" class="f_custom" value="<?php echo $options['custom']; ?>" />
555
+ <input type="hidden" name="f_order[<?php echo $i; ?>]" class="f_order" value="<?php echo $i; ?>" />
556
+
557
+ <input type="hidden" name="f_name[<?php echo $i; ?>]" class="f_name" value="<?php echo esc_attr( $name ); ?>" />
558
+ <input type="hidden" name="f_name_new[<?php echo $i; ?>]" class="f_name_new" value="" />
559
+ <input type="hidden" name="f_type[<?php echo $i; ?>]" class="f_type" value="<?php echo $options['type']; ?>" />
560
+ <input type="hidden" name="f_label[<?php echo $i; ?>]" class="f_label" value="<?php echo $options['label']; ?>" />
561
+ <input type="hidden" name="f_placeholder[<?php echo $i; ?>]" class="f_placeholder" value="<?php echo $options['placeholder']; ?>" />
562
+ <input type="hidden" name="f_options[<?php echo $i; ?>]" class="f_options" value="<?php echo($options['options']) ?>" />
563
+
564
+ <input type="hidden" name="f_class[<?php echo $i; ?>]" class="f_class" value="<?php echo $options['class']; ?>" />
565
+ <input type="hidden" name="f_label_class[<?php echo $i; ?>]" class="f_label_class" value="<?php echo $options['label_class']; ?>" />
566
+
567
+ <input type="hidden" name="f_required[<?php echo $i; ?>]" class="f_required" value="<?php echo($options['required']) ?>" />
568
+ <input type="hidden" name="f_clear[<?php echo $i; ?>]" class="f_clear" value="<?php echo($options['clear']) ?>" />
569
+
570
+ <input type="hidden" name="f_enabled[<?php echo $i; ?>]" class="f_enabled" value="<?php echo($options['enabled']) ?>" />
571
+ <input type="hidden" name="f_validation[<?php echo $i; ?>]" class="f_validation" value="<?php echo($options['validate']) ?>" />
572
+ <input type="hidden" name="f_show_in_email[<?php echo $i; ?>]" class="f_show_in_email" value="<?php echo($options['show_in_email']) ?>" />
573
+ <input type="hidden" name="f_show_in_order[<?php echo $i; ?>]" class="f_show_in_order" value="<?php echo($options['show_in_order']) ?>" />
574
+ <input type="hidden" name="f_deleted[<?php echo $i; ?>]" class="f_deleted" value="0" />
575
+
576
+ <!--$properties = array('type', 'label', 'placeholder', 'class', 'required', 'clear', 'label_class', 'options');-->
577
+ </td>
578
+ <td class="td_select"><input type="checkbox" name="select_field"/></td>
579
+ <td class="td_name"><?php echo esc_attr( $name ); ?></td>
580
+ <td class="td_type"><?php echo $options['type']; ?></td>
581
+ <td class="td_label"><?php echo $options['label']; ?></td>
582
+ <td class="td_placeholder"><?php echo $options['placeholder']; ?></td>
583
+ <td class="td_validate"><?php echo $options['validate']; ?></td>
584
+ <td class="td_required status"><?php echo($options['required'] == 1 ? '<span class="status-enabled tips">Yes</span>' : '-' ) ?></td>
585
+ <td class="td_clear status"><?php echo($options['clear'] == 1 ? '<span class="status-enabled tips">Yes</span>' : '-' ) ?></td>
586
+ <td class="td_enabled status"><?php echo($options['enabled'] == 1 ? '<span class="status-enabled tips">Yes</span>' : '-' ) ?></td>
587
+ <td class="td_edit">
588
+ <button type="button" class="f_edit_btn" <?php echo($options['enabled'] == 1 ? '' : 'disabled') ?>
589
+ onclick="openEditFieldForm(this,<?php echo $i; ?>)"><?php _e( 'Edit', 'thwcfd' ); ?></button>
590
+ </td>
591
+ </tr>
592
+ <?php $i++; endforeach; ?>
593
+ </tbody>
594
+ </table>
595
+ </form>
596
+ <?php
597
+ $this->wcfd_new_field_form_pp();
598
+ $this->wcfd_edit_field_form_pp();
599
+ ?>
600
+ </div>
601
+ <?php
602
+ }
603
+
604
+ public function save_options( $section ) {
605
+ $o_fields = $this->get_fields( $section );
606
+ $fields = $o_fields;
607
+ //$core_fields = array_keys( WC()->countries->get_address_fields( WC()->countries->get_base_country(), $section . '_' ) );
608
+ //$core_fields[] = 'order_comments';
609
+
610
+ $f_order = ! empty( $_POST['f_order'] ) ? $_POST['f_order'] : array();
611
+
612
+ $f_names = ! empty( $_POST['f_name'] ) ? $_POST['f_name'] : array();
613
+ $f_names_new = ! empty( $_POST['f_name_new'] ) ? $_POST['f_name_new'] : array();
614
+ $f_types = ! empty( $_POST['f_type'] ) ? $_POST['f_type'] : array();
615
+ $f_labels = ! empty( $_POST['f_label'] ) ? $_POST['f_label'] : array();
616
+ $f_placeholder = ! empty( $_POST['f_placeholder'] ) ? $_POST['f_placeholder'] : array();
617
+ $f_options = ! empty( $_POST['f_options'] ) ? $_POST['f_options'] : array();
618
+
619
+ $f_class = ! empty( $_POST['f_class'] ) ? $_POST['f_class'] : array();
620
+ $f_label_class = ! empty( $_POST['f_label_class'] ) ? $_POST['f_label_class'] : array();
621
+
622
+ $f_required = ! empty( $_POST['f_required'] ) ? $_POST['f_required'] : array();
623
+ $f_clear = ! empty( $_POST['f_clear'] ) ? $_POST['f_clear'] : array();
624
+ $f_enabled = ! empty( $_POST['f_enabled'] ) ? $_POST['f_enabled'] : array();
625
+
626
+ $f_show_in_email = ! empty( $_POST['f_show_in_email'] ) ? $_POST['f_show_in_email'] : array();
627
+ $f_show_in_order = ! empty( $_POST['f_show_in_order'] ) ? $_POST['f_show_in_order'] : array();
628
+
629
+ $f_validation = ! empty( $_POST['f_validation'] ) ? $_POST['f_validation'] : array();
630
+ $f_deleted = ! empty( $_POST['f_deleted'] ) ? $_POST['f_deleted'] : array();
631
+
632
+ $f_position = ! empty( $_POST['f_position'] ) ? $_POST['f_position'] : array();
633
+ $f_display_options = ! empty( $_POST['f_display_options'] ) ? $_POST['f_display_options'] : array();
634
+ $max = max( array_map( 'absint', array_keys( $f_names ) ) );
635
+
636
+ for ( $i = 0; $i <= $max; $i ++ ) {
637
+ $name = empty( $f_names[$i] ) ? '' : urldecode( sanitize_title( wc_clean( stripslashes( $f_names[$i] ) ) ) );
638
+ $new_name = empty( $f_names_new[$i] ) ? '' : urldecode( sanitize_title( wc_clean( stripslashes( $f_names_new[$i] ) ) ) );
639
+ $allow_override = apply_filters('thwcfd_allow_default_field_override_'.$new_name, false);
640
+
641
+ if(!empty($f_deleted[$i]) && $f_deleted[$i] == 1){
642
+ unset( $fields[$name] );
643
+ continue;
644
+ }
645
+
646
+ // Check reserved names
647
+ if($this->is_reserved_field_name( $new_name ) && !$allow_override){
648
+ continue;
649
+ }
650
+
651
+ //if update field
652
+ if( $name && $new_name && $new_name !== $name ){
653
+ if ( isset( $fields[$name] ) ) {
654
+ $fields[$new_name] = $fields[$name];
655
+ } else {
656
+ $fields[$new_name] = array();
657
+ }
658
+
659
+ unset( $fields[$name] );
660
+ $name = $new_name;
661
+ } else {
662
+ $name = $name ? $name : $new_name;
663
+ }
664
+
665
+ if(!$name){
666
+ continue;
667
+ }
668
+
669
+ //if new field
670
+ if ( !isset( $fields[$name] ) ) {
671
+ $fields[$name] = array();
672
+ }
673
+
674
+ $o_type = isset( $o_fields[$name]['type'] ) ? $o_fields[$name]['type'] : 'text';
675
+
676
+ //$o_class = isset( $o_fields[$name]['class'] ) ? $o_fields[$name]['class'] : array();
677
+ //$classes = array_diff( $o_class, array( 'form-row-first', 'form-row-last', 'form-row-wide' ) );
678
+
679
+ $fields[$name]['type'] = empty( $f_types[$i] ) ? $o_type : wc_clean( $f_types[$i] );
680
+ $fields[$name]['label'] = empty( $f_labels[$i] ) ? '' : wp_kses_post( trim( stripslashes( $f_labels[$i] ) ) );
681
+ $fields[$name]['placeholder'] = empty( $f_placeholder[$i] ) ? '' : wc_clean( stripslashes( $f_placeholder[$i] ) );
682
+ $fields[$name]['options'] = empty( $f_options[$i] ) ? array() : array_map( 'wc_clean', explode( '|', trim(stripslashes($f_options[$i])) ) );
683
+
684
+ $fields[$name]['class'] = empty( $f_class[$i] ) ? array() : array_map( 'wc_clean', explode( ',', $f_class[$i] ) );
685
+ $fields[$name]['label_class'] = empty( $f_label_class[$i] ) ? array() : array_map( 'wc_clean', explode( ',', $f_label_class[$i] ) );
686
+
687
+ $fields[$name]['required'] = empty( $f_required[$i] ) ? false : true;
688
+ $fields[$name]['clear'] = empty( $f_clear[$i] ) ? false : true;
689
+
690
+ $fields[$name]['enabled'] = empty( $f_enabled[$i] ) ? false : true;
691
+ $fields[$name]['order'] = isset($f_order[$i]) && is_numeric($f_order[$i]) ? wc_clean( $f_order[$i] ) : '';
692
+
693
+ if (!empty( $fields[$name]['options'] )) {
694
+ $fields[$name]['options'] = array_combine( $fields[$name]['options'], $fields[$name]['options'] );
695
+ }
696
+
697
+ if (!in_array( $name, $this->locale_fields ) || apply_filters('thwcfd_allow_address_field_validation_override', false, $name)){
698
+ $fields[$name]['validate'] = empty( $f_validation[$i] ) ? array() : explode( ',', $f_validation[$i] );
699
+ }
700
+
701
+ if (!$this->is_default_field_name( $name )){
702
+ $fields[$name]['custom'] = true;
703
+ $fields[$name]['show_in_email'] = empty( $f_show_in_email[$i] ) ? false : true;
704
+ $fields[$name]['show_in_order'] = empty( $f_show_in_order[$i] ) ? false : true;
705
+ } else {
706
+ $fields[$name]['custom'] = false;
707
+ }
708
+
709
+ $fields[$name]['label'] = __($fields[$name]['label'], 'woocommerce');
710
+ $fields[$name]['placeholder'] = __($fields[$name]['placeholder'], 'woocommerce');
711
+ }
712
+
713
+ uasort( $fields, array( $this, 'sort_fields_by_order' ) );
714
+ $result = update_option( 'wc_fields_' . $section, $fields );
715
+
716
+ if ( $result == true ) {
717
+ echo '<div class="updated"><p>' . __( 'Your changes were saved.', 'thwcfd' ) . '</p></div>';
718
+ } else {
719
+ echo '<div class="error"><p> ' . __( 'Your changes were not saved due to an error (or you made none!).', 'thwcfd' ) . '</p></div>';
720
+ }
721
+ }
722
+
723
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://themehigh.com/
4
  Tags: checkout field editor, woocommerce checkout field editor, checkout manager, woocommerce checkout manager, checkout field customizer, checkout form editor, checkout form customizer, checkout, WooCommerce checkout, checkout form designer, checkout
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
- Stable tag: 1.2.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -32,24 +32,30 @@ Check out the premium version of WooCommerce Checkout Field Editor Pro - The bes
32
  <blockquote>
33
  = PREMIUM VERSION FEATURES =
34
  <ul>
35
- <li><strong>12 field types are available:</strong> In Add New Field form and Edit Field form you can choose field type from a list of 12 including 10 input fields and one field for title/heading and one for label.
36
  <p>Available field types:</p>
37
  <ol>
38
  <li><strong>Text</strong> – A basic input text field.</li>
39
  <li><strong>Hidden</strong> – A hidden field.</li>
40
  <li><strong>Password</strong> – An input password text box.</li>
 
 
 
41
  <li><strong>Textarea</strong> – A textarea field.</li>
42
  <li><strong>Radio</strong> – Radio button input (for selecting one of many choices)</li>
43
- <li><strong>Checkbox</strong> – A checkbox field.</li>
 
44
  <li><strong>Select</strong> – A drop-down list (for selecting one of many choices)</li>
45
  <li><strong>Multi-select</strong> – A drop-down list (allows multiple selections from many choices)</li>
46
  <li><strong>Date picker</strong> – Select a date from a popup.</li>
47
  <li><strong>Time picker</strong> – Select a time from a popup.</li>
 
48
  <li><strong>Heading</strong> – Display a heading/ title</li>
49
  <li><strong>Label</strong> – Display a label/ text</li>
50
  </ol>
51
  </li>
52
- <li><strong>Conditional Fields:</strong> Conditionally display fields based on cart items and other field(s) values.</li>
 
53
  <li><strong>Price Fields:</strong> Add an extra cost to the cart total based on field selection.</li>
54
  <li><strong>Add new section:</strong> Add new section(s) in predefined positions in checkout page.
55
  <p>Available positions:</p>
@@ -62,8 +68,12 @@ Check out the premium version of WooCommerce Checkout Field Editor Pro - The bes
62
  <li>After shipping form</li>
63
  <li>Before registration form</li>
64
  <li>After registration form</li>
65
- <li>Before order_notes</li>
66
  <li>After order notes</li>
 
 
 
 
67
  </ol>
68
  </li>
69
  <li><strong>Edit section(s) properties:</strong> Edit custom added section(s) label and display position.</li>
@@ -102,6 +112,16 @@ Yes. There is a button 'reset to default fields' to go back to the WooCommerce d
102
  8. Newly added field
103
 
104
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
105
  = 1.2.5 =
106
  * WooCommerce tested up to version updated.
107
 
4
  Tags: checkout field editor, woocommerce checkout field editor, checkout manager, woocommerce checkout manager, checkout field customizer, checkout form editor, checkout form customizer, checkout, WooCommerce checkout, checkout form designer, checkout
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
+ Stable tag: 1.2.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
32
  <blockquote>
33
  = PREMIUM VERSION FEATURES =
34
  <ul>
35
+ <li><strong>17 field types are available:</strong> In Add New Field form and Edit Field form you can choose field type from a list of 17 including 15 input fields and one field for title/heading and one for label.
36
  <p>Available field types:</p>
37
  <ol>
38
  <li><strong>Text</strong> – A basic input text field.</li>
39
  <li><strong>Hidden</strong> – A hidden field.</li>
40
  <li><strong>Password</strong> – An input password text box.</li>
41
+ <li><strong>Telephone</strong> – An input tel field.</li>
42
+ <li><strong>Email</strong> – An input email field.</li>
43
+ <li><strong>Number</strong> – An input number field.</li>
44
  <li><strong>Textarea</strong> – A textarea field.</li>
45
  <li><strong>Radio</strong> – Radio button input (for selecting one of many choices)</li>
46
+ <li><strong>Checkbox</strong> – A checkbox field.</li>
47
+ <li><strong>Checkbox Group</strong> – A group of checkboxes (allows multiple selections from many choices).</li>
48
  <li><strong>Select</strong> – A drop-down list (for selecting one of many choices)</li>
49
  <li><strong>Multi-select</strong> – A drop-down list (allows multiple selections from many choices)</li>
50
  <li><strong>Date picker</strong> – Select a date from a popup.</li>
51
  <li><strong>Time picker</strong> – Select a time from a popup.</li>
52
+ <li><strong>File Upload</strong> – A file upload field.</li>
53
  <li><strong>Heading</strong> – Display a heading/ title</li>
54
  <li><strong>Label</strong> – Display a label/ text</li>
55
  </ol>
56
  </li>
57
+ <li><strong>Conditional Fields:</strong> Conditionally display fields & sections based on cart items and other field(s) values.</li>
58
+ <li><strong>Custom Validations:</strong> Custom validator feature can be used to define custom validation rules using RegEx.</li>
59
  <li><strong>Price Fields:</strong> Add an extra cost to the cart total based on field selection.</li>
60
  <li><strong>Add new section:</strong> Add new section(s) in predefined positions in checkout page.
61
  <p>Available positions:</p>
68
  <li>After shipping form</li>
69
  <li>Before registration form</li>
70
  <li>After registration form</li>
71
+ <li>Before order notes</li>
72
  <li>After order notes</li>
73
+ <li>Before terms & conditions</li>
74
+ <li>After terms & conditions</li>
75
+ <li>Before submit button</li>
76
+ <li>After submit button</li>
77
  </ol>
78
  </li>
79
  <li><strong>Edit section(s) properties:</strong> Edit custom added section(s) label and display position.</li>
112
  8. Newly added field
113
 
114
  == Changelog ==
115
+ = 1.2.8 =
116
+ * Fix for the issue of displaying 'Optional' text for required fields.
117
+
118
+ = 1.2.7 =
119
+ * WooCommerce tested up to version updated.
120
+
121
+ = 1.2.6 =
122
+ * New filter to allow default field names for new fields.
123
+ * Fix for the issue of not displaying settings popup properly.
124
+
125
  = 1.2.5 =
126
  * WooCommerce tested up to version updated.
127