簡體   English   中英

在 WooCommerce 我的帳戶訂單列表中添加發送給客戶的管理員訂單備注

[英]Add Admin order notes sent to customer in WooCommerce My Account Orders list

基於WooCommerce admin orders list custom column with order notes sent to customer answer code,我嘗試添加以下代碼以在 WooCommerce 我的帳戶訂單列表中創建一個新列,我已將manage_edit-shop_order_columns更改為woocommerce_my_account_my_orders_columns掛鈎,但未成功:

// Add custom column on admin orders list page
add_filter( 'woocommerce_my_account_my_orders_columns', 'add_order_notes_column' );
function add_order_notes_column( $columns ) {
    $columns['order_notes'] = 'Order Notes';
    return $columns;
}

// CSS styles
add_action( 'admin_print_styles', 'add_order_notes_column_style' );
function add_order_notes_column_style() {
    $css = '.post-type-shop_order table.widefat.fixed { table-layout: auto; width: 100%; }';
    $css .= 'table.wp-list-table .column-order_notes { min-width: 280px; text-align: left; }';
    $css .= '.column-order_notes ul { margin: 0 0 0 18px; list-style-type: disc; }';
    // $css .= '.order_customer_note { color: #ee0000; }'; // red
    // $css .= '.order_private_note { color: #0000ee; }'; // blue
    wp_add_inline_style( 'woocommerce_admin_styles', $css );
}

// Admin orders list custom column displayed content
add_action( 'woocommerce_my_account_my_orders_columns', 'add_order_notes_content' );
function add_order_notes_content( $column ) {
    global $post, $the_order;

    if( 'order_notes' !== $column )
        return;

    $order = is_a($the_order, 'WC_Order') ? $the_order : wc_get_order( $post->ID );

    $notes = wc_get_order_notes( array(
        'order_id' => $order->get_id(),
        'order_by' => 'date_created',
        'order' => 'ASC',
    ) );

    if( ! empty($notes) ) {
        echo '<ul>';

        foreach( $notes as $note ) {
            if( $note->customer_note && 'system' !== $note->added_by ) {
                echo '<li class="order_customer_note">' . sprintf( __('%s by %s <br> %s:'),
                    date_i18n( 'm/d/y H:i', strtotime( $note->date_created ) ),
                    $note->added_by,
                    $note->content
                ) . '</li>';
            }
        }
        echo '</ul>';
    }
}

我希望這個專欄的內容是一樣的,但我希望標題說“下載”。

更新:這是一個屏幕截圖,我希望列到 go:

欄目截圖

您的代碼中有很多錯誤... 要將管理員在我的帳戶訂單中發送的客戶訂單備注顯示為新列,請改用以下內容:

// Add custom column on admin orders list page
add_filter( 'woocommerce_my_account_my_orders_columns', 'add_myaccount_admin_order_notes_column' );
function add_myaccount_admin_order_notes_column( $columns ) {
    $column_actions = $columns['order-actions'];
    unset($columns['order-actions']);

    $columns['admin-notes'] = __('Admin Notes', 'woocommerce');
    $columns['order-actions'] = $column_actions;

    return $columns;
}

// CSS styles
add_action( 'wp_head', 'myaccount_admin_order_notes_inline_style', 100 );
function myaccount_admin_order_notes_inline_style() {
    if( is_account_page() && is_wc_endpoint_url('orders') ) :
    ?><style>ul.order-note-item {list-style:none; margin:0;} ul.order-note-item > li { margin:0 0 6px;}</style><?php
    endif;
}

// Admin orders list custom column displayed content
add_action( 'woocommerce_my_account_my_orders_column_admin-notes', 'add_myaccount_admin_order_notes_content' );
function add_myaccount_admin_order_notes_content( $order ) {
    $notes = wc_get_order_notes( array(
        'order_id' => $order->get_id(),
        'order_by' => 'date_created',
        'order' => 'ASC',
    ) );

    if( ! empty($notes) ) {
        $output = [];

        foreach( $notes as $note ) {
            if( $note->customer_note && 'system' !== $note->added_by ) {
                $output[] = sprintf( __('%s <br> %s'),
                    date_i18n( 'm/d/y H:i', strtotime( $note->date_created ) ),
                    $note->content
                );
            }
        }
        echo '<ul class="order-note-item"><li>'. implode('</li><li>', $output) .'</li></ul>';
    }
}

代碼進入活動子主題(或活動主題)的functions.php文件。 測試和工作。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM