Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created November 25, 2014 22:42
Show Gist options
  • Save lmartins/33fbe331f18c210ff528 to your computer and use it in GitHub Desktop.
Save lmartins/33fbe331f18c210ff528 to your computer and use it in GitHub Desktop.
Custom columns in WooCommerce Orders page
/**
* Custom Columns to Woo Orders Page
* @SEE: http://stackoverflow.com/questions/13683162/woocommerce-show-custom-column
*/
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 you column(s)
//all of your columns will be added before the actions column
$new_columns['donation_code'] = 'Donation Code';
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION( $column ) {
global $post;
$order = new WC_Order( $post->ID );
$items = $order->get_items();
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'donation_code' ) {
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$donation_id = get_post_meta( $product_id, 'donation_code', true );
echo $donation_id . "<br/>";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment