I am trying to write order line items from Woocommerce (in Wordpress) to a file and I don't know how to get that data.
Here is my hook and function for it:
add_action( 'woocommerce_new_order', 'helios_export', 1, 1 );
function helios_export( $order_id ) {
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
$line_items = $order->get_items();
$fp = fopen('order.txt', 'w');
fwrite($fp, json_encode($line_items, JSON_PRETTY_PRINT));
fclose($fp);
}
This code doesn't write anything inside the file and I get no errors.
The $order_data object contains all the order data, but the line items show up empty there too:
line_items: []
So how do I get the items from the order?
Thank you!