WooCommerce thank you page not showing customer details like the Billing Address and Shipping Address? It may be because the user is not logged in and checking out as a guest! By default, WooCommerce does not show customer details on the thank you page (order received endpoint of the checkout) if they checkout as a guest. The customer details being the Billing Address, including the billing email and billing phone, and Shipping Address. After tearing my hair out thinking there was a conflict somewhere, it turns out this is native behaviour of WooCommerce. The customer details are not shown on the order received page for security purposes. The customer details is not protected in the same way for logged in, registered users. This snippet will run on the thank you page and tests whether the user is logged in or not. If they are, nothing happens because when a user is logged in, these customer details are shown. However, if the code picks up that the user is not logged in, it will force the thank you page to output the order-details-customer.php template which is the customer details (Billing Address, including the billing email and billing phone, and Shipping Address (if enabled and entered)).
/**
* Snippet Name: WooCommerce Show Customer Addresses On Thank You Page For Guest Checkouts
* Snippet Author: ecommercehints.com
*/
add_action( 'woocommerce_thankyou', 'ecommercehints_show_customer_addresses_on_thank_you_if_guest', 10, 1 );
function ecommercehints_show_customer_addresses_on_thank_you_if_guest($order_id) {
if (!$order_id || is_user_logged_in()) { // Do nothing if there is no order or the customer is logged in
return;
}
$order = wc_get_order($order_id);
wc_get_template( 'order/order-details-customer.php', array('order' => $order )); // Show the addresses
}