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

发布于 2025-01-22 11:45:47 字数 937 浏览 0 评论 0 原文

是否可以在WooCommerce Admin产品列表中添加“交付时间”列?

我知道在“屏幕选项”上选择还有一些其他列(拇指,价格,product_cat等),但是“交货时间”不可用。

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


编辑:

我试图遵循loictheaztecs的答案,但是我有问题可以找到正确的meta_key slug。

如果我在wp_postmeta中搜索“交货”,则将获得0个结果。

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

db一般搜索:

”


wp_terms db:

“


从这里正确正确的meta_key slug?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2025-01-29 11:45:47

这是使用2个自定义函数挂钩的方法。第一个用标题创建列,第二个用产品数据填充了列。但是,您需要在第二个功能中设置正确的 meta_key 以获取数据。

这是该代码:

// 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;
    }
}

代码在您的活动子主题(或主题)的function.php文件中或任何插件文件中。

测试并有效。


如何获得正确的meta_key slug:

找到正确的 meta_key slug对应于对应的“交付时间” ,您应该需要在您的数据库使用phpmyadmin。您将不得不搜索 交付 wp_postmeta 表:

/I.SSTATIC.NET/GAN0N.PNG“ RER = 您将获得这种结果(这里只有1行带有假sl)

”在此处输入图像说明”

所以现在您应该能够获得正确的slug name ( like this fake "_delivery_date" one)


Related answer (for orders):

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文