You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce Booking调用get_customer_note()无法获取客户备注如何解决

问题根因

WooCommerce中WC_Order类提供的get_customer_note()方法本身返回的就是字符串格式的客户备注内容,并非WP_Post对象,你代码中将返回值当作对象调用post_excerpt属性的逻辑是错误的,因此无法拿到对应内容。

修复后的代码
<p class="form-field form-field-wide">
    <label for="excerpt"><?php _e( 'Customer provided note', 'woocommerce-bookings' ); ?>:</label>
    <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?>">
    <?php 
    // 先判断order对象是否有效,避免报错
    if ( is_a( $order, 'WC_Order' ) ) {
        $customer_note = $order->get_customer_note();
        echo wp_kses_post( $customer_note );
    }
    ?></textarea>
</p>
核心修改点
  • 删除了原代码中多余的->post_excerpt属性调用,直接输出get_customer_note()返回的字符串内容
  • 新增了订单对象有效性校验逻辑,避免订单对象未初始化时抛出PHP报错

内容的提问来源于stack exchange,提问作者Hamza Butt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 00:36:05