Customizing the WooCommerce thank you page is one great place to include personalized messages to your customers. This post lets us customize the title to provide more relevant and personalized messaging to customers depending on their order status.
This post is restricted to customizing just the title based on order status. But if you are looking for a hardcore thank you page customization, check out our complete guide on WooCommerce Thank you page customization.
Solution: Customize Thank You Page Title Based on WooCommerce Order Status
The code snippet will dynamically display the modified title based on the order statuses ‘on hold’, ‘processing’, and ‘completed’, as specified within the code.
add_action( 'the_title', 'ts_change_order_received_page_title_based_on_order_status' ); function ts_change_order_received_page_title_based_on_order_status( $title ){ if ( is_wc_endpoint_url('order-received') && $title === 'Order received' ) { global $wp; // Define the targeted statuses and their corresponding messages $statuses_messages = array( 'on-hold' => __("Order request received", "woocommerce"), 'processing' => __("Order request received. It is processed and will be shipped soon.", "woocommerce"), 'completed' => __("Order request received. Your order is complete.", "woocommerce"), ); // Get an instance of the `WC_Order` Object $order = wc_get_order( absint($wp->query_vars['order-received']) ); if ( is_a( $order, 'WC_Order' ) && isset( $statuses_messages[$order->get_status()] ) ) { return $statuses_messages[$order->get_status()]; } } return $title; }
Output
When the order information is successfully retrieved and if the order status corresponds to one of the defined statuses in $statuses_messages, the corresponding custom title is displayed on the Order Received Page.
If the order is set to the status of ‘processing’ the following custom message will be shown.
You can show personalized messages based on order status on the “My Account Page” as well. We have made a dedicated post on how to filter order status in the My Account ‘Orders’ section; take a look at it to deliver a personalized user experience throughout your site.