php - 在 WooCommerce 3.3 的管理员订单列表中显示退回订单备注

标签 php wordpress woocommerce backend orders

是否有任何钩子(Hook)或选项可以在后端的 WooCommerce 订单页面中显示订单备注? 我尝试了以下代码并设法添加了一列。

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

我卡在添加订单备注了

最佳答案

以下将在 WooCommerce 3.3+ 管理订单列表中重新显示订单备注:

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>';
}

代码进入您活跃的子主题(或主题)的 function.php 文件。

经过测试并有效。

enter image description here

关于php - 在 WooCommerce 3.3 的管理员订单列表中显示退回订单备注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49025066/

相关文章:

php - 将应用优惠券描述添加到 WooCommerce 管理员电子邮件通知

php - 使用行和列索引以表格格式显示数据库表中的数据

php使用insert语句添加到数据库

javascript - 如何将 jquery 添加到 wordpress 插件

php - 更改 Woocommerce 电子邮件表总计中的 "Shipping"标签?

jquery - WordPress 定制器中的 slider UI

php - 当购物车不为空时设置购物车永久链接

php - 在 Woocommerce 中下订单后,将附件添加到管理员电子邮件通知

php - 更改kartik dynagrid操作列

php - 使用 php 动态创建 zip