• Home
  • WordPress
  • WooCommerce redirect loop when cart and checkout on the same page

WooCommerce redirect loop when cart and checkout on the same page

I just launched a website with a single page checkout process which works fine if there’s at least one product in the cart.

The problem is if cart an checkout is on the same page and a user tries to access this page without any products in his cart, woocommerce redirects to the cart again and again.

To solve this problem I found this solution:
https://wordpress.org/support/topic/cart-checkout-on-same-page-redirect-loop-problem/

But when an order is finished the cart is empty again so this script redirects again to the home page instead of the order confirmation page.

I improved the script and want to share it with you:

 

3 thoughts on “WooCommerce redirect loop when cart and checkout on the same page”

  1. Hi,

    Thanks for writing up your solution, it’s always reassuring to find others have hit the same problem.

    Under Checkout Pages I’ve set both ‘Basket Page’ and ‘Checkout Page’ to /checkout/ and added the cart and checkout shortcodes to the checkout page. This works brilliantly but runs into the issue described above.

    I’ve added your PHP function to my child themes functions.php file but without any success, I still get a redirect loop. Equally clearing the basket via AJAX in the checkout page results in the page eventually crashing.

    Very frustrating!

    Dan

    1. Hi Dan,
      Sorry I don’t have a brilliant idea for you, it took me hours to solve this for myselfes.
      In your situation I’d try to remove the IF-clause to see wether the function has any effect at all. If so then improve the conditions, if not I’d have a look at the theme. Maybe there’s another ‘template_redirect’ hook.

Leave a Reply

Your email address will not be published. Required fields are marked *