For my WooCommerce store, I am writing a plugin that when an item is placed, creates a PDF with a picking list and a delivery label. It all works, except I can not seem to get the items in the order, I can get the order status and other parts of the order just not the items.
// Getting an instance of the WC_Order object from a defined ORDER ID
$order = wc_get_order( $order_id );
// Iterating through each "line" items in the order
foreach ($order->get_items() as $item_id => $item ) {
// Get an instance of corresponding the WC_Product object
$product = $item->get_product();
$product_name = $item->get_name(); // Get the item name (product name)
$item_quantity = $item->get_quantity(); // Get the item quantity
// Add item name and quantity to the PDF (Picking List)
$pdf->Cell(0, 10, "Product name: '.$product_name.' | Quantity: '.$item_quantity.'", 0, 1);
}
I have tried pushing the items to the debugging log, but it isn't showing the details of the items, and so I think it is the way I am getting the items, rather than an error with writing them to the PDF.