Repository navigation
Expand file tree
/
Copy pathcategory_extra_fields.php
More file actions
48 lines (40 loc) · 1.73 KB
/
Copy pathcategory_extra_fields.php
File metadata and controls
48 lines (40 loc) · 1.73 KB
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
<?php
//Product Cat Create page
function wh_taxonomy_add_new_meta_field() {
?>
<div class="form-field">
<label for="wh_meta_code"><?php _e('Code', 'wh'); ?></label>
<input type="text" name="wh_meta_code" id="wh_meta_code">
<p class="description"><?php _e('Enter a code, <= 100 character', 'wh'); ?></p>
</div>
<?php
}
//Product Cat Edit page
function wh_taxonomy_edit_meta_field($term) {
//getting term ID
$term_id = $term->term_id;
// retrieve the existing value(s) for this meta field.
$wh_meta_code = get_term_meta($term_id, 'wh_meta_code', true);
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="wh_meta_code"><?php _e('Meta code', 'wh'); ?></label></th>
<td>
<input type="text" name="wh_meta_code" id="wh_meta_code" value="<?php echo esc_attr($wh_meta_code) ? esc_attr($wh_meta_code) : ''; ?>">
<p class="description"><?php _e('Enter a code, <= 100 character', 'wh'); ?></p>
</td>
</tr>
<?php
}
add_action('product_cat_add_form_fields', 'wh_taxonomy_add_new_meta_field', 10, 1);
add_action('product_cat_edit_form_fields', 'wh_taxonomy_edit_meta_field', 10, 1);
// Save extra taxonomy fields callback function.
function wh_save_taxonomy_custom_meta($term_id) {
$wh_meta_code = filter_input(INPUT_POST, 'wh_meta_code');
update_term_meta($term_id, 'wh_meta_code', $wh_meta_code);
}
add_action('edited_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
add_action('create_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
// USAGE, to retrive data:
//
// echo $productCatMetacode = get_term_meta($term_id, 'wh_meta_code', true);
// echo $productCatMetaDesc = get_term_meta($term_id, 'wh_meta_desc', true);