[Resolved] redirect to shop archive if cart is empty

Home Forums Support [Resolved] redirect to shop archive if cart is empty

Home Forums Support redirect to shop archive if cart is empty

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2201011
    sparkle

    in the past, i’ve used this code to redirect a person to the shop catalog page when the cart is empty but they click on the shopping cart icon in the menu, but it’s not working anymore?

    // woo - navigation - empty cart redirect to shop
    add_action( 'template_redirect', 'empty_cart_redirect' );
    function empty_cart_redirect(){
        if( is_cart() && WC()->cart->is_empty() ) {
            wp_safe_redirect( get_permalink( wc_get_page_slug( 'store' ) ) );
            exit();
        }
    }

    i originally found it here
    https://stackoverflow.com/questions/24300052/if-cart-is-empty-the-cart-page-will-redirect-to-shop-page-in-woocommerce

    but now, it won’t redirect to the store page (yes, i’ve checked the slug) do you know why?

    #2201024
    sparkle

    oh! never mind. i thought i needed to match the slug of our shop page, but it has to stay ‘shop’ to work properly.

    thanks for your moral support! lol

    ๐Ÿ™‚

    #2201078
    Ying
    Staff
    Customer Support

    lol glad you figured it out ๐Ÿ™‚

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.