我正在使用最新的 Woocommerce 版本 2.4.12。我想对 woocommerce --> 订单下管理仪表板中的订单页面进行一些更改。
它在 plugins->woocommerce 文件夹中的文件在哪里?我在我的主题中创建了一个 woocommerce 文件夹来覆盖模板文件。我想将客户的电话号码添加到 ship_to 列。客户希望在订单页面上显示客户的电话号码。有什么方法可以使用 functions.php 添加钩子(Hook)并进行更改?
最佳答案
试试这个到你的functions.php
add_filter( 'manage_edit-shop_order_columns', 'shop_order_columns' );
function shop_order_columns( $columns ){
$new_columns = (is_array($columns)) ? $columns : array();
$new_columns['phone'] = 'Phone';
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'shop_order_posts_custom_column' );
function shop_order_posts_custom_column( $column ){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
$billing_address = $the_order->get_address();
if ( $column == 'phone' ) {
echo ( isset( $billing_address['phone'] ) ? $billing_address['phone'] : '');
}
}
位置问题???...
尝试第一个功能
function shop_order_columns($columns){
$columns = (is_array($columns)) ? $columns : array();
$phone = array( 'phone' => 'Phone' );
$position = 5;
$new_columns = array_slice( $columns, 0, $position, true ) + $phone;
return array_merge( $new_columns, $columns );
}
针对 WooCommerce 3 进行了更新。
关于wordpress - 如何编辑 woocommerce 管理订单页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34785747/