4

Is it possible to add a column "delivery time" to the Woocommerce admin product list?

I know there are some additional columns (thumb, price, product_cat etc) to choose at "Screen Options" but "delivery time" is not available.

Is it possible somehow to add it to the list?


EDIT:

I tried to follow LoicTheAztecs answer, but I'm having problems to find the correct meta_key slug.

If i search for "delivery" in wp_postmeta I'm getting 0 results.

But there are products with delivery time assigned. On my product page there's a text field "Lieferzeit: 1–2 Wochen" (means Delivery time: 1–2 weeks). If I search the whole database for "Wochen" I'm getting 2 hits in wp_options und 6 hits in wp_terms.

DB general search:

db search


Hits in wp_terms DB:

hits in wp_terms


Do you know how to find the correct meta_key slug from here?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
tlange
  • 43
  • 1
  • 4

1 Answers1

10

Here is the way to do it with that 2 custom functions hooked. The first one create the column with the title, the second one populate the column with the products data. But you will need to set in that second function, the correct corresponding meta_key to get the data.

Here is that code:

// ADDING A CUSTOM COLUMN TITLE TO ADMIN PRODUCTS LIST
add_filter( 'manage_edit-product_columns', 'custom_product_column',11);
function custom_product_column($columns)
{
   //add columns
   $columns['delivery'] = __( 'Delivery time','woocommerce'); // title
   return $columns;
}

// ADDING THE DATA FOR EACH PRODUCTS BY COLUMN (EXAMPLE)
add_action( 'manage_product_posts_custom_column' , 'custom_product_list_column_content', 10, 2 );
function custom_product_list_column_content( $column, $product_id )
{
    global $post;

    // HERE get the data from your custom field (set the correct meta key below)
    $delivery_time = get_post_meta( $product_id, '_delivery_time', true );

    switch ( $column )
    {
        case 'delivery' :
            echo $delivery_time; // display the data
            break;
    }
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and works.


How to get the correct meta_key slug:

To find the correct meta_key slug corresponding to the "delivery time", you should need to make search in your database using PhpMyAdmin. You will have to search for delivery term in wp_postmeta table this way:

enter image description here

Then you will get this kind of results (here there is just 1 line with a fake slug):

enter image description here

So now you should be able to get the correct slug name (like this fake "_delivery_date" one)


Related answer (for orders): Add custom columns to admin orders list in WooCommerce backend

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thanks for your answer. I noticed your speaking about delivery date, but i mean delivery time. I try to get a column in admin product list which says "1 week" .. "1-2 weeks" etc – tlange Sep 30 '17 at 12:52
  • I guess there's a misunderstanding because I didn't explained it well. I'm not trying to display the delivery time of an order. I'm interested in the delivery time which is assigned to a product, like it's article number or price. [Example here](http://tillmannlange.de/tmp/product.jpg) And I'm trying to have an additional checkbox "delivery time" [here](http://tillmannlange.de/tmp/backend.jpg) I'm refering to [this site](https://www.design-deli.net/produkt/mesh/). Is this even possible? – tlange Oct 02 '17 at 10:19
  • @tiange No misunderstanding as we are here working **on product level** and not in order level. The code provided is maid to display a product custom field in the admin product list (which works). Now **Nobody can't find for you this custom field key**, as this is your minimal job and it's related to your settings and own customizations. In your question update you don't provide any information related on how your are setting the **"terms"** in your product … So it can be a term for a tag, a category or an attribute. I am not a soothsayer. – LoicTheAztec Oct 02 '17 at 18:18
  • `global $post` seems unnecessary, as the function works without it. Wordpress [docs](https://make.wordpress.org/docs/plugin-developer-handbook/10-plugin-components/custom-list-table-columns/#output-table-cell-contents) also don't reference it. – Matts Aug 12 '19 at 04:57