phpwordpresswoocommercecartcheckout

WooCommerce Combined Cart & Checkout Page (Redirect Issue)


I have a single page site that has a product listing, cart & checkout all on one page. It's been a challenge to get this setup working but I have it 99% of the way there :/

My issue is if I click on the Update Cart button without any of the Qty fields being changed is redirects me to the actual cart page.

Here is my setup

This works great, I can add products to the cart, adjust the qty in the cart and checkout without issue.

However, if I click the "Update Cart" without any changes to any Qty fields it redirects to /cart. This is a huge problem as I need to stay on this page.

Things I've tried...


Solution

  • The only way to get this solved is by keeping the update button disabled until a quantity has been changed. It requires custom JavaScript (jQuery).

    Now for that redirection problem to the cart page, you could try to change the cart URL used in/with wc_get_cart_url() function to the checkout URL, using the following:

    add_filter( 'woocommerce_get_cart_url', function( $url ) { 
        return wc_get_checkout_url();
    } );
    

    or simply:

    add_filter( 'woocommerce_get_cart_url', 'wc_get_checkout_url' );
    

    This could improve/solve the redirection behavior issue.