Reputation: 736
Is it possible to get only latest product of woocommerce order? I know that is possible for notes as example:
// Get last order note
$latest_notes = wc_get_order_notes( array(
'order_id' => $order->get_id(),
'limit' => 1,
'orderby' => 'date_created_gmt',
) );
$latest_note = current( $latest_notes );
Can I make something similar for products inside order?
Upvotes: 2
Views: 700
Reputation: 253814
To get the latest product from a WC_Order
Object, you can use end()
function from order items array, like:
$order_items = $order->get_items(); // Get order items
$last_item = end($order_items); // Latest WC_Order_Item_Product Object instance
$product = $last_item->get_product(); // Latest WC_Product Object instance
Related: Get Order items and WC_Order_Item_Product in WooCommerce 3
Upvotes: 3