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

Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中将自定义列添加到管理产品列表)
本文介绍了在 WooCommerce 3 中将自定义列添加到管理产品列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

是否可以在 Woocommerce 管理产品列表中添加交货时间"列?

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

我知道在屏幕选项"中有一些额外的列(拇指、价格、product_cat 等)可供选择,但交货时间"不可用.

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?

我尝试按照 LoicTheAztecs 的回答进行操作,但在找到正确的 meta_key slug 时遇到问题.

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

如果我在 wp_postmeta 中搜索delivery",我会得到 0 个结果.

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

但是有些产品指定了交货时间.在我的产品页面上有一个文本字段Lieferzeit: 1–2 Wochen"(表示交货时间:1–2 周).如果我在整个数据库中搜索Wochen",我会在 wp_options 中获得 2 次点击,在 wp_terms 中获得 6 次点击.

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.

数据库一般搜索:

wp_terms 数据库中的点击次数:

Hits in wp_terms DB:

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

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

推荐答案

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

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.

代码如下:

// 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 表中搜索 delivery 术语:

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:

然后你会得到这样的结果(这里只有 1 行带有假 slug):

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

所以现在你应该能够得到正确的 slug 名称(比如这个假的_delivery_date") ...

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

相关答案(针对订单):将自定义列添加到 WooCommerce 后端的管理订单列表

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

这篇关于在 WooCommerce 3 中将自定义列添加到管理产品列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)