Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In case someone still needs it - instructions on how to add new columns in Woocommerce orders list. No need in unsetting the default columns, just add this in your functions.php and your code will be valid for updates.</p> <h1>1. Define columns position and names</h1> <pre><code>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['MY_COLUMN_ID_1'] = 'MY_COLUMN_1_TITLE'; $new_columns['MY_COLUMN_ID_2'] = 'MY_COLUMN_2_TITLE'; //stop editing $new_columns['order_actions'] = $columns['order_actions']; return $new_columns; } </code></pre> <h1>2. For each custom column, show the values</h1> <pre><code>add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 ); function MY_COLUMNS_VALUES_FUNCTION($column){ global $post; $data = get_post_meta( $post-&gt;ID ); //start editing, I was saving my fields for the orders as custom post meta //if you did the same, follow this code if ( $column == 'MY_COLUMN_ID_1' ) { echo (isset($data['MY_COLUMN_1_POST_META_ID']) ? $data['MY_COLUMN_1_POST_META_ID'] : ''); } if ( $column == 'MY_COLUMN_ID_2' ) { echo (isset($data['MY_COLUMN_2_POST_META_ID']) ? $data['MY_COLUMN_2_POST_META_ID'] : ''); } //stop editing } </code></pre> <h1>3. (optional) Function to make the columns sortable</h1> <pre><code>add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' ); function MY_COLUMNS_SORT_FUNCTION( $columns ) { $custom = array( //start editing 'MY_COLUMN_ID_1' =&gt; 'MY_COLUMN_1_POST_META_ID', 'MY_COLUMN_ID_2' =&gt; 'MY_COLUMN_2_POST_META_ID' //stop editing ); return wp_parse_args( $custom, $columns ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload