In WooCommerce, for logged in users the Thankyou (order-received) page does show the customer details like the name, address and e-mail, but nothing when customers are not registered.
How can I ensure that non registered users can see their details on the Thankyou (order-received) page when the payment is successfully finished, just like registered users?
Why the customer details doesn't show up on the Thankyou (order-received) page for non registered users?
You can change this behavior for non logged users with the following code:
add_action( 'woocommerce_thankyou', 'adding_customers_details_to_thankyou', 10, 1 );
function adding_customers_details_to_thankyou( $order_id ) {
// Only for non logged in users
if ( ! $order_id || is_user_logged_in() ) return;
$order = wc_get_order($order_id); // Get an instance of the WC_Order object
wc_get_template( 'order/order-details-customer.php', array('order' => $order ));
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.
May be the fact that customer info doesn't show up is for security reasons, as this info is not really protected the same way than for logged in users (registered users).