Support » Plugin: WooCommerce » Redirect Loop occurs when calling for Cart page if cart is empty

Viewing 11 replies - 1 through 11 (of 11 total)
  • Redirects come from .htaccess in the WordPress root, so temporarily rename this file. If your page works, go to Admin page > Settings > Permalinks and “Save changes”. WordPress will create a new .htaccess. If it doesn’t work, you’ve still got the old .htaccess. I have assumed you are on an Apache server. Windows servers will be different.

    Thanks for the response. I followed your instructions. I renamed the old .htaccess file, clicked “Save” under permalinks, and WP created a new .htaccess file …. which looks like this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    However, this did not solve the problem. The symptoms are the exact same as before.

    Now– I’m a designer, not a technical person … but I do host with GoDaddy and my server is a Windows server. I am not sure what the difference would be between mine and Apache.

    Windows uses a file called Web.config to do the same job. This has a different format. Its outside my experience but hopefully someone else can help with that.

    You might try reinstalling WordPress at Admin page > Dashboard > Updates “Re-install Now”, and resinstalling WooCommerce. Deactivate and delete the current plugin and reinstall from a fresh download. Your settings are in your database and should not be affected. Best to take a backup first.

    Ugh… I re-installed WordPress, I deleted Woocommerce and re-installed … it lost all my settings which I had to go recalibrate… and of course, the problem still happens.

    Sorry about losing your WooCommerce settings, didn’t know that.

    These services are detecting that your site is using an Apache server:
    http://sitecheck.sucuri.net/results/urtfc.org/
    http://whois.domaintools.com/urtfc.org
    so now looking for some other cause.

    This service:
    http://www.internetofficer.com/seo-tool/redirect-check/
    says http://www.urtfc.org/ is being permanently redirected to http://urtfc.org/

    Please check in Admin page > Settings > General that WordPress url and Site Address url are both http://urtfc.org/ (without the www)

    Unfortunately if you change these and it goes wrong, you could get locked out of the site. If so, the remedy would be to go to phpAdmin in cpanel and edit the values in the wp_options table. If you are unable to do that we need to think carefully before trying new values. Anyway, first off, what do these field show?

    No worries — I figured the settings would probably reset, so I was prepared for it. lol

    In General Settings, I have both the WordPress Address and Site Address set to http://urtfc.org (no www). That is how it always has been.

    I disabled all plug-ins … including the few WooCommerce add-ons I have such as Product Shipping and Name Your Price. With everything disabled, it still has the problem. I went through system status to make sure everything there checks out to be the newest version.

    I thought I had Apache, but I also know I’ve seen it’s a Windows server (as opposed to Linux) … but I know very little about all that. I do know that I have .htaccess files and not web.config.

    Your checkout page shows a Your order review box at the top with a remove cross and quantity change & update cart button. This order review box layout is non-standard and will have come from a custom page template from your theme.

    In the top post you say that you tried this with the TwentyFourteen theme, and the problem persists, yet TwentyFourteen doesn’t have a custom checkout template and the standard WooCommerce checkout template has an non-editable order review box which is positioned after the shipping form and before the payment options. You should be able to see this layout if you switch to TwentyFourteen theme again.

    There is some fault with the theme’s template for this page, and so the theme author is best placed to fix it. The theme does not appear to be from wordpress.org so forum members have no access to it. Check you are using the latest version of your theme. If it is a paid-for theme these usually come with support included.

    I do not use a 3rd party theme, rather one I have developed myself over time for the websites I create.

    I did not like having a separate cart page and checkout page (as it just added one more click to the process for people just buying one item, which is going to be the bulk of this website’s customers).

    So I combined the cart and checkout pages on to one page … and I did so by just including both short codes on one page, like this:

    <h2>Your Order</h2>
    [woocommerce_cart]
    [woocommerce_checkout]

    I don’t THINK this is the problem, however… because I have tested it with just the cart shortcode and just the checkout shortcode, and the problem occurs regardless.

    The redirect seems to be happening before the page even loads at all… before these shortcodes would even be processed. I have even added a forced redirect in the functions.php file that looks for the cart page, checks if it’s empty, and if so redirects to a totally different page. But this code never fires either.

    It’s as if, the moment you click the cart button with an empty cart, it never even tries to load the page. I am baffled.

    Oh– because I just combined the 2 shortcodes on the checkout page, when you switch to the Twenty Fourteen theme, it still works because the changes are not made in the theme, but on-page.

    The only difference, when you use Twenty Fourteen, you see the cart at top and then repeated at the bottom (as is standard on checkout page). In my theme, I have made the 2nd cart display:none as it is not necessary to review it again, with it being at the top.

    Oh. I’ve tried this. In Admin page > WooCommerce > Settings > Checkout tab, Checkout pages, the cart page points to the checkout page. I presume this is how you have it set. I had the same experience you describe. ie something still in the cart: works OK, nothing left in the cart: redirect loop.

    In the default setup, an attempt to use the checkout page when the cart is empty results in the cart page coming up with an empty cart message. So we can see the redirect loop forming here. The checkout section, finding the cart empty, loops to the checkout page. The loop is actioned in cart-errors.php line 20.

    I can’t help thinking having cart and checkout on the same page just isn’t going to work without some recoding work.

    There is a plugin which might be of interest:
    https://wordpress.org/plugins/woocommerce-direct-checkout/

    You nailed it.

    I didn’t think that was the problem, because I had written an if/then condition on the page itself to ignore the checkout shortcode if cart was empty. The problem is… that code was never being read because the redirect happened before it.

    So….. I solved it using this code in my function.php file….

    add_action( ‘init’, ‘woocommerce_empty_cart_redirect’ );
    function woocommerce_empty_cart_redirect() {
    global $woocommerce;
    if ( $_SERVER[“REQUEST_URI”] == “/checkout/” && !sizeof( $woocommerce->cart->get_cart() )) {
    wp_redirect( get_permalink( wc_get_page_id( ‘shop’ ) ) );
    exit;
    }
    }

    If someone with an empty cart tries to view the cart, it simply redirects to the shop page.

    Another possibility would be to create a new page, and use the CART shortcode ONLY. Redirection to this would display the empty cart on that condition, and the cart/checkout combo page for all other carts.

    I appreciate your help. I doubt I ever would have figured this out on my own!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Redirect Loop occurs when calling for Cart page if cart is empty’ is closed to new replies.