Get last order by user id on Woocommerce

$user_id = 1032; // The user ID

// Get the WC_Customer instance Object for the current user
$customer = new WC_Customer( $user_id );

// Get the last WC_Order Object instance from current customer
$last_order = $customer->get_last_order();

$order_id     = $last_order->get_id(); // Get the order id
$order_data   = $last_order->get_data(); // Get the order unprotected data in an array
$order_status = $last_order->get_status(); // Get the order status
    

Leave a Reply

Your email address will not be published. Required fields are marked *