Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add / remove columns in Woocommerce admin product list

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')?

like image 220
lilbiscuit Avatar asked May 25 '14 17:05

lilbiscuit


People also ask

How do I change the number of columns in WooCommerce?

1 Answer. Show activity on this post. Install and activate this plug. Then go Woocommerce -> Products, scroll down to the Product Columns heading and change the amount to 3.

How do I add a column to my WordPress admin?

For instance, you can click the 'Edit' button for any column and then change its type, label, and width. In addition to the default columns, you can add more admin columns by clicking the '+ Add Column' button. For example, we added the featured image admin column for the posts screen.

How do I add a column in WooCommerce orders page?

WooCommerce Orders List Column, Step 1: Add a Header. Adding a new column is straight-forward using the manage_edit-{$post_type}_columns filter from WordPress core. This will let us change the columns shown in the list table for orders so we can inject our own.

How to add custom columns to WooCommerce admin orders list?

PHP Snippet: Add custom column to WooCommerce admin orders list. In order to add a new column in the orders table, we’ll use the manage_edit-shop_order_columns filter. In your child theme’s functions.php file add the following code:

How do I change the stock level in WooCommerce?

There are various settings in WooCommerce which control how the stock level is displayed (see WooCommerce > Settings > Products > Inventory ), and this column will change based on these settings. The weight and dimensions columns will display the relevant data as entered for each product under the Shipping tab.

How to filter products by featured products in WooCommerce?

By default Woocommerce admin doesn’t have an option to filter products by featured products. If you would like to have this feature then use this snippet here below.

What is the stock column in WooCommerce?

The stock column will either contain the basic stock status (e.g. 'In Stock' or 'Out of Stock') or the exact stock level. This is controlled in the main WooCommerce stock settings - WooCommerce > Settings > Products > Inventory.


3 Answers

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 the manage_{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:

add_action( 'manage_product_posts_custom_column', 'wpso23858236_product_column_offercode', 10, 2 );  function wpso23858236_product_column_offercode( $column, $postid ) {     if ( $column == 'offercode' ) {         echo get_post_meta( $postid, 'offercode', true );     } } 

You could also use a plugin to control this behaviour, such as Admin Columns.

like image 191
engelen Avatar answered Sep 25 '22 17:09

engelen


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:

$columns['cb']   $columns['thumb'] $columns['name']  $columns['sku']  $columns['is_in_stock'] $columns['price'] $columns['product_cat']  $columns['product_tag'] $columns['featured'] $columns['product_type'] $columns['date'] 

and that is the correct filter to apply these removals.

add_filter( 'manage_edit-product_columns', 'change_columns_filter',10, 1 ); function change_columns_filter( $columns ) { unset($columns['product_tag']); unset($columns['sku']); unset($columns['featured']); unset($columns['product_type']); return $columns; } 
like image 26
nh-labs Avatar answered Sep 25 '22 17:09

nh-labs


In case someone wants to insert in a certain order, here is how to add the column to be right after Price:

add_filter( 'manage_edit-product_columns', 'wootix_show_product_order', 15 ) ;

function wootix_show_product_order( $columns )
{
    //add column
    $arr = array( 'wootix_credit' => __( 'Credits', 'wootix' ) ) ;

    array_splice( $columns, 6, 0, $arr ) ;

    return $columns ;
}
like image 32
harrrrrrry Avatar answered Sep 24 '22 17:09

harrrrrrry