skip to Main Content

i want to show a custom text in orders preview in WooCommerce.

enter image description here


I found that public function render_billing_address_column in

includes/admin/list-tables/class-wc-admin-list-table-orders.php

i could modify the code and add some text there but im looking for way for doing this in another custom plugin

 if ( order had this specification ) {
    echo 'my custom text;
 }

2

Answers


  1. Chosen as BEST ANSWER

    thank you MrEbabi your code goes to function and worked well. also if someone want to read $post_meta from a order and do something they could done it with below code

    function column_content_with_custom_text( $column ) {
    global $post;
    $order = new WC_Order( $order_id );
    
    if ( 'billing_address' === $column ) {
    if( empty( get_post_meta( $post->ID, 'custom_meta', true ) ) ) {
        echo "<b>Custom Text</b><br>";
    }
    

  2. You can use either of these hooks: woocommerce_admin_order_preview_start or woocommerce_admin_order_preview_end like this:

    add_action( 'woocommerce_admin_order_preview_end', 'lets_show_something_in_preview' );
    function lets_show_something_in_preview() {
        if ( order had this specification ) { 
           echo 'my custom text'; 
        }
    }
    

    or

    add_action( 'woocommerce_admin_order_preview_start', 'lets_show_something_in_preview' );
    function lets_show_something_in_preview() {
        if ( order had this specification ) { 
            echo 'my custom text'; 
        }
    }
    

    or adding a custom column with custom text:

    add_filter( 'manage_edit-shop_order_columns', 'lets_add_a_new_column_to_admin_order_page' );
    
    function lets_add_a_new_column_to_admin_order_page( $columns ) 
    {
        $columns['another_column'] = 'Your Column';
        return $columns;
    }
    
    add_action( 'manage_shop_order_posts_custom_column', 'column_content_with_custom_text' );
    
    function column_content_with_custom_text( $column )
    {
        global $post;
    
        if ( 'another_column' === $column ) 
        {
            echo "Your Custom Text";
        }
    }
    

    or edit a specific column by adding custom text:
    enter image description here

    add_action( 'manage_shop_order_posts_custom_column', 'column_content_with_custom_text' );
    
    function column_content_with_custom_text( $column )
    {
        global $post;
    
        if ( 'billing_address' === $column ) 
        {
            echo "<b>Your Custom Text</b><br>";
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search