• Hi, I want to add a custom note in view order page. This text will be automatically placed when an order is placed. Customer can view this text under Customer Note section.

    I have tried using this code but of no result.

    add_action( ‘woocommerce_new_order’, ‘add_engraving_notes’, 1, 1 );

    function add_engraving_notes( $order_id ) {
    //note this line is different
    //because I already have the ID from the hook I am using.
    $order = new WC_Order( $order_id );

    // The text for the note
    $note = __(“Custom Order Note Here”);

    // Add the note
    $order->add_order_note( $note );

    // Save the data
    $order->save();
    }

    Kindly help

Viewing 10 replies - 1 through 10 (of 10 total)
  • Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello @indrabhusanroy
    The code you use is correct, but use wc_get_order instead of WC_Order().

    Also, it might not work depending on where you added the code. Is it in functions.php?

    Thread Starter indrabhusanroy

    (@indrabhusanroy)

    Hi, I added this code (php snippet) using woody snippets plugin but still does not works. Here is the code—

    add_action( ‘woocommerce_new_order’, ‘add_engraving_notes’, 1, 1 );

    function add_engraving_notes( $order_id ) {
    //note this line is different
    //because I already have the ID from the hook I am using.
    $order = new wc_get_order( $order_id );

    // The text for the note
    $note = ‘No special message yet’;

    // Add the note
    $order->add_order_note( $note );

    // Save the data
    $order->save();
    }

    Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    @indrabhusanroy I used this code and it works:

    add_action( 'woocommerce_new_order', 'add_engraving_notes' );
    function add_engraving_notes( $order_id ) {
    	//note this line is different
    	//because I already have the ID from the hook I am using.
    	$order = wc_get_order( $order_id );
    
    	// The text for the note
    	$note = 'No special message yet';
    
    	// Add the note
    	$order->add_order_note( $note );
    
    	// Save the data
    	$order->save();
    }
    Thread Starter indrabhusanroy

    (@indrabhusanroy)

    Yes it works but it shows only in admin dashboard under “order notes”. I want to show this custom text automatically to my customers when they order, on their order page under customer notes section.

    In edit order page there is a place to add customer note. Here admin can send a note to customer. Customer can view it under Customer Note.

    Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    For that you need to pass a second parameter to the method add_order_note.

    Change this line

    $order->add_order_note( $note );

    to

    $order->add_order_note( $note, true );

    Thread Starter indrabhusanroy

    (@indrabhusanroy)

    Even after doing this nothing shows up in customer note section

    Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Is the note showing in blue on the edit order screen?

    Like this: https://d.wedj.at/c3lXc4

    If yes, then the note is added properly and it should show in the View order for the custoemr. If it does not, I’d try switching to a different theme to confirm if it works then, like Storefront or TwentyNineteen.

    Thread Starter indrabhusanroy

    (@indrabhusanroy)

    The note appears under order note section with purple background.

    Theme is ok, I have checked. It’s probably a problem with WOOCOMMERCE ORDER TRACKER Plugin which I’m using. When I’m sending a order note manually it is going to the customer, but automattic sending of order note is not happening.

    Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    If they appear as purple it means that they are private notes. They must appear as blue to show for the customer.

    The second parameter does that as per this document: https://docs.woocommerce.com/wc-apidocs/source-class-WC_Order.html#1624-1680

    Thread Starter indrabhusanroy

    (@indrabhusanroy)

    So what to change or edit to make it happen.

    I also tried this code on another site using the same theme but without the woocommerce tracker plugin, there it works fine and order note appears in blue. But in my site it appears in purple.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom order note in view order page’ is closed to new replies.