Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

Adding Columns to My Orders List in WooCommerce

In my WooCommerce site, I want to add some columns to my order listing page in the woocommerce admin area. We’re looking at the “Orders” menu in the my account page currently, which shows order number, date, status, total, and actions column by default . In this column list we are add “Ship to” column. So let’s have a look. how we can do this.

For this, Add below line of code in your theme’s functions.php file of your active child theme (or theme) and save the file. You can “ship to” column added in my orders list in WooCommerce.


function add_column_orders_list_adminpanel( $columns ) {
    $new_columns = array();
    foreach ( $columns as $key => $name ) {
        $new_columns[ $key ] = $name;
        // add ship-to after order status column
        if ( 'order-status' === $key ) {
            $new_columns['order-ship-to'] = __( 'Ship to', 'textdomain' );
        }
    }
    return $new_columns;
}
add_filter( 'woocommerce_my_account_my_orders_columns', 'add_column_orders_list_adminpanel' );


// Adds data to the custom "ship to" column in "My Account > Orders".

function add_data_my_orders_ship_to_column( $order ) {
    $formatted_shipping = $order->get_formatted_shipping_address();
    echo ! empty( $formatted_shipping ) ? $formatted_shipping : '–';
}
add_action( 'woocommerce_my_account_my_orders_column_order-ship-to', 'add_data_my_orders_ship_to_column' );

Exit mobile version