Last active
September 21, 2019 21:56
-
-
Save web-hat/47f274c7334bba29f45cb8dd57bbaa71 to your computer and use it in GitHub Desktop.
Populating custom fields value in product categories admin screen or in categories listing table.
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 | |
//Displaying Additional Columns | |
add_filter( 'manage_edit-product_cat_columns', 'wh_customFieldsListTitle' ); //Register Function | |
add_action( 'manage_product_cat_custom_column', 'wh_customFieldsListDisplay' , 10, 3); //Populating the Columns | |
/** | |
* Meta Title and Description column added to category admin screen. | |
* | |
* @param mixed $columns | |
* @return array | |
*/ | |
function wh_customFieldsListTitle( $columns ) { | |
$columns['pro_meta_title'] = __( 'Meta Title', 'woocommerce' ); | |
$columns['pro_meta_desc'] = __( 'Meta Description', 'woocommerce' ); | |
return $columns; | |
} | |
/** | |
* Meta Title and Description column value added to product category admin screen. | |
* | |
* @param string $columns | |
* @param string $column | |
* @param int $id term ID | |
* | |
* @return string | |
*/ | |
function wh_customFieldsListDisplay( $columns, $column, $id ) { | |
if ( 'pro_meta_title' == $column ) { | |
$columns = esc_html( get_term_meta($id, 'wh_meta_title', true) ); | |
} | |
elseif ( 'pro_meta_desc' == $column ) { | |
$columns = esc_html( get_term_meta($id, 'wh_meta_desc', true) ); | |
} | |
return $columns; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related article: http://www.webhat.in/article/woocommerce-tutorial/adding-custom-fields-to-woocommerce-product-category/