In case anyone else experiences timeout issues in the future and customers aren’t getting directed to any kind of thank you message, here is something you can try to get it working. It involves using a child theme (or a custom theme if you’ve built one from scratch) which I won’t cover here, there’s plenty of documentation on creating a child theme out there.
1. Create a thank you page, like you would any other page in WordPress
2. In your theme’s functions.php file, add WooCommerce support:
/**
* Declare WooCommerce Support
*
*/
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
3. In your theme’s functions.php file, add the redirect code and alter the URL to direct to your new thank you page:
/**
* Custom redirect for order confirmation
*
*/
function my_custom_redirect( $order_id ){
$order = wc_get_order( $order_id );
$url = 'https://yoursite.com/thank-you';
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}
add_action( 'woocommerce_thankyou', 'my_custom_redirect');
4. Save the functions.php file and upload to your child themes root folder. Or do the code edits directly in WordPress theme editor (Appearance -> Theme Editor -> Theme Files -> functions.php)
5. (OPTIONAL) Going back to the thank you page you created in the first step, you can add the following short code in addition to whatever thank you message you have, in order to display the order details to the customer: [confirmation_order_details]
That’s it. This is pretty much the only solution I could find for intermittent timeout issues that kept happening to me. Hope it might help someone else in the future.