How to Change Thank You Page Message in WooCommerce
Explanation
If you're looking to add a personal touch to the "Thank You" page in WooCommerce, this snippet is your go-to solution. It allows you to customize the message that customers see after completing a purchase.
Here's what it does:
- It hooks into the WooCommerce system right after an order is placed, specifically on the "Thank You" page.
- The function checks if the order ID is valid to ensure everything runs smoothly.
- It retrieves the order details using the order ID, making sure the order exists.
- Then, it crafts a custom message that includes the order number, thanking the customer for their purchase.
- Finally, it displays this personalized message on the page.
Note: You can modify the $custom_message
variable to include any text or information you want to share with your customers. Just make sure to keep it friendly and engaging!
Code
<?php
// Hook into the WooCommerce 'thank you' page
add_action( 'woocommerce_thankyou', 'wp_dudecom_custom_thank_you_message', 20 );
function wp_dudecom_custom_thank_you_message( $order_id ) {
// Ensure the order ID is valid
if ( ! $order_id ) {
return;
}
// Get the order object
$order = wc_get_order( $order_id );
// Check if the order is valid
if ( ! $order ) {
return;
}
// Customize the thank you message
$custom_message = 'Thank you for your purchase! Your order number is ' . $order->get_order_number() . '. We appreciate your business and hope you enjoy your purchase.';
// Output the custom message
echo '<p>' . esc_html( $custom_message ) . '</p>';
}
?>
Instructions
File Location: Add the following code to your theme's functions.php
file or in a custom plugin file if you prefer to keep theme updates separate from custom code.
Prerequisites:
- Ensure WooCommerce is installed and activated on your WordPress site.
Implementation Steps:
- Access your WordPress dashboard.
- Navigate to Appearance > Theme Editor if you are adding the code to
functions.php
. Alternatively, use an FTP client or a file manager to access your WordPress files directly. - Locate and open the
functions.php
file of your active theme. If using a custom plugin, open the plugin file where you want to add the code. - Copy the provided code snippet and paste it at the end of the
functions.php
file or your custom plugin file. - Save the changes to the file.
- Test the implementation by placing a test order on your WooCommerce store to ensure the custom message appears on the "Thank You" page.
Note: You can modify the $custom_message
variable within the code to personalize the message further to suit your brand's tone and style.
If you need assistance with this implementation or require more advanced functionality, consider reaching out to wp-dude.com for expert WordPress support.