-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathreadme.txt
319 lines (249 loc) · 8.63 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
=== WooCommerce Custom Product Data Fields ===
Contributors: kharisblank
Tags: ecommerce, e-commerce, commerce, woocommerce, extension, product, tab, framework
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ACYNA5XNUGBUL
Requires at least: 3.1
Tested up to: 3.9.1
Stable tag: 1.1
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
WooCommerce extension which will help you to build extra product data fields easily.
== Description ==
WooCommerce Custom Product Data Fields is a simple framework which will help you to build extra product data fields easily, e.g. secondary product title, vendor info, custom message for individual product, etc.
You can use this plugin as a library of your ‘brand-new’ WooCommerce Extension.
= Available Fields =
* text
* number
* textarea
* checkbox
* select
* radio
* hidden
* multiselect
* image
* gallery
* colorpicker
* datepicker
* devider
= Defining Your Fields =
<code>
/**
* WooCommerce product data tab definition
*
* @return array
*/
add_action('wc_cpdf_init', 'prefix_custom_product_data_tab_init', 10, 0);
if(!function_exists('prefix_custom_product_data_tab_init')) :
function prefix_custom_product_data_tab_init(){
$custom_product_data_fields = array();
/** First product data tab starts **/
/** ===================================== */
$custom_product_data_fields['custom_data_1'] = array(
array(
'tab_name' => __('Custom Data', 'wc_cpdf'),
),
array(
'id' => '_mytext',
'type' => 'text',
'label' => __('Text', 'wc_cpdf'),
'placeholder' => __('A placeholder text goes here.', 'wc_cpdf'),
'class' => 'large',
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_mynumber',
'type' => 'number',
'label' => __('Number', 'wc_cpdf'),
'placeholder' => __('Number.', 'wc_cpdf'),
'class' => 'short',
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_mytextarea',
'type' => 'textarea',
'label' => __('Textarea', 'wc_cpdf'),
'placeholder' => __('A placeholder text goes here.', 'wc_cpdf'),
'style' => 'width:70%;height:140px;',
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_mycheckbox',
'type' => 'checkbox',
'label' => __('Checkbox', 'wc_cpdf'),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_myselect',
'type' => 'select',
'label' => __('Select', 'wc_cpdf'),
'options' => array(
'option_1' => 'Option 1',
'option_2' => 'Option 2',
'option_3' => 'Option 3'
),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_myradio',
'type' => 'radio',
'label' => __('Radio', 'wc_cpdf'),
'options' => array(
'radio_1' => 'Radio 1',
'radio_2' => 'Radio 2',
'radio_3' => 'Radio 3'
),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_myhidden',
'type' => 'hidden',
'value' => 'Hidden Value',
),
array(
'id' => '_mymultiselect',
'type' => 'multiselect',
'label' => __('Multiselect', 'wc_cpdf'),
'placeholder' => __('Multiselect maan!', 'wc_cpdf'),
'options' => array(
'option_1' => 'Option 1',
'option_2' => 'Option 2',
'option_3' => 'Option 3',
'option_4' => 'Option 4',
'option_5' => 'Option 5'
),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
'class' => 'medium'
),
// image
array(
'id' => '_myimage',
'type' => 'image',
'label' => __('Image 1', 'wc_cpdf'),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'id' => '_mygallery',
'type' => 'gallery',
'label' => __('Gallery', 'wc_cpdf'),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
// Color
array(
'id' => '_mycolor',
'type' => 'color',
'label' => __('Select color', 'wc_cpdf'),
'placeholder' => __('A placeholder text goes here.', 'wc_cpdf'),
'class' => 'large',
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
// Datepicker
array(
'id' => '_mydatepicker',
'type' => 'datepicker',
'label' => __('Select date', 'wc_cpdf'),
'placeholder' => __('A placeholder text goes here.', 'wc_cpdf'),
'class' => 'large',
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
),
array(
'type' => 'divider'
)
);
/** First product data tab ends **/
/** ===================================== */
/** Second product data tab starts **/
/** ===================================== */
$custom_product_data_fields['custom_data_2'] = array(
array(
'tab_name' => __('Custom Data 2', 'wc_cpdf'),
),
array(
'id' => '_mytext_2',
'type' => 'text',
'label' => __('Text ABCD', 'wc_cpdf'),
'placeholder' => __('A placeholder text goes here.', 'wc_cpdf'),
'class' => 'large',
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
)
);
return $custom_product_data_fields;
}
endif;
</code>
= Getting The Field Value =
<code>
/**
*
* $wc_cpdf->get_value($post_id, $field_id);
* $post_id = (integer) post ID
* $field_id = (string) unique field ID
*
*/
global $wc_cpdf;
echo $wc_cpdf->get_value(get_the_ID(), '_mytext');
</code>
Retrieving multiselect value
<pre>
global $wc_cpdf;
$multiselect = $wc_cpdf->get_value($post->ID, '_mymultiselect');
foreach ($multiselect as $value) {
echo $value;
}
</pre>
Retrieving image value
<pre>
global $wc_cpdf;
$image_id = $wc_cpdf->get_value($post->ID, '_myimage');
$size = 'thumbnail';
$image_attachment = wp_get_attachment_image($image_id, $size);
echo $image_attachment;
</pre>
Retrieving gallery value
<pre>
global $wc_cpdf;
$gallery = $wc_cpdf->get_value($post->ID, '_mygallery');
foreach ($gallery as $image_id) {
$image_id = $wc_cpdf->get_value($post->ID, '_mygallery');
$size = 'thumbnail';
$image_attachment = wp_get_attachment_image($image_id, $size);
echo $image_attachment;
}
</pre>
This project is also available on [Github](https://github.com/kharissulistiyo/WooCommerce-Custom-Product-Data-Fields).
= More info =
Send me your question to my contacts below:
Mail: [kharisulistiyo(at)gmail(dot)com](mailto:kharisulistiyo@gmail.com)
Twitter: [@kharissulistiyo](http://twitter.com/kharissulistiyo)
P.S: Don't be worry, I always reply. :)
== Installation ==
1. Upload this plugin to the /wp-content/plugins/ directory.
2. Activate the plugin through the Plugins menu in WordPress.
3. Define your custom product data fields in your theme `functions.php` file. See `fields-init.php` inside this plugin folder.
== Screenshots ==
1. WooCommerce Custom Product Data Fields
== Changelog ==
= 1.0.2 =
* Fix some bugs
* Add multiselect field
* Add image field
* Add image field
* Add gallery field
* Add colorpicker field
* Add datepicker field
* Add devider
* Allow multiple data tabs definition
* Update fields definition function (via hook)
= 1.0 =
* Initial release