Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
Created October 19, 2015 17:11
Show Gist options
  • Save jgarciaruiz/60de84f280509338be17 to your computer and use it in GitHub Desktop.
Save jgarciaruiz/60de84f280509338be17 to your computer and use it in GitHub Desktop.
Add custom field column to WC products admin table
/* WC HPD */
//manage_product_posts_custom_column
add_filter( 'manage_edit-product_columns', 'products_customcol_fn' );
function products_customcol_fn($columns){
$new_columns = (is_array($columns)) ? $columns : array();
$new_columns['HPD'] = 'hpd';
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'products_customcol_value_fn', 2 );
function products_customcol_value_fn($column){
global $post;
$hpdname = get_post_meta( $post->ID, 'hpd_name', true );
if ( $column == 'HPD' ) {
if ( isset($hpdname) ){
echo $hpdname;
}else{
echo "-";
}
}
}
add_filter( "manage_edit-product_sortable_columns", 'products_customcol_sort_fn' );
function products_customcol_sort_fn( $columns ) {
$custom = array(
'HPD' => 'hpdname'
);
return wp_parse_args( $custom, $columns );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment