在Woocommerce 3+中的“我的帐户订单"表中添加自定义列 [英] Add a custom column to My Account Orders table in Woocommerce 3+

查看:101
本文介绍了在Woocommerce 3+中的“我的帐户订单"表中添加自定义列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Woocommerce 3.5.x在用户帐户(我的帐户)区域有一个特殊页面,其中显示用户的先前订单.

Woocommerce 3.5.x has a special page at the user account (My Account) area where it displays the user's previous Orders.

此页面现在默认显示为5列.

This page is now 5 column displays as default.

以下是带有5列的woocommerce Orders区域的屏幕截图:

Here the screenshot of the woocommerce Orders area with 5 column:

我的订单

我找不到更改此方法的方法.

I Can't find the way to change this.

如何在默认值中添加新列?

How can I add a new column in the default?

推荐答案

这需要2个函数,这些函数将添加一个新列

This requires 2 functions that will add a new column

第二个函数挂钩是一个复合挂钩:woocommerce_my_account_my_orders_column_{$column_id}其中,{$column_id}需要替换为第一个函数中设置的列键子段.

The second function hook is a composite hook: woocommerce_my_account_my_orders_column_{$column_id} where {$column_id} need to be replaced by the column key slug that is set in the first function.

第二个功能管理显示的行值,您可以添加例如自定义字段以获取自定义订单元数据值.

That second function manage the displayed row values and you can add for example a custom field to get custom order meta data values.

代码:

add_filter( 'woocommerce_account_orders_columns', 'add_account_orders_column', 10, 1 );
function add_account_orders_column( $columns ){
    $columns['custom-column'] = __( 'New Column', 'woocommerce' );

    return $columns;
}

add_action( 'woocommerce_my_account_my_orders_column_custom-column', 'add_account_orders_column_rows' );
function add_account_orders_column_rows( $order ) {
    // Example with a custom field
    if ( $value = $order->get_meta( '_custom_field' ) ) {
        echo esc_html( $value );
    }
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

您已完成并将其自定义列添加到我的帐户订单"表中:

You are done and have added a custom column to My account orders table:

如果要在表html输出中进行更改,则必须覆盖模板文件:myaccount/orders.php

这篇关于在Woocommerce 3+中的“我的帐户订单"表中添加自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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