Display product Name on the Orders page

The default Orders page of the client Dashboard in Woocommerce does not display the product name. This code will add a column and display the product name.

// Add product Name in Orders - client area
add_filter('woocommerce_create_account_default_checked', '__return_true'); 

add_filter( 'woocommerce_my_account_my_orders_columns', 'additional_my_account_orders_column', 10, 1 );
function additional_my_account_orders_column( $columns ) {
    $new_columns = [];

    foreach ( $columns as $key => $name ) {
        $new_columns[ $key ] = $name;

        if ( 'order-status' === $key ) {
            $new_columns['order-items'] = __( 'Product | qty', 'woocommerce' );
        }
    }
    return $new_columns;
}

add_action( 'woocommerce_my_account_my_orders_column_order-items', 'additional_my_account_orders_column_content', 10, 1 );
function additional_my_account_orders_column_content( $order ) {
    $details = array();

    foreach( $order->get_items() as $item )
        $details[] = $item->get_name() . ' × ' . $item->get_quantity();

    echo count( $details ) > 0 ? implode( '<br>', $details ) : '–';
}
// END- Add product Name in Orders - client area
Before the snippet
After adding the snippet

As you see in the picture above. If clients purchased many products, they will easy to know which product is what, to view and browse.

You should add the script above into the functions.php file of your child theme.

We will be happy to hear your thoughts

Leave a reply

Turnkey Websites
Logo
Register New Account
Login to the site