skip to Main Content

I’m looking to add a column to the Woocommerce Orders page – specifically "company name". This is listed in the orders as ‘Customer’. I’d like to display this as a column in the orders page.

2

Answers


  1. <pre>
    Step 1:-
    /* add custom column under order listing page */
    /**
     * Add 'Company name' column header to 'Orders' page immediately after 'Total' column.
     *
     * @param string[] $columns
     * @return string[] $new_columns
     */
    function sv_wc_cogs_add_order_profit_column_header( $columns ) {
    
        $new_columns = array();
    
        foreach ( $columns as $column_name => $column_info ) {
    
            $new_columns[ $column_name ] = $column_info;
    
            if ( 'order_total' === $column_name ) {
                
                $new_columns['company_name'] = __( 'Company name', 'my-textdomain' );
            }
        }
    
        return $new_columns;
    }
    add_filter( 'manage_edit-shop_order_columns', 'sv_wc_cogs_add_order_profit_column_header', 20 );
    
    Step 2:-
    
    /**
     * Add 'Company name' column content to 'Orders' page immediately after 'Total' column.
     *
     * @param string[] $column name of column being displayed
     */
    function sv_wc_cogs_add_order_profit_column_content( $column ) {
        global $post;
    
        if ( 'company_name' === $column ) {
    
           
            $company_name = !empty(get_post_meta($post->ID,'company_name',true)) ? get_post_meta($post->ID,'company_name',true) : 'N/A';
            
    
            echo $company_name;
        }
        
    }
    add_action( 'manage_shop_order_posts_custom_column', 'sv_wc_cogs_add_order_profit_column_content' );
    </pre>
    

    Copy above code in theme functions.php file

    Login or Signup to reply.
  2. Change code from 
    
     $company_name = !empty(get_post_meta($post->ID,'company_name',true)) ? get_post_meta($post->ID,'company_name',true) : 'N/A';
    
    To 
    
     $company_name = !empty(get_post_meta($post->ID,'_billing_company',true)) ? get_post_meta($post->ID,'_billing_company',true) : 'N/A';
    

    I hope will this work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search