Notification of Customer Notes in Woocommerce

I am trying to setup a custom notification for any Woocommerce order that have a Customer Note added during checkout. I have the following but cannot get it to trigger. Can a second pair of eyes see where I am going wrong?

function woo_email_customer_message( $order_id ) {
        global $woocommerce;
        $order = new WC_Order( $order_id );
        $order_customer_message = $order->customer_message;

        if( $order->customer_message() ) {

            $to = 'contact@example.com';
	        $subject = 'New Order Completed with Notes!!! :)';
	        $headers = 'From: My Name ' . "\r\n";

	        $message = 'A new order has been completed.\n';
	        $message .= 'Order ID: '.$order_id.'\n';
	        $message .= $order->customer_message;
	        @wp_mail( $to, $subject, $message, $headers );
        }
}
add_action( 'woocommerce_thankyou', 'woo_email_customer_message' );
    Vaughan

    Hi Neil,

    Hope you're well?

    Can you try the following:

    function woo_email_customer_message( $order_id ) {
            $order = wc_get_order( $order_id );
    
            if( $order->customer_message() ) {
    
                $to = 'contact@example.com';
    	        $subject = 'New Order Completed with Notes!!! :)';
    	        $headers = 'From: My Name ' . "\r\n";
    
    	        $message = 'A new order has been completed.\n';
    	        $message .= 'Order ID: '.$order_id.'\n';
    	        $message .= $order->customer_message;
    	        @wp_mail( $to, $subject, $message, $headers );
            }
    }
    add_action( 'woocommerce_thankyou', 'woo_email_customer_message' );

    Hope this helps

      Neil Batchelor
      [21-Mar-2017 16:09:22 UTC] PHP Fatal error:  Uncaught Error: Call to undefined method WC_Order::customer_message() in /home/webdesign/public_html/wp-content/themes/encode-base-theme/functions.php:172
      Stack trace:
      #0 /home/webdesign/public_html/wp-includes/class-wp-hook.php(298): woo_email_customer_message(2045)
      #1 /home/webdesign/public_html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
      #2 /home/webdesign/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
      #3 /home/webdesign/public_html/wp-content/plugins/woocommerce/templates/checkout/thankyou.php(65): do_action('woocommerce_tha...', 2045)
      #4 /home/webdesign/public_html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(203): include('/home/webdesign...')
      #5 /home/webdesign/public_html/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(212): wc_get_template('checkout/thanky...', Array)
      #6 /home/webdesign/public_html/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(59): WC_Shortcode_Chec in /home/webdesign/public_html/wp-content/themes/encode-base-theme/functions.php on line 172
    Vaughan

    Ok,

    Let's go back to this:

    But add a var_dump() into it.

    function woo_email_customer_message( $order_id ) {
            $order = new WC_Order( $order_id );
            var_dump($order);
            if( $order->customer_message() ) {
    
                $to = 'contact@example.com';
    	        $subject = 'New Order Completed with Notes!!! :)';
    	        $headers = 'From: My Name ' . "\r\n";
    
    	        $message = 'A new order has been completed.\n';
    	        $message .= 'Order ID: '.$order_id.'\n';
    	        $message .= $order->customer_message;
    	        @wp_mail( $to, $subject, $message, $headers );
            }
    }
    add_action( 'woocommerce_thankyou', 'woo_email_customer_message' );

    See what the dump says.

    Thanks

    Neil Batchelor

    Vaughan Apologies long day in the office. Here is the var_dump:

    object(WC_Order)#8444 (14) { ["order_type"]=> string(6) "simple" ["id"]=> int(2051) ["post"]=> object(WP_Post)#8447 (24) { ["ID"]=> int(2051) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2017-03-21 17:17:48" ["post_date_gmt"]=> string(19) "2017-03-21 17:17:48" ["post_content"]=> string(0) "" ["post_title"]=> string(39) "Order – March 21, 2017 @ 05:17 PM" ["post_excerpt"]=> string(11) "Order Notes" ["post_status"]=> string(13) "wc-processing" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(19) "order_58d1603ce2ec6" ["post_name"]=> string(25) "order-mar-21-2017-0517-pm" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2017-03-21 17:17:48" ["post_modified_gmt"]=> string(19) "2017-03-21 17:17:48" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(68) "https://web-design-stratford.co.uk/?post_type=shop_order&p=2051" ["menu_order"]=> int(0) ["post_type"]=> string(10) "shop_order" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "1" ["filter"]=> string(3) "raw" } ["order_date"]=> string(19) "2017-03-21 17:17:48" ["modified_date"]=> string(19) "2017-03-21 17:17:48" ["customer_message"]=> string(11) "Order Notes" ["customer_note"]=> string(11) "Order Notes" ["post_status"]=> string(13) "wc-processing" ["prices_include_tax"]=> bool(false) ["tax_display_cart"]=> string(4) "excl" ["display_totals_ex_tax"]=> bool(true) ["display_cart_ex_tax"]=> bool(true) ["formatted_billing_address":protected]=> string(0) "" ["formatted_shipping_address":protected]=> string(0) "" }

    Neil Batchelor

    Vaughan Got it!

    function woo_email_customer_message( $order_id ) {
            $order = new WC_Order( $order_id );
            var_dump($order);
            if( $order->customer_note != '' ) {
    
                $to = 'contact@example.com';
                    $subject = 'New Order Completed with Notes!!! :)';
    
                    $message = 'A new order has been completed.';
                    $message .= 'Order ID: '.$order_id.'';
                    $message .= $order->customer_message;
                    @wp_mail( $to, $subject, $message, $headers );
            }
    }
    add_action( 'woocommerce_thankyou', 'woo_email_customer_message' );

    Thanks for your help with this.