In this article, We will show you how to solve WordPress WooCommerce error “Sorry, your session has expired. Return to homepage”. This is a terrible error that’s not easy to solve. You might need the help of an expert to solve this kind of error and it cost nearly $50 to $100. But here, we will show you the possible ways without any cost. Let’s just jump into it.
Table of Contents |
1. What Are The Factors That Raised This Error |
2. How To Check This Error |
3. How This Error Occurs |
4. Solution For “Sorry, Your session has expired. Return to homepage” Error |
An Ideal Place to Add Code in WordPress
Most Important: Add the following code to your child theme’s functions.php file. If you add custom code directly to your parent theme’s functions.php file then it will be wiped entirely when you update the theme.
If you are using a custom theme and if it doesn’t require any update then you can directly place the code into wp-content/themes/your-theme/function.php file.
Please also note that we have tested all codes in the GeneratePress child theme & Storefront child theme.
What Are The Factors That Raised This Error
- The first thing that raises this issue could be your installed theme. Even themes purchased from well-known websites like ThemeForest, ThemeFuse, WordPress theme store, or any other website that sells WordPress themes can generate this issue.
- Secondly, your installed plugins. Any plugins that concern with WooCommerce can raise this kind of issue.
- The third thing is the developed code. If you had written any code using any session related functions like
session_start()
,session_destroy()
,unset()
, etc. not in a proper way.
How To Check This Error
To see this error, add any product into the cart and follow all the processes including checkout.
After the successful payment, you will automatically be redirected to the owner’s store or you will be asked to go to the owner’s store. After clicking on that link, you will be taken to the store.
Then you will see the message like "Sorry, Your session has expired. Return to homepage".
You can also check that your cart will not be not empty but it should empty after the successful payment. Right? Let’s got ahead and see the next things.
How This Error Occurs
WooCommerce has it’s own Thank You
page, due to some conflict with Theme or Plugin, it won’t take you to the Thank You
page so we just need to force the WordPress to do that. Let’s do it.
Solution For “Sorry, Your session has expired. Return to homepage” Error
- The first thing you have to do is check whether your website has a
Thank You
page or not. If not, then please add a new page with the title “Thank You
“. - After that, you need to add below code into your function.php file to force the WordPress to go to the “Thank You” page after successful payment.
/* @ Redirect to the Thank You page after successful payment in WooCommerce */
if( !function_exists('sc_custom_redirect_after_purchase') ):
function sc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty($wp->query_vars['order-received']) ) :
$order_id = absint($wp->query_vars['order-received']);
$order_key = wc_clean($_GET['key']);
$th_page_url = 'https://www.example.com/thank-you';
$redirect = add_query_arg(
array(
'order' => $order_id,
'key' => $order_key,
), $th_page_url);
wp_safe_redirect($redirect);
exit;
endif;
}
add_action('template_redirect', 'sc_custom_redirect_after_purchase');
endif;
In order to make the above code snippet working, you need to replace your Thank You page URL on line no. 14.
That’s it. We hope this article helped you to solve “Sorry, your session has expired. Return to homepage” error in WooCommerce.
Additionally, read our guide:
- How to Create a Plugin in WordPress from Scratch
- WooCommerce: Disable Zoom, Lightbox, And Gallery Slider
- How to Disable Admin Bar in WordPress Without Plugin
- How to Rollback WordPress Plugin Update
- How To Send Custom Emails in WordPress
Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you in advance 🙂. Keep Smiling! Happy Coding!
Good write-up, I’m regular visitor of one’s website, maintain up the excellent operate, and It is going to be a regular visitor for a lengthy time.
Hey Karyl, Thank you for your kind word. This means a lot. Thank you 🙂
Pretty! This was an extremely wonderful post. Thanks for supplying this information. Dianna Avery Wessling
Thank you 🙂