Advertisement
lorro

WooCommerce - Add extra columns to the shop order table

Feb 23rd, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. // WooCommerce - Add extra columns to the shop order table
  3. // since v3.3
  4.  
  5. add_filter( 'manage_shop_order_posts_columns', 'set_shop_order_posts_columns', 99 );
  6. function set_shop_order_posts_columns( $columns ) {
  7.   // $columns['unwanted_column'] = 'Unwanted column'; // comment out any unwanted columns
  8.   $columns['order_items'] = 'Order items';
  9.   $columns['order_notes'] = 'Order notes';
  10.   $columns['payment_method'] = 'Payment<br>Method';
  11.   return $columns;
  12. }
  13.  
  14. add_action( 'manage_shop_order_posts_custom_column' , 'show_custom_columns', 10, 2 );
  15. function show_custom_columns( $column_name, $post_id ) {
  16.   switch ( $column_name ) {
  17.     case 'order_items':
  18.       $order = new WC_Order( $post_id );
  19.       $order_items = $order->get_items();
  20.       $nr = 1;
  21.       foreach( $order_items as $order_item ) {
  22.         print $nr.') '.$order_item->get_name().'<br>';
  23.         $nr++;
  24.       }
  25.       break;
  26.     case 'order_notes':
  27.       $order = new WC_Order( $post_id );
  28.       $note = $order->get_customer_note();
  29.       // choose one of the following print statements
  30.       // print $note;
  31.       print $note ? 'Yes' : '';
  32.       break;
  33.     case 'payment_method':
  34.       $order = new WC_Order( $post_id );
  35.       print $order->get_payment_method();
  36.       break;
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement