12

I have a little problem when I try to display woocommerce customer order comments (not the notes, but the comments that a customer can add during the checkout process).

(I'm going to add just the relative lines for this problem, as other woocommerce data is correctly displayed so it shouldn't be a setup problem).

What I've tried so far is this:

$notes = $order->get_customer_order_notes(); //This line returns an Array[]

Inside that array, this is the field that I think I need, as it contains my order comment:

$notes
  0={stdClass} 38
    post_excerpt = "test"

and so what I did is trying to display this value like this:

echo "Order Notes: " . $notes->post_excerpt

but unfortunately the result is empty.

What am I doing wrong? Many thanks

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Nick
  • 13,493
  • 8
  • 51
  • 98

2 Answers2

21

I found a way to display the customer checkout comment, selecting $order->customer_message; and then setting this value as a variable.

ecairol
  • 6,233
  • 1
  • 27
  • 26
Nick
  • 13,493
  • 8
  • 51
  • 98
  • 2
    thanks!! this helped me to customize the output of the YITH WooCommerce PDF Invoice and Shipping List plugin template so as to accommodate the customer notes... As an FYI for any interested parties, for the purposes of that plugin, the appropriate adjusted variable value is $document->order->customer_message; – jadik Nov 16 '16 at 08:18
21

Update 2017 - 2018 | For Woocommerce 3+

Since Woocommerce 3 you can't access anymore properties From the WC_Order object. You need to use the WC_Order method get_customer_note() instead:

$customer_note = $order->get_customer_note();

Related:
Display order customer note in Woocommerce email notifications
Add order customer note to YITH Woocommerce PDF Invoice

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399