Last active
March 27, 2017 18:10
-
-
Save web-hat/171b82a617bed1b112a2b546a1876fa2 to your computer and use it in GitHub Desktop.
WooCommerce Product Category custom field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
//Product Cat Create page | |
function wh_taxonomy_add_new_meta_field() { | |
?> | |
<div class="form-field"> | |
<label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label> | |
<input type="text" name="wh_meta_title" id="wh_meta_title"> | |
<p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p> | |
</div> | |
<div class="form-field"> | |
<label for="wh_meta_desc"><?php _e('Meta Description', 'wh'); ?></label> | |
<textarea name="wh_meta_desc" id="wh_meta_desc"></textarea> | |
<p class="description"><?php _e('Enter a meta description, <= 160 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_title = get_term_meta($term_id, 'wh_meta_title', true); | |
$wh_meta_desc = get_term_meta($term_id, 'wh_meta_desc', true); | |
?> | |
<tr class="form-field"> | |
<th scope="row" valign="top"><label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label></th> | |
<td> | |
<input type="text" name="wh_meta_title" id="wh_meta_title" value="<?php echo esc_attr($wh_meta_title) ? esc_attr($wh_meta_title) : ''; ?>"> | |
<p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p> | |
</td> | |
</tr> | |
<tr class="form-field"> | |
<th scope="row" valign="top"><label for="wh_meta_desc"><?php _e('Meta Description', 'wh'); ?></label></th> | |
<td> | |
<textarea name="wh_meta_desc" id="wh_meta_desc"><?php echo esc_attr($wh_meta_desc) ? esc_attr($wh_meta_desc) : ''; ?></textarea> | |
<p class="description"><?php _e('Enter a meta description', 'wh'); ?></p> | |
</td> | |
</tr> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment