在 WooCommerce 我的帐户订单列表中添加发送给客户的管理员订单备注 [英] Add Admin order notes sent to customer in WooCommerce My Account Orders list
问题描述
基于
您的代码中有很多错误... 要将管理员发送的客户订单备注显示在我的帐户订单中作为新列,请改用以下内容:
>
//在管理订单列表页面添加自定义列add_filter('woocommerce_my_account_my_orders_columns', 'add_myaccount_admin_order_notes_column');函数 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;返回 $columns;}//CSS 样式add_action('wp_head', 'myaccount_admin_order_notes_inline_style', 100);函数 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万一;}//管理订单列表自定义列显示内容add_action('woocommerce_my_account_my_orders_column_admin-notes', 'add_myaccount_admin_order_notes_content');函数 add_myaccount_admin_order_notes_content( $order ) {$notes = wc_get_order_notes( 数组('order_id' =>$order->get_id(),'order_by' =>'创建日期','订单' =>'ASC',) );如果(!空($notes)){$输出= [];foreach( $notes as $note ) {if( $note->customer_note && 'system' !== $note-> added_by ) {$output[] = sprintf( __('%s
%s'),date_i18n('m/d/y H:i', strtotime( $note->date_created ) ),$note->内容);}}echo '- '.implode('</li><li>', $output) .'</li></ul>';}}
代码位于活动子主题(或活动主题)的functions.php 文件中.经测试有效.
Based on WooCommerce admin orders list custom column with order notes sent to customer answer code, I have tried unsuccessfully to add the following code to make a new column in the WooCommerce My Account Orders list where I've changed manage_edit-shop_order_columns
to woocommerce_my_account_my_orders_columns
hook like:
// 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>';
}
}
I want the content of this column to be the same, but I want the title to say "Download".
Updated: Here is a screenshot where I want the column to go:
There are many mistakes in your code… To display the customer order notes sent by admin in My account orders as a new column, use the following instead:
// 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>';
}
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
这篇关于在 WooCommerce 我的帐户订单列表中添加发送给客户的管理员订单备注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!