PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 12, 2022

[FIXED] Display user description in WooCommerce admin order edit pages after billing address

 February 12, 2022     backend, hook-woocommerce, orders, woocommerce, wordpress     No comments   

Issue

I need to display customer Bio in WooCommerce admin order edit pages after the billing address.

Actually I only succeeded to display in a column like that:

column

With this code:

 // Adding a custom new column to admin orders list
add_filter( 'manage_edit-shop_order_columns', 'custom_column_eldest_players', 20 );
function custom_column_eldest_players($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['user-bio'] = __( 'Note client', 'woocommerce');
        }
    }
    return $reordered_columns;
}

// Adding custom fields meta data for the 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 ) {
    if ( 'user-bio' === $column ) {
        global $the_order;

        echo ( $user = $the_order->get_user() ) ? $user->description : 'n/c';
    }
}

But I don't know how to insert in WooCommerce admin order edit pages. Any advice?


Solution

Do display the user description on the admin order pages after billing adress you can use the woocommerce_admin_order_data_after_billing_address acton hook.

So you get:

// Display on admin order pages after billing adress
function action_woocommerce_admin_order_data_after_billing_address( $order ) {  
    // Get user
    $user = $order->get_user();
    
    // Initialize
    $output = __( 'Bio: ', 'woocommerce' );

    // Is a WP user
    if ( is_a( $user, 'WP_User' ) ) {
        ! empty( $user->description ) ? $output .= $user->description : $output .= __( 'n/c', 'woocommerce' );
    } else {
        $output .= __( 'n/c', 'woocommerce' );
    }
    
    // Output
    echo $output;
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );


Answered By - 7uc1f3r
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing