热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

php–在WooCommerce中将列添加到管理员订单列表

我正在为我的一个电子商务WordPress网站使用WooCommerce插件.我想在WooCommerce管理区域的订单列表页面中添加一些列.我无法找到添加它的位置.任何人都可以建

我正在为我的一个电子商务WordPress网站使用WooCommerce插件.我想在WooCommerce管理区域的订单列表页面中添加一些列.我无法找到添加它的位置.

任何人都可以建议我需要修改哪个模板页面以满足我的要求吗?

解决方法:


Updated: 2018-03-30 – added positioning feature to the new columns


因此,如果要在订单管理员列表页面(后端)中添加一些列,请执行以下操作:

在WOOCOMMERCE ADMIN ORDERS列表中添加列

在下面的示例中,我们在现有的“Total”和“Actions”列之前添加了2个新的自定义列.

// ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping "Total" and "Actions" columns at the end)
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns)
{
$reordered_columns = array();
// Inserting columns to a specific location
foreach( $columns as $key => $column){
$reordered_columns[$key] = $column;
if( $key == 'order_status' ){
// Inserting after "Status" column
$reordered_columns['my-column1'] = __( 'Title1','theme_domain');
$reordered_columns['my-column2'] = __( 'Title2','theme_domain');
}
}
return $reordered_columns;
}
// Adding custom fields meta data for each new column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
switch ( $column )
{
case 'my-column1' :
// Get custom post meta data
$my_var_One= get_post_meta( $post_id, '_the_meta_key1', true );
if(!empty($my_var_one))
echo $my_var_one;
// Testing (to be removed) - Empty value case
else
echo '(no value)';
break;
case 'my-column2' :
// Get custom post meta data
$my_var_two = get_post_meta( $post_id, '_the_meta_key2', true );
if(!empty($my_var_two))
echo $my_var_two;
// Testing (to be removed) - Empty value case
else
echo '(no value)';
break;
}
}

代码位于活动子主题(或活动主题)的function.php文件中.经过测试和工作.

enter image description here

相关答案(适用于产品):Add custom columns to admin producs list in WooCommerce backend


推荐阅读
author-avatar
小哥
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有