Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom order note programmatically in Woocommerce admin order edit pages

In woocommerce I am trying to add a custom order note in the admin order edit pages through php (so programmatically). I haven't find the way yet.

Any help will be appreciated.

WooCommerce order note in the order admin page

like image 524
Max Avatar asked Feb 07 '18 15:02

Max


People also ask

How do I create an order programmatically in WooCommerce?

php $order->add_product( get_product( '129' ), 1 ); // This is an existing SIMPLE product $order->set_address( $address, 'billing' ); // $order->calculate_totals(); $order->update_status("Completed", 'Imported order', TRUE); } add_action( 'init', 'create_vip_order' );


1 Answers

From a dynamic Order Id you can use WC_Order add_order_note() method this way:

// If you don't have the WC_Order object (from a dynamic $order_id)
$order = wc_get_order(  $order_id );

// The text for the note
$note = __("This is my note's text…");

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

Tested and works.

like image 98
LoicTheAztec Avatar answered Oct 23 '22 11:10

LoicTheAztec