在 WooCommerce 我的帐户订单列表中添加发送给客户的管理员订单备注

编辑咖啡馆

基于WooCommerce 管理订单列表自定义列,订单注释发送到客户答案代码,我尝试添加以下代码以在 WooCommerce 我的帐户订单列表中创建一个新列,但我已更改manage_edit-shop_order_columnswoocommerce_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>';
    }
}

我希望此列的内容相同,但我希望标题为“下载”。

更新:这是我希望列去的屏幕截图:

列的屏幕截图

LoicTheAztec

您的代码中有很多错误……要将管理员发送的客户订单备注显示在我的帐户订单中作为新列,请改用以下内容:

// 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 文件中。测试和工作。

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

WooCommerce将电子邮件通知发送给管理员以获取特定的订单状态

在Woocommerce管理员订单列表“订单”现有列中添加自定义字段

在WooCommerce管理员订单列表中以批量操作添加自定义取消订单状态

在Woocommerce管理员订单列表中显示带有作者和日期的订单注释

在WooCommerce管理员订单列表中显示每个订单的变体名称

在Woocommerce中以BCC身份发送给管理员的新帐户电子邮件通知

在Woocommerce管理员订单列表自定义列中显示结帐字段值

在Woocommerce管理员订单列表自定义列中显示用户名

仅在WooCommerce管理员订单列表自定义列中显示特定订单状态的数据

Woocommerce 3.3管理员订单列表中的自定义订单状态背景按钮颜色

将自定义订单状态添加到WooCommerce管理员订单列表中的过滤器菜单

如何在WooCommerce管理员订单列表中的买家姓名之后添加第一笔订单消息

从订单预览中删除WooCommerce管理员订单操作

在客户订单历史记录中显示最后的WooCommerce管理员订单记录

在Woocommerce管理员“编辑订单”页面中显示客户取消的订单数

在优惠券设置中添加一个字段,并在Woocommerce管理员订单列表上显示该值

在Woocommerce管理员订单列表上处理多个自定义批量操作

更改Woocommerce管理员订单列表的时间和日期格式

在Woocommerce管理员订单编辑页面中以编程方式添加自定义订单注释

在管理员-> Woocommerce->订单的“订单”列表中显示运输邮政编码。

在WooCommerce中将列添加到管理订单列表

在woocommerce的管理订单列表顶部添加按钮

在 WooCommerce 管理订单列表的自定义列中显示私人和客户管理注释

在新列中将客户电子邮件添加到Woocommerce上的管理订单列表

在“订单”列中将客户电子邮件和电话添加到Woocommerce上的管理订单列表

在Woocommerce中每页自定义我的帐户订单列表帖子

Woocommerce中我的帐户订单列表上的有条件取消按钮

根据订单状态隐藏 WooCommerce 管理订单列表中的订单(表格行)

woocommerce-将订单电子邮件通知发送给客户批准