• Hallo, I got a problem with “This webpage has a redirect loop” when i try to remove the very last item in the Woo-Cart by the (x) on my Chechout-page. If more than 1 item in the Cart i can remove all, but not the last item. (Like empty the Cart).

    WC Version: 2.1.12
    I use Woo Force SSL on check-out.

    I’ve tried to redirect the Cart to Frontpage when empty, with this Snippet in the themes/functions.php…

    // check for empty-cart get param to clear the cart
    add_action( ‘init’, ‘woocommerce_clear_cart_url’ );
    function woocommerce_clear_cart_url() {
    global $woocommerce;
    
    if ( isset( $_GET['empty-cart'] ) ) {
    $woocommerce->cart->empty_cart();
    wp_redirect('https://ivsstiftelse.dk/'); exit;
      }
    }

    but it doesn’t work.

    What is wrong here?

    Thx in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    I just figured this issue out! I have two function because I am using the first for a few things, but try this:

    function woocommerce_show_checkout() {
    	global $woocommerce;
    
    	$cart_number = sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);
    
    	if ($cart_number == 0) {
    		return false;
    	} else {
    		return true;
    	}
    
    }
    
    add_action('template_redirect', 'redirection_function');
    function redirection_function(){
        global $woocommerce;
        $cartNumber = woocommerce_show_checkout();
    
        if( is_checkout() and $cartNumber == false ) {
            wp_redirect( home_url() ); exit;
        }
    }

    I just want to thank you iCaleb, it saves me a lot of time! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce Empty Cart makes redirect Loop error’ is closed to new replies.