问题
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;
}
and in my store checkout I collect these two meta keys: "dname" and "additional_allergies"
回答1:
Assuming the
meta_keys
used =dname
andadditional_allergies
. If this is not the case, you will see the 'Meta key is wrong' message, then it is a matter of looking for the right meta_key in your database.
// Add a Header
function custom_shop_order_column( $columns ) {
// Add new columns
$columns['dogs_name'] = 'Dogs Name';
$columns['additional_allergies'] = 'Allergies';
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 10, 1 );
// Populate the Column
function custom_shop_order_list_column_content( $column, $post_id ) {
// Compare
if ( $column == 'dogs_name' ) {
$dogs_name = get_post_meta( $post_id, 'dname', true);
if ( $dogs_name ) {
echo $dogs_name;
} else {
echo 'Meta key is wrong';
}
}
if ( $column == 'additional_allergies' ) {
$allergies = get_post_meta( $post_id, 'additional_allergies', true);
if ( $allergies ) {
echo $allergies;
} else {
echo 'Meta key is wrong';
}
}
}
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 2 );
来源:https://stackoverflow.com/questions/61154720/im-collecting-meta-key-data-and-i-want-to-display-it-in-the-wordpress-dashboar