Skip to content

Instantly share code, notes, and snippets.

@web-hat
Last active September 21, 2019 21:56
Show Gist options
  • Save web-hat/47f274c7334bba29f45cb8dd57bbaa71 to your computer and use it in GitHub Desktop.
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.
<?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