I am trying to display the data for the last customer order on a custom page using a shortcode. With the help of resources from this platform, I have managed so far to display order ID, subtotal, and total. Displaying the order title (or the title of the product/item in the order) has taken me hours. I have tried ->get_name as you can see in the commented section, but failed. I tried so many, including post_title but failed. Your help will be appretiated.
if ( is_user_logged_in() ){
$customer_user_id = get_current_user_id();
$last_order = wc_get_customer_last_order( $customer_user_id);
if ( !empty( $last_order ) ) {
$order_id = $last_order->get_id();
$withdrawqr_subtotal =$last_order->get_subtotal();
$withdrawqr_total = $last_order->get_total();
$withdrawqr_fee = $withdrawqr_total-$withdrawqr_subtotal;
//$withdrawqr_agent =$last_order->get_name();
$withdrawqr_id = $last_order->get_id();
$withdrawqr_code =str_shuffle("DANTE");
$withdrawqr_date = $last_order->get_date_created()->format('Y-m-d H:i:s');
$retun_this_withdraw_text = "
<html>
<head>
<title>Summary</title>
</head>
<body>
<p>Confirmed <strong>".$withdrawqr_code."".$withdrawqr_id."</strong>. You have withdrawn<strong> KES ".$withdrawqr_subtotal." </strong>from <strong>".$withdrawqr_agent." </strong>on <strong>".$withdrawqr_date. "</strong>. You have been charged <strong>KES ".$withdrawqr_fee."</strong> withdrawal fee. Thank you</p>
</body>
</html>
";
return $retun_this_withdraw_text;
}
}
}
add_shortcode('withdrawqr_get_last_order_details','withdrawqr_get_last_order_details');