How to add AliExpress order number and tracking number columns to All Orders view

the_lyall

Active Member
I was having difficulty keeping track of which orders I’d already placed on AliExpress and which ones had order lines that still needed shipping, without going into the order details. Therefore I added the below columns so I have an ‘at a glance’ view. This is the most useful thing I’ve added and I put it on all sites (I have emailed this as a suggestion to add in last year).

1590487860207.png

This is especially useful for multi-product orders as you can see at a glance how many order lines are still awaiting shipping.

This is very simple to add. Just add the following code into your child theme* functions.php file in Appearance > Theme Editor

*It is important to always work with a child theme and not to edit the main theme, as any updates you make will be lost if you update the theme otherwise. I recommend Child Theme Configurator plugin for easily creating a child theme.

Code to add:
Updated 30/05/20 thanks to @nenene for the idea of making the order and tracking numbers clickable

PHP:
// ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping "Total" and "Actions" columns at the end)
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns)
{
    $reordered_columns = array();

    // Inserting columns to a specific location
    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key ==  'order_status' ){
            // Inserting after "Status" column
            $reordered_columns['my-column1'] = __( 'AliExpress Order(s)','theme_domain');
            $reordered_columns['my-column2'] = __( 'Tracking','theme_domain');
        }
    }
    return $reordered_columns;
}

// Adding custom fields meta data for each new column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
    switch ( $column )
    {
        case 'my-column1' :
            global $post;
            $order = wc_get_order( $post->ID );
            $items = $order->get_items();

            foreach ( $order->get_items() as $item_id => $item ) {

                // Here you get your data
                $custom_field = wc_get_order_item_meta( $item_id, 'adsw_order_number', true );

                // To test the output
                // print_r($custom_field);
               
                if(!empty($custom_field)){
                // If it is an array of values
                if( is_array( $custom_field ) ){
                    echo implode('<br>', $custom_field ); // one value displayed by line
                }
                // just one value (a string)
                else {
                    echo '<a href="https://trade.aliexpress.com/order_detail.htm?orderId='.$custom_field.'" target="_blank">'.$custom_field.'</a><br>';
                }
                }
                else {
                    echo '<small>(<em>Not placed</em>)</small><br/>';
                }
            }


            break;

        case 'my-column2' :
           global $post;
            $order = wc_get_order( $post->ID );
            $items = $order->get_items();

            foreach ( $order->get_items() as $item_id => $item ) {

                // Here you get your data
                $custom_field = wc_get_order_item_meta( $item_id, 'adsw_tip', true );

                if(!empty($custom_field)){
                // If it is an array of values
                if( is_array( $custom_field ) ){
                    echo implode( '<br>', $custom_field ); // one value displayed by line
                }
                // just one value (a string)
                else {
                    echo '<a href="https://global.cainiao.com/detail.htm?mailNoList='.$custom_field.'" target="_blank">'.$custom_field.'</a><br>';
                }
                }
                else {
                    echo '<small>(<em>No tracking</em>)</small><br/>';
                }
            }
    }
}

That's it!
 
Last edited:

Mar

Moderator
I was having difficulty keeping track of which orders I’d already placed on AliExpress and which ones had order lines that still needed shipping, without going into the order details. Therefore I added the below columns so I have an ‘at a glance’ view. This is the most useful thing I’ve added and I put it on all sites (I have emailed this as a suggestion to add in last year).

View attachment 11936

This is especially useful for multi-product orders as you can see at a glance how many order lines are still awaiting shipping.

This is very simple to add. Just add the following code into your child theme* functions.php file in Appearance > Theme Editor

*It is important to always work with a child theme and not to edit the main theme, as any updates you make will be lost if you update the theme otherwise. I recommend Child Theme Configurator plugin for easily creating a child theme.

Code to add:

PHP:
// ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping "Total" and "Actions" columns at the end)

add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns)
{
    $reordered_columns = array();

    // Inserting columns to a specific location
    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key ==  'order_status' ){
            // Inserting after "Status" column
            $reordered_columns['my-column1'] = __( 'AliExpress Order(s)','theme_domain');
            $reordered_columns['my-column2'] = __( 'Tracking','theme_domain');
        }
    }
    return $reordered_columns;
}

// Adding custom fields meta data for each new column
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
    switch ( $column )
    {
        case 'my-column1' :
            global $post;
            $order = wc_get_order( $post->ID );
            $items = $order->get_items();

            foreach ( $order->get_items() as $item_id => $item ) {


                $custom_field = wc_get_order_item_meta( $item_id, 'adsw_order_number', true );
            
                if(!empty($custom_field)){
                // If it is an array of values
                if( is_array( $custom_field ) ){
                    echo implode('<br>', $custom_field ); // one value displayed by line
                }
                // just one value (a string)
                else {
                    echo $custom_field.'<br>';
                }
                }
                else {
                    echo '<small>(<em>Not placed</em>)</small><br/>';
                }
            }


            break;

        case 'my-column2' :
           global $post;
            $order = wc_get_order( $post->ID );
            $items = $order->get_items();

            foreach ( $order->get_items() as $item_id => $item ) {

                // Here you get your data
                $custom_field = wc_get_order_item_meta( $item_id, 'adsw_tip', true );

                if(!empty($custom_field)){
                // If it is an array of values
                if( is_array( $custom_field ) ){
                    echo implode( '<br>', $custom_field ); // one value displayed by line
                }
                // just one value (a string)
                else {
                    echo $custom_field.'<br>';
                }
                }
                else {
                    echo '<small>(<em>No tracking</em>)</small><br/>';
                }
            }
    }
}

That's it!
Very good.
 

the_lyall

Active Member
Thanks for making these cool things!
Is these fields clickable?

Updated version below with clickable fields. Tracking link opens with Cainiao but you can change the link to use any tracking page you want, or even your own tracking page if using that option like I am. Thank you for the suggestion!

PHP:
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns)
{
    $reordered_columns = array();

    // Inserting columns to a specific location
    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key ==  'order_status' ){
            // Inserting after "Status" column
            $reordered_columns['my-column1'] = __( 'AliExpress Order(s)','theme_domain');
            $reordered_columns['my-column2'] = __( 'Tracking','theme_domain');
        }
    }
    return $reordered_columns;
}

// Adding custom fields meta data for each new column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
    switch ( $column )
    {
        case 'my-column1' :
            global $post;
            $order = wc_get_order( $post->ID );
            $items = $order->get_items();

            foreach ( $order->get_items() as $item_id => $item ) {

                // Here you get your data
                $custom_field = wc_get_order_item_meta( $item_id, 'adsw_order_number', true );

                // To test the output
                // print_r($custom_field);
               
                if(!empty($custom_field)){
                // If it is an array of values
                if( is_array( $custom_field ) ){
                    echo implode('<br>', $custom_field ); // one value displayed by line
                }
                // just one value (a string)
                else {
                    echo '<a href="https://trade.aliexpress.com/order_detail.htm?orderId='.$custom_field.'" target="_blank">'.$custom_field.'</a><br>';
                }
                }
                else {
                    echo '<small>(<em>Not placed</em>)</small><br/>';
                }
            }


            break;

        case 'my-column2' :
           global $post;
            $order = wc_get_order( $post->ID );
            $items = $order->get_items();

            foreach ( $order->get_items() as $item_id => $item ) {

                // Here you get your data
                $custom_field = wc_get_order_item_meta( $item_id, 'adsw_tip', true );

                if(!empty($custom_field)){
                // If it is an array of values
                if( is_array( $custom_field ) ){
                    echo implode( '<br>', $custom_field ); // one value displayed by line
                }
                // just one value (a string)
                else {
                    echo '<a href="https://global.cainiao.com/detail.htm?mailNoList='.$custom_field.'" target="_blank">'.$custom_field.'</a><br>';
                }
                }
                else {
                    echo '<small>(<em>No tracking</em>)</small><br/>';
                }
            }
    }
}

Tested and works :)
 

Robmar G

New Member
Buddy how are you?, I text you at pm about this code. Let me tell you it is amazing and thank you so much for wrote it. But the problem now is I don't know if with the last aliwoo update or even woocommerce isn't working properly, It shows the columns but stays clear (not placed) when I already placed the order.
 
Top