• Resolved nemovich

    (@nemovich)


    Hello,

    I’m trying to add some custom fields values to customer note, I came across a bit of code here and it works nicely but only for the first custom field delivery_date, I need to retrieve the values of multiple custom fields and put the in one customer note. I tired false at the end but it does not work.

    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 = get_post_meta( $order_id, 'delivery_date', 'time_slot_from', 'time_slot_to', true );
    
    	// Add the note
    	$order->add_order_note( $note );
    
    	// Save the data
    	$order->save();
    }

    any help is welcome, thank you

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

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello,
    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:

    1. WooCommerce Slack Community: https://woocommerce.com/community-slack/
    2. WooCommerce FB group: https://www.facebook.com/groups/advanced.woocommerce/
    Thread Starter nemovich

    (@nemovich)

    I got help from another samaritan, here’s the code :

    add_action( 'woocommerce_new_order', 'add_engraving_notes' );
    
    function add_engraving_notes( $order_id ) {
    
    //because I already have the ID from the hook I am using.
        $order = wc_get_order( $order_id );
    
    // The text for the note
        $delivery_date   = get_post_meta( $order_id, 'delivery_date', true );
        $time_slot_from  = get_post_meta( $order_id, 'time_slot_from', true );
        $time_slot_to    = get_post_meta( $order_id, 'time_slot_to', true );
    
        $note = "Deliver Date:$delivery_date Time Slot From: $time_slot_from Time Slot To: $time_slot_to";
    
    // Add the note
        $order->add_order_note( $note );
    
    // Save the data
        $order->save();
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding custom fields to customer note’ is closed to new replies.