forked from mattiasghodsian/wooCMFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
110 lines (102 loc) · 3.93 KB
/
example.php
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
<?php
/**
* Plugin Name: wooCustomMetaFields Example
* Plugin URI: https://github.com/mattiasghodsian/wooCustomMetaFields
* Description: This class Simplifys adding fields to woocommer product data meta
* Version: 0.1.0
* Author: Mattias Ghodsian
* Author URI: https://github.com/mattiasghodsian/
*/
include_once 'custom_wooCommerce_field.php';
add_action( 'plugins_loaded', 'wooCMFS' );
function wooCMFS() {
// Woo_Custom_Meta_Fields class
$cf = New Woo_Custom_Meta_Fields();
// add fields
$array = [
[
'type' => 'text', # text, textarea, select, radio
'attr' => [ # any woocommerce attribute
'id' => '_demo_text',
'placeholder' => 'Lorem ipsum dolor sit amet',
'label' => __('Demo Text', 'woocommerce'),
'type' => 'text',
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_text_input.html
],
[
'type' => 'text', # text, textarea, select, radio
'attr' => [ # any woocommerce attribute
'id' => '_demo_number',
'placeholder' => '1337',
'label' => __('Demo Number', 'woocommerce'),
'type' => 'number',
'custom_attributes' => [
'step' => 'any',
'min' => '0'
]
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_text_input.html
],
[
'type' => 'textarea', # text, textarea
'attr' => [ # any woocommerce attribute
'id' => '_demo_description',
'placeholder' => 'Lorem ipsum dolor sit amet',
'label' => __('Demo Description', 'woocommerce'),
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_textarea_input.html
],
[
'type' => 'select', # text, textarea, select, radio
'attr' => [ # any woocommerce attribute
'id' => '_demo_select',
'label' => __('Demo Select', 'woocommerce'),
'options' => [
'1' => 'Demo option 1',
'2' => 'Demo option 2',
'3' => 'Demo option 3',
]
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_select.html
],
[
'type' => 'radio', # text, textarea, select, radio
'attr' => [ # any woocommerce attribute
'id' => '_demo_radio',
'label' => __('Demo Radio', 'woocommerce'),
'options' => [
'0' => __('Demo option 1'),
'1' => __('Demo option 2'),
]
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_radio.html
],
[
'type' => 'checkbox', # text, textarea, select, radio, checkbox
'attr' => [ # any woocommerce attribute
'id' => '_demo_checkbox',
'label' => __('Demo checkbox', 'woocommerce' ),
'description' => __( 'Check me!', 'woocommerce' ),
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_checkbox.html
],
[
'type' => 'hidden', # text, textarea, select, radio, checkbox
'attr' => [ # any woocommerce attribute
'id' => '_demo_hidden',
]
# https://docs.woocommerce.com/wc-apidocs/function-woocommerce_wp_hidden_input.html
]
];
$cf->addFields($array);
// execute
$cf->init([
'tab' => 'woocommerce_product_options_general_product_data'
]);
/**
* tested tabs
* woocommerce_product_options_general_product_data
* woocommerce_product_options_inventory_product_data
*/
}