1 <?php
2 3 4 5 6 7 8 9
10
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 14 15 16 17 18 19
20 function woocommerce_wp_text_input( $field ) {
21 global $thepostid, $post, $woocommerce;
22
23 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
24 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
25 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
26 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
27 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
28 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
29 $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
30 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
31
32 switch ( $data_type ) {
33 case 'price' :
34 $field['class'] .= ' wc_input_price';
35 $field['value'] = wc_format_localized_price( $field['value'] );
36 break;
37 case 'decimal' :
38 $field['class'] .= ' wc_input_decimal';
39 $field['value'] = wc_format_localized_decimal( $field['value'] );
40 break;
41 }
42
43
44 $custom_attributes = array();
45
46 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
47 foreach ( $field['custom_attributes'] as $attribute => $value )
48 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
49
50 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
51
52 if ( ! empty( $field['description'] ) ) {
53
54 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
55 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
56 } else {
57 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
58 }
59
60 }
61 echo '</p>';
62 }
63
64 65 66 67 68 69 70
71 function woocommerce_wp_hidden_input( $field ) {
72 global $thepostid, $post;
73
74 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
75 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
76 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
77
78 echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
79 }
80
81 82 83 84 85 86 87
88 function woocommerce_wp_textarea_input( $field ) {
89 global $thepostid, $post, $woocommerce;
90
91 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
92 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
93 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
94 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
95 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
96
97 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><textarea class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="2" cols="20">' . esc_textarea( $field['value'] ) . '</textarea> ';
98
99 if ( ! empty( $field['description'] ) ) {
100
101 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
102 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
103 } else {
104 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
105 }
106
107 }
108 echo '</p>';
109 }
110
111 112 113 114 115 116 117
118 function woocommerce_wp_checkbox( $field ) {
119 global $thepostid, $post;
120
121 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
122 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
123 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
124 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
125 $field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
126 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
127
128 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' /> ';
129
130 if ( ! empty( $field['description'] ) ) echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
131
132 echo '</p>';
133 }
134
135 136 137 138 139 140 141
142 function woocommerce_wp_select( $field ) {
143 global $thepostid, $post, $woocommerce;
144
145 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
146 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
147 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
148 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
149
150 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
151
152 foreach ( $field['options'] as $key => $value ) {
153
154 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
155
156 }
157
158 echo '</select> ';
159
160 if ( ! empty( $field['description'] ) ) {
161
162 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
163 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
164 } else {
165 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
166 }
167
168 }
169 echo '</p>';
170 }
171
172 173 174 175 176 177 178
179 function woocommerce_wp_radio( $field ) {
180 global $thepostid, $post, $woocommerce;
181
182 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
183 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
184 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
185 $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
186 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
187
188 echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="wc-radios">';
189
190 foreach ( $field['options'] as $key => $value ) {
191
192 echo '<li><label><input
193 name="' . esc_attr( $field['name'] ) . '"
194 value="' . esc_attr( $key ) . '"
195 type="radio"
196 class="' . esc_attr( $field['class'] ) . '"
197 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
198 /> ' . esc_html( $value ) . '</label>
199 </li>';
200 }
201 echo '</ul>';
202
203 if ( ! empty( $field['description'] ) ) {
204
205 if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
206 echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
207 } else {
208 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
209 }
210
211 }
212
213 echo '</fieldset>';
214 }