問題描述
我希望在客戶的訂單歷史記錄中顯示最后一個訂單說明,目前只能通過 Woocommerce 中的管理員查看.
I am looking to display the last Order Note, currently only viewable via Admin in Woocommerce, on the customer side in their Order History.
這樣他們就可以查看我們在之后添加的跟蹤編號,訂單被設置為完成.
So they can view the tracking number we add in after the order is set as complete.
https://example.com/my-account/view-order/135/
我們首先通過 Woocommerce API 將訂單設置為 COMPLETE,然后添加帶有跟蹤鏈接的訂單備注,從而添加客戶備注.因此,跟蹤引用將始終是最后一項.
We add a customer note by first setting the order as COMPLETE via the Woocommerce API then adding an order note with the tracking link. So the tracking ref will always be the last item.
如何在客戶訂單歷史記錄中顯示最后一個訂單備注?似乎不存在用于在客戶端顯示訂單備注的插件.
How can I show the last Order Note on the customer order history? No plugins seem to exist for Order Notes to be shown on the customer side.
理想的結果:
推薦答案
以下將顯示最后的管理員訂單備注到我的帳戶查看訂單頁面:
The following will display last admin order note to my account view orders pages:
add_filter( 'woocommerce_get_order_item_totals', 'account_view_order_last_order_note', 10, 3 );
function account_view_order_last_order_note( $total_rows, $order, $tax_display ){
// For "completed" orders on my account view order pages
if( $order->has_status('completed') && is_wc_endpoint_url( 'view-order' ) ){
// Get last order note
$latest_notes = wc_get_order_notes( array(
'order_id' => $order->get_id(),
'limit' => 1,
'orderby' => 'date_created_gmt',
) );
$latest_note = current( $latest_notes );
if ( isset( $latest_note->content ) ) {
// Add a new row for tracking
$total_rows['order_tracking'] = array(
'label' => __('Tracking:','woocommerce'),
'value' => $latest_note->content
);
}
}
return $total_rows;
}
代碼位于活動子主題(或活動主題)的 function.php 文件中.經測試有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
這篇關于在客戶訂單歷史記錄中顯示最后的 WooCommerce 管理員訂單備注的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!