Last active
March 5, 2026 09:37
-
-
Save xlplugins/9b3ed1d02659b8be7396e3963e99f902 to your computer and use it in GitHub Desktop.
refresh checkout on session expiry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * If update_order_review returns and woocommerce_cart_hash cookie is not found → refresh checkout once. | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| add_action( 'wp_footer', 'keep_wc_session_refresh_script', 20 ); | |
| function keep_wc_session_refresh_script() { | |
| if ( ! function_exists( 'is_checkout' ) || ! is_checkout() || is_wc_endpoint_url( 'order-received' ) ) { | |
| return; | |
| } | |
| ?> | |
| <script> | |
| (function($) { | |
| var done = 'wc_checkout_refresh_done'; | |
| $(document).ajaxComplete(function(e, xhr, s) { | |
| if ( sessionStorage.getItem(done) === '1' ) return; | |
| if ( ! s || ! s.url || s.url.indexOf('update_order_review') === -1 ) return; | |
| var m = document.cookie.match( /(?:^|; )woocommerce_cart_hash=([^;]*)/ ); | |
| if ( ! m || ! m[1] ) { | |
| sessionStorage.setItem(done, '1'); | |
| window.location.reload(); | |
| } | |
| }); | |
| })(jQuery); | |
| </script> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment