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

Display last WooCommerce admin order note in customers order history(在客户订单历史记录中显示最后的 WooCommerce 管理员订单备注)
本文介绍了在客户订单历史记录中显示最后的 WooCommerce 管理员订单备注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我希望在客户的订单历史记录中显示最后一个订单说明,目前只能通过 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 管理员订单备注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)