Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Customer order comments (customer note) in Woocommerce

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

like image 575
Nick Avatar asked Nov 26 '14 08:11

Nick


People also ask

How do I get order notes in WooCommerce?

The first way that you can get order notes in WooCommerce is by using the “Order Notes” field in the checkout process. This field is located on the checkout page, and it allows you to add a note to each order.

What are WooCommerce order notes?

WPC Order Notes for WooCommerce is an easy tool for store owners to manage all order notes. It offers a quick preview of added notes in each order from the popup. It lists all the notes with paging and provides the search function for finding the needed detail quickly.

How do I hide the order of notes in WooCommerce?

To hide the order of notes in WooCommerce, you first need to log into your WordPress dashboard. From there, go to WooCommerce > Settings > Advanced. Once you're on the Advanced settings page, find the checkbox that says “Hide all order notes”. Check this box and then save your changes.


2 Answers

Ok, after some time spent on trying, I finally find out that the right way to display the customer checkout comment is selecting $order->customer_message; and set this value as variable.

like image 59
Nick Avatar answered Oct 17 '22 19:10

Nick


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

like image 35
LoicTheAztec Avatar answered Oct 17 '22 18:10

LoicTheAztec