【发布时间】:2022-05-09 17:40:05
【问题描述】:
我们在私人笔记中添加我们自己的生产编号,如果我们可以在新列下的订单列表中显示这些私人笔记,那将非常方便,在整个互联网上搜索但没有一个代码有效。
非常感谢!
【问题讨论】:
标签: wordpress woocommerce
我们在私人笔记中添加我们自己的生产编号,如果我们可以在新列下的订单列表中显示这些私人笔记,那将非常方便,在整个互联网上搜索但没有一个代码有效。
非常感谢!
【问题讨论】:
标签: wordpress woocommerce
尝试在function.php文件中添加这段代码sn-p:
add_action( 'wpo_wcol_custom_row', 'wpo_wcol_order_notes', 10, 1 );
function wpo_wcol_order_notes ( $order_id ) {
$notes = wc_get_order_notes( array(
'order_id' => $order_id,
'type' => 'customer', // use 'internal' for admin and system notes, empty for all
) );
if ( $notes ) {
foreach( $notes as $key => $note ) {
// system notes can be identified by $note->added_by == 'system'
printf( '<div class="note_content">%s</div>', wpautop( wptexturize( wp_kses_post( make_clickable( $note->content ) ) ) ) );
}
}
}
【讨论】:
wpo_wcol_order_notes 是插件WooCommerce Print Order List 特有的,如果没有它,它将无法工作。
这里有在 Woocommerce 订单列表中显示私人笔记的代码:
// WooCommerce - Add order notes column to orders list
// Code goes in functions.php for your child theme
// not tested in a PHP snippet plugin
// Add column "Order Notes" on the orders page
add_filter( 'manage_edit-shop_order_columns', 'add_order_notes_column' );
function add_order_notes_column( $columns ) {
$new_columns = ( is_array( $columns ) ) ? $columns : array();
$new_columns['order_notes'] = 'Order Notes';
return $new_columns;
}
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 );
}
// Add order notes to the "Order Notes" column
add_action( 'manage_shop_order_posts_custom_column', 'add_order_notes_content' );
function add_order_notes_content( $column ) {
if( $column != 'order_notes' ) return;
global $post, $the_order;
if( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
$args = array();
$args['order_id'] = $the_order->get_id();
$args['order_by'] = 'date_created';
$args['order'] = 'ASC';
$notes = wc_get_order_notes( $args );
if( $notes ) {
print '<ul>';
foreach( $notes as $note ) {
if( $note->customer_note ) {
print '<li class="order_customer_note">';
} else {
print '<li class="order_private_note">';
}
$date = date( 'd/m/y H:i', strtotime( $note->date_created ) );
print $date.' by '.$note->added_by.'<br>'.$note->content.'</li>';
}
print '</ul>';
}
} // end function
只需将代码复制并粘贴到您的 functions.php 文件中即可。
致谢:https://wordpress.org/support/topic/display-private-note-column-on-woocommerce-order-page/
【讨论】: