I have the following code:
$customer_orders = get_posts(array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => 'shop_order',
'post_status' => array_keys(wc_get_order_statuses()),
)
);
$last_post_date;
$loop = new WP_Query($customer_orders);
foreach ($customer_orders as $orderItem)
{
$order = wc_get_order($orderItem->ID);
$last_post_date = $orderItem->post_date;
}
echo $last_post_date;
I want to print the $last_post_date
, which is created from an order made by a customer.
So if a customer makes 2 order I will get an array [0] and [1].
But at the moment $last_post_date
is not printing the post_date
from array[0]
.
It is always printing the post date from the order that was made first, not last,
Thanks for the help!