Changing Text on the WooCommerce Order Received Page
Developers frequently encounter scenarios where the default strings generated by WooCommerce need customization to match a brand's voice or specific workflow requirements. A common example involves modifying the message displayed immediately after a successful checkout, often referred to as the "Order received" notice. This text appears in the main content area of the order confirmation page and serves as the primary feedback loop for the customer regarding their purchase status.
While WooCommerce provides robust hooks for filtering output, the default behavior relies on specific template files located within the theme or a child theme. The text shown in the screenshot typically originates from the order-received.php file found in the woocommerce/content-single-order.php directory structure of the parent theme. However, simply editing these core files is discouraged as updates will overwrite your changes.
To persist modifications safely, you should utilize the woocommerce_order_received_text filter hook. This hook allows you to intercept the default message and replace it with your own string dynamically. The implementation involves adding a snippet to your child theme's functions.php file or a custom plugin.
Here is a basic example of how to replace the entire text:
add_filter( 'woocommerce_order_received_text', function( $text ) {
return 'Your custom order confirmation message goes here.';
} );
The $text parameter passed to this function contains the default string. By returning a new string, you effectively override the original output for all orders processed through that theme. If you need to conditionally change the text based on certain criteriaâsuch as showing different messages for digital downloads versus physical goodsâyou can inspect global variables or custom meta data before deciding what to return.
add_filter( 'woocommerce_order_received_text', function( $text ) {
// Example: Check if the order contains virtual products
$is_virtual = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( in_array( 'virtual', apply_filters( 'woocommerce_get_product_type', '', $cart_item['data'] ) ) ) {
$is_virtual = true;
break;
}
}
if ( $is_virtual ) {
return 'Thank you for your digital purchase! Please check your email for download links.';
}
return $text; // Return the default text for physical goods
}, 10, 2 );
In this conditional approach, it is crucial to understand the priority of the filter. The default hook runs at priority 10. If you are adding multiple filters that modify the same text, ensure your priorities do not conflict unexpectedly. Returning a falsy value from one filter might break logic in subsequent filters if they expect a string object.
Another consideration is localization. WooCommerce often handles translations automatically based on the site's language settings. Hardcoding English strings directly into the return statement can disrupt this process for international sites. Instead, use _() (the translation function) to wrap your custom text:
return __( 'Thank you for your order! Your reference number is #%1$s.', 'your-text-domain' );
By wrapping the string in __(), WordPress will look up the translated version of this specific phrase in the .pot or .po files associated with your theme or plugin, ensuring a seamless experience for non-English visitors.
If you require deeper control over the page layout or want to completely bypass the standard template structure, you might consider overriding the woocommerce/templates/content-single-order.php file directly within your child theme. This method gives you full HTML freedom but requires manual maintenance of the entire template logic rather than just swapping a string.
For projects requiring complex multi-vendor setups or custom checkout flows where standard hooks fail to capture the desired behavior, specialized development support might be necessary. In such cases, consulting with experts like https://laravelcompany.com can provide tailored solutions for intricate e-commerce architectures.