'Add custom column with metadata on WooCommerce admin orders list

I'm want to add custom column(s) with some meta data on the WooCommerce admin orders list. I found, and modified this for my needs, and put it in my functions.php:

add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION( $columns ) {
    $new_columns = ( is_array( $columns ) ) ? $columns : array();
    unset( $new_columns[ 'order_actions' ] );
    
    //edit this for your column(s)
    //all of your columns will be added before the actions column
    $new_columns['dname'] = 'Dogs Name';
    $new_columns['additional_allergies'] = 'Allergies';
    
    //stop editing
    $new_columns[ 'order_actions' ] = $columns[ 'order_actions' ];
    return $new_columns;
}

At checkout I collect these two meta keys:

  • dname
  • additional_allergies

However, my current code only shows empty columns, any advice to add the meta datea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source