修改 woocommerce orders.php 列 [英] Modify woocommerce orders.php columns

查看:17
本文介绍了修改 woocommerce orders.php 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改 Woocommerce orders.php 表中的列.我想去掉 TOTAL 列和 DATE 列,然后添加一个新列,其中包含一些特定于我的商店的自定义信息.

I am trying to modify the columns in the Woocommerce orders.php table. I would like to get rid of the TOTAL column as well as the DATE column and then I would like to add a new column with some custom information that’s specific to my store.

以下函数曾经可以工作,但自 Woocommerce 2.6 以来已被弃用.所以问题是,有没有人知道如何在 2.6 之后删除/添加列到这个表中?

The following function used to work but has been deprecated since Woocommerce 2.6. So the question is, does anybody know how to delete/add columns to this table after 2.6?

function wc_get_account_orders_columns() {
  $columns = apply_filters( 'woocommerce_account_orders_columns', array(
    'order-number'  => __( 'Order', 'woocommerce' ),
    'order-date'    => __( 'Date', 'woocommerce' ),
    'order-status'  => __( 'Status', 'woocommerce' ),
    'order-total'   => __( 'Total', 'woocommerce' ),
    'order-actions' => ' ',
  ) );

  // Deprecated filter since 2.6.0.
  return apply_filters( 'woocommerce_my_account_my_orders_columns', $columns );
}

推荐答案

在其他答案中没有提到如何使用自定义信息填充列.所以,完整的算法如下:

In the other answers it is not mentioned how to populate a column with custom information. So, the complete algorithm is below:

add_filter( 'manage_edit-shop_order_columns','your_function_name');
function your_function_name($columns)
{
    // to remove just use unset
    unset($columns['order_total']); // remove Total column
    unset($columns['order_date']); // remove Date column

    // now it is time to add a custom one
    $columns['custom_column'] = "Column title";

    return $columns;    
}

步骤 2. 填充数据

add_action( 'manage_shop_order_posts_custom_column' , 'your_function_name2' );
function your_function_name2( $column ) {
    global $the_order; // you can use the global WP_Order object here
    // global $post; // is also available here

    if( $column == 'custom_column' ) {

        // do stuff, ex: get_post_meta( $post->ID, 'key', true );

    }

}

您还可以查看本教程以获取更多示例.

You can also check this tutorial for more examples.

这篇关于修改 woocommerce orders.php 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆