Created
July 28, 2013 16:31
-
-
Save milesstewart88/6099184 to your computer and use it in GitHub Desktop.
Place the custom field values in the custom columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Custom fields in custom admin columns | |
*/ | |
add_action( 'manage_orders_posts_custom_column', 'my_manage_orders_columns', 10, 2 ); | |
function my_manage_orders_columns( $column, $post_id ) { | |
global $post; | |
switch( $column ) { | |
/* If displaying the 'email' column. */ | |
case 'user_email_address' : | |
/* Get the post meta. */ | |
$email = get_post_meta( $post_id, 'user_email_address', true ); | |
/* If no email is found, output a default message. */ | |
if ( empty( $email ) ) | |
echo __( 'Unknown' ); | |
else | |
echo $email; | |
break; | |
/* If displaying the 'order_amount' column. */ | |
case 'order_amount' : | |
/* Get the post meta. */ | |
$order_amount = get_post_meta( $post_id, 'order_amount', true ); | |
/* If no order_amount is found, output a default message. */ | |
if ( empty( $order_amount ) ) | |
echo __( 'Unknown' ); | |
else | |
echo $order_amount; | |
break; | |
/* If displaying the 'transaction_id' column. */ | |
case 'transaction_id' : | |
/* Get the post meta. */ | |
$transaction_id = get_post_meta( $post_id, 'transaction_id', true ); | |
/* If no transaction_id is found, output a default message. */ | |
if ( empty( $transaction_id ) ) | |
echo __( 'Unknown' ); | |
else | |
echo $transaction_id; | |
break; | |
/* If displaying the 'order_status' column. */ | |
case 'order_status' : | |
/* Get the post meta. */ | |
$order_status = get_post_meta( $post_id, 'order_status', true ); | |
/* If no order_status is found, output a default message. */ | |
if ( empty( $order_status ) ) | |
echo __( 'Unknown' ); | |
else | |
echo $order_status; | |
break; | |
/* Just break out of the switch statement for everything else. */ | |
default : | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment