Woocommerce – get_items() returns empty array


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);

add_action('woocommerce_new_order', 'add_engraving_notes');
, Todd Coffee 3 years 2020-07-03T09:10:51-05:00 0 Answers 78 views 0

Leave an answer