duandu1377 2018-02-28 08:29
浏览 86
已采纳

在WooCommerce 3.3上显示管理员订单列表中的订单备注

Is there any hooks or options to display order notes in WooCommerce order page in back end ? I have tried the following code and managed to add a column.

function wc_new_order_column( $columns ) {
    $columns['my_column'] = 'My column';
    return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'wc_new_order_column' );

I am stuck in adding order notes

  • 写回答

1条回答 默认 最新

  • douyun1860 2018-03-01 10:03
    关注

    The following will enable back the display of Order Notes in WooCommerce 3.3+ admin orders list:

    add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 90 );
    function custom_shop_order_column( $columns )
    {
        $ordered_columns = array();
    
        foreach( $columns as $key => $column ){
            $ordered_columns[$key] = $column;
            if( 'order_date' == $key ){
                $ordered_columns['order_notes'] = __( 'Notes', 'woocommerce');
            }
        }
    
        return $ordered_columns;
    }
    
    add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 1 );
    function custom_shop_order_list_column_content( $column )
    {
        global $post, $the_order;
    
        $customer_note = $post->post_excerpt;
    
        if ( $column == 'order_notes' ) {
    
            if ( $the_order->get_customer_note() ) {
                echo '<span class="note-on customer tips" data-tip="' . wc_sanitize_tooltip( $the_order->get_customer_note() ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
            }
    
            if ( $post->comment_count ) {
    
                $latest_notes = wc_get_order_notes( array(
                    'order_id' => $post->ID,
                    'limit'    => 1,
                    'orderby'  => 'date_created_gmt',
                ) );
    
                $latest_note = current( $latest_notes );
    
                if ( isset( $latest_note->content ) && 1 == $post->comment_count ) {
                    echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
                } elseif ( isset( $latest_note->content ) ) {
                    // translators: %d: notes count
                    echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content . '<br/><small style="display:block">' . sprintf( _n( 'Plus %d other note', 'Plus %d other notes', ( $post->comment_count - 1 ), 'woocommerce' ), $post->comment_count - 1 ) . '</small>' ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
                } else {
                    // translators: %d: notes count
                    echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( sprintf( _n( '%d note', '%d notes', $post->comment_count, 'woocommerce' ), $post->comment_count ) ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
                }
            }
        }
    }
    
    // Set Here the WooCommerce icon for your action button
    add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
    function add_custom_order_status_actions_button_css() {
        echo '<style>
        td.order_notes > .note-on { display: inline-block !important;}
        span.note-on.customer { margin-right: 4px !important;}
        span.note-on.customer::after { font-family: woocommerce !important; content: "\e026" !important;}
        </style>';
    }
    

    Code goes in function.php file of your active child theme (or theme).

    Tested and works.

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决