donglu8779
2017-08-15 13:26
浏览 53
已采纳

在WooCommerce 3中将自定义列添加到管理产品列表

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?

图片转代码服务由CSDN问答提供 功能建议

是否可以在Woocommerce管理产品列表中添加“交付时间”列?

我知道在“屏幕选项”中有一些额外的列(thumb,price,product_cat等)可供选择,但“交付时间”不可用。

是否有可能以某种方式将其添加到列表中?


编辑: < / p>

我试图按照LoicTheAztecs的回答,但是我遇到了找到正确的meta_key slug的问题。

如果我在wp_postmeta中搜索“delivery” 我得到0结果。

但是有些产品的分配时间。 在我的产品页面上有一个文本字段“Lieferzeit:1-2 Wochen”(表示交货时间:1 -2周)。 如果我在整个数据库中搜索“Wochen”,我在wp_options中获得2次点击,在wp_terms中获得6次点击。

数据库一般搜索:


点击 wp_terms DB:

< img src =“https://i.stack.imgur.com/zLVGo.png”alt =“点击wp_terms”>


你知道吗? 如何从这里找到正确的meta_key slug?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudan1123 2017-08-15 14:54
    已采纳

    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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题