I want to customize the columns in Woocommerce admin area when viewing the product list.
Specifically, I want to remove some columns, and add several custom field columns.
I tried many solutions listed online, and I can remove columns and add new ones like this:
add_filter( 'manage_edit-product_columns', 'show_product_order',15 );
function show_product_order($columns){
//remove column
unset( $columns['tags'] );
//add column
$columns['offercode'] = __( 'Offer Code');
return $columns;
}
But how do I populate the new column with the actual product data (in this case, a custom field called ‘offercode’)?
The filter
manage_edit-{post_type}_columns
is only used to actually add the column. To control what is displayed in the column for each post (product), you can use themanage_{post_type}_posts_custom_column
action. This action is called for each custom column for every post, and it passes two arguments:$column
and$postid
.Using this action is quite easy, you can find an example to display the custom field “offercode” below:
You could also use a plugin to control this behaviour, such as Admin Columns.
this table view is used by many plugins and wordpress itself. You have to check the column name. $columns[‘tags’] is the tag in WordPress Post View, not in Woocommerce!
Here is a list of some $columns used by Woocommerce:
and that is the correct filter to apply these removals.
In case someone wants to insert in a certain order, here is how to add the column to be right after
Price
:If you additionally want to sort the columns (as shown above, your column will just be attached to the end), you can do something like that in your hook of “manage_edit-product_columns” (example is taken from a class I’ve implemented):