Buy All 47 Premium Themes For the Price Of $199.99

How to Add a Custom “Empty Cart Redirect” in WooCommerce Using Hooks

A common issue in WooCommerce stores is users landing on an empty cart page.
Instead of showing an empty cart, you can redirect customers to a more useful page such as the shop or homepage.

In this tutorial, you will learn how to redirect users when their WooCommerce cart is empty using hooks.

Why This Improves Sales

An empty cart is a dead end. Redirecting users keeps them engaged and encourages continued shopping.

  • Prevents dead-end pages
  • Improves user navigation
  • Increases product discovery
  • Boosts conversion rates

The WooCommerce Hook We Will Use

We will use:

template_redirect

This hook runs before WordPress loads the page content, making it perfect for redirects.

Example Code

Add this code to your theme’s functions.php file or a custom plugin:


add_action('template_redirect', 'redirect_empty_cart');

function redirect_empty_cart() {

    if (is_cart() && WC()->cart && WC()->cart->is_empty()) {

        wp_redirect(wc_get_page_permalink('shop'));
        exit;
    }
}

How It Works

This function checks if the user is on the cart page and if the cart is empty.

  • If cart is empty → redirect to shop page
  • If cart has items → normal cart page loads

Customization Ideas

  • Redirect to homepage instead of shop
  • Show special offers before redirecting
  • Delay redirect with a message
  • Redirect based on user role