在Woocommerce管理员订单列表中显示作者和日期的订单注释 [英] Show Order Notes with author and date in Woocommerce Admin Order List

查看:124
本文介绍了在Woocommerce管理员订单列表中显示作者和日期的订单注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用" 答案代码,我能够在管理员订单列表中添加订单注释"列,但它仅显示状态已从一个"状态更改为到另一个.

Using "Display back Order Notes in Admin orders list on WooCommerce 3.3" answer code, I am able to add Order notes column in Admin orders list, but it only shows that status changed from One status to another.

现在,我也想向作者显示此更改和日期,就像在订单编辑页面中一样.

Now I would like also to show author of this change and date when it's happened, just, just like in order edit pages.

有什么建议吗?

推荐答案

没有必要将global $post, $the_order;manage_shop_order_posts_custom_column一起使用.这是因为第二个参数包含$post_id

It is not necessary to use global $post, $the_order; with manage_shop_order_posts_custom_column. This is because there is a 2nd parameter that contains the $post_id


$latest_note仅包含注释,而作者和日期除外.

$latest_note contains more then only the note, also the author and the date are available among others


根据现有规则,通过样式表而不是通过admin_head


很高兴看到您是否已找到代码并想要添加其他功能, 您首先尝试先寻求帮助

It is always nice to see if you have found code and you want to add extra functionality, you first try before asking for help

要回答您的问题,请应用以下内容

To answer your question, apply the following

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_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 10, 1 );


function custom_shop_order_list_column_content( $column, $post_id ) {

    // Get $order object
    $order = wc_get_order( $post_id );

    if ( $column == 'order_notes' ) {

        if ( $order->get_customer_note() ) {
            echo '<span class="note-on customer tips" data-tip="' . wc_sanitize_tooltip( $order->get_customer_note() ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
        }

        // Retrieves the amount of comments a post has.
        $amount_of_comments = get_comments_number( $post_id );

        if ( $amount_of_comments > 0 ) {

            $latest_notes = wc_get_order_notes( array(
                'order_id' => $post_id,
                'limit'    => 1,
                'orderby'  => 'date_created_gmt',
            ) );

            $latest_note = current( $latest_notes );

            // Content
            $content = $latest_note->content;

            // Added by
            $added_by = $latest_note->added_by;

            // Date created - https://www.php.net/manual/en/function.date.php
            $date_created = $latest_note->date_created->date('j F Y - g:i:s');

            if ( isset( $content ) && $amount_of_comments == 1 ) {
                echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( 'Author: ' . $added_by . '<br/>' . 'Date: ' . $date_created . '<br/>' . $content ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
            } elseif ( isset( $content ) ) {
                // translators: %d: notes count
                echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( 'Author: ' . $added_by . '<br/>' . 'Date: ' . $date_created . '<br/>' . $content . '<br/><small style="display:block">' . sprintf( _n( 'Plus %d other note', 'Plus %d other notes', ( $amount_of_comments - 1 ), 'woocommerce' ), $amount_of_comments - 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', $amount_of_comments, 'woocommerce' ), $amount_of_comments ) ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
            }
        }
    }
}
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 2 );

这篇关于在Woocommerce管理员订单列表中显示作者和日期的订单注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆