Adding a WooCommerce Order List Column and Value

In the woo page of the trade order (Admin Side) I want to add the Drop Shipping column to the list of orders

which i did 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;                                       
}

It works enter image description here

Now I want to show the completed data in this field

I found a solution here

I follow the same step as the mention, but I cannot 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;                        
    } 

}

I also check the wp_postmeta table, but the result was not found.

Could you tell me where I made a mistake and how to add value to drop_shipping

Thank.

0
source share

All Articles