In woo commerce order page(Admin Side) I want to add Drop Shipping column in order list
which I done through
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;
}
}
Also I check wp_postmeta table but there is no result found..
Can you please tell me where is I done mistake and how to add value in drop_shipping
Thank You.
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;
}
}