dongyan2445 2019-04-23 14:17
浏览 95
已采纳

在客户订单历史记录中显示最后一个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.

Tracking

Customer Order History

https://example.com/my-account/view-order/135/

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.

Ideal outcome:

Ideal

  • 写回答

1条回答 默认 最新

  • duanhongxian6982 2019-04-23 16:11
    关注

    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;
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题