## Woocommerce – get_items() returns empty array

Question

I am trying to write a function that will allow me to add product meta tags as additional order notes. Unfortunately, nothing works. After a few hours I decided to bring the function to the simplest form to see what does not work.

Each time I place an order for two products. I check my order and see two products. My function should create a note with the text “test 2” but creates a “test 0”.
And I have no idea why.

function add_engraving_notes($order_id) {$order = wc_get_order($order_id);$note = 'Test';

$items =$order->get_items();
$note .= count($items);

$order->add_order_note($note);

\$order->save();
}