문제

I want to redirect user to home page if shopping cart is empty, is this possible to do from admin panel, if yes please guide, otherwise I have to redirect by controller overloading.

도움이 되었습니까?

해결책

I don't think you can do this from the admin, but you could try

  1. In app/design/frontend/default/your-theme/template/checkout/cart/noItems.phtml add (this may not be the best solution but does work)

     <?php Mage::app()->getResponse()->setRedirect($this->getContinueShoppingUrl()); ?>
    
  2. Create an observer (try controller_action_predispatch_checkout_cart_delete) that check if your cart is empty then redirect see to the home page (for redirecting from observer see)

  3. Using javascript and timer so that the user will see that there cart is empty before redirecting to home page (see time delayed redirect?) Add code below to noItems.phtml see solution #1

    <script>
     setTimeout(function () {
       window.location.href = "<?php echo $this->getContinueShoppingUrl() ?>"; //will redirect  to your blog page (an ex: blog.html)
     }, 2000); //will call the function after 2 secs.
    </script>
    

다른 팁

Add this to your functions.php

function cart_empty_redirect_to_shop() {
    global $woocommerce;

    if ( is_page('cart') and !sizeof($woocommerce->cart->cart_contents) ) {
        wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); exit;
    }
}

add_action( 'wp_head', 'cart_empty_redirect_to_shop' );

The above will redirect an empty cart to the shop page.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top