I am using "How can I get the latest order id in Woocommerce" answer code that returns last order with a custom function get_last_order_id()
.
Here is my code attempt where I get order items:
<?php
$latest_order_id = get_last_order_id(); // Last order ID
$order = wc_get_order( $latest_order_id ); // Get an instance of the WC_Order object
$order_details = $order->get_data(); // Get the order data in an array
$order_status = esc_html( wc_get_order_status_name( $order->get_status() ) );
$order_items = $order_details['line_items'];
?>
Then I use this in this code:
<div class="row last-order">
<div class="col-md-7">
<ul>
<?php
foreach ($order_items as $product_name) { ?>
<li><?php echo $product_name['name']; ?></li>
<?php
}
?>
</ul>
</div>
<div class="col-md-4 order-status-box">
<h6 class="status"><?php echo $order_status; ?></h6>
<i class="fas fa-chevron-down icon"></i>
</div>
</div>
I would like to get the last order for the current customer. How can I change the custom function get_last_order_id()
to get the last order for the current customer?
I would like to receive the contents of my cart in addition to the latest order from the current user.