添加WooCommerce订单列表列和值 [英] Add a WooCommerce Orders List Column and value
本文介绍了添加WooCommerce订单列表列和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在woo贸易订单页面(管理端)中,我想在订单列表中添加直接送货"列
In woo commerce order page(Admin Side) I want to add Drop Shipping column in order list
我通过
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_total' ){
$reordered_columns['drop_shipping'] = __( 'Drop Shipping','twentyseventeen');
}
}
return $reordered_columns;
}
有效
现在我想在该字段中显示填充数据
Now I want to show populate data in that field
我从这里找到了解决方法
I found the solution from here
我遵循与提及相同的步骤,但是我无法获得价值
I follow same step as mention but I cant get the value
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
//echo $column;
switch ( $column )
{
case 'drop_shipping' :
// Get custom post meta data
$my_var_one = get_post_meta( $post_id, 'drop_shipping', true );
if(!empty($my_var_one))
echo $my_var_one;
// Testing (to be removed) - Empty value case
else
echo '<small>(<em>no value</em>)</small>';
break;
}
}
我也检查了wp_postmeta表,但是没有找到结果.
Also I check wp_postmeta table but there is no result found..
能否请您告诉我我在哪里做错了以及如何在drop_shipping中增加价值
Can you please tell me where is I done mistake and how to add value in drop_shipping
谢谢.
推荐答案
按照建议我弄错了,我在wp_postmeta中添加了_drop_shipping
As per Suggestion I got my mistake, I add _drop_shipping
in wp_postmeta
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 'drop_shipping' :
if(get_post_meta( $post_id, '_drop_shipping', true )){
$my_var_one = get_post_meta( $post_id, '_drop_shipping', true );
echo $my_var_one;
}
else{
add_post_meta($post_id, '_drop_shipping', $post_id);
$my_var_one = get_post_meta( $post_id, '_drop_shipping', true );
echo $my_var_one;
}
break;
}
}
这篇关于添加WooCommerce订单列表列和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文