How To Redirect WooCommerce and EDD Empty Checkout Pages

You are currently viewing How To Redirect WooCommerce and EDD Empty Checkout Pages

The empty checkout page is no fun. Not for the store owner or the website visitor.

Besides being unuser-friendly, a cart page without items will ultimately cost you revenue.

When the user removes items from the cart, there is a better chance for him to navigate away from your website afterward. To prevent it from happening, it will be better to direct them to some of the products that may interest them.

Please take a look at our website, for example. When you try to load our checkout page pluginsforwp.com/checkout when it’s empty, you’ll be redirected to our subscription page.

By doing so, I focused your attention on our available plans rather than giving you the option of where to go next, saving you valuable page load time.

This tutorial will redirect WooCommerce and Easy Digital Downloads empty cart pages to different pages.

Both codes below must be pasted in the functions.php file of your child theme or a site-specific plugin. Read our article and learn how to create a custom site-specific plugin in WordPress.

Please apply the functions below to a child theme and remember to back up WordPress before editing core files.

WooCommerce extensions

Redirect an Empty Checkout Page in WooCommerce

If you’re using the WooCommerce plugin to sell your goods, use the code below:

add_action("template_redirect", 'redirect_empty_checkout_woocommerce');
function redirect_empty_checkout_woocommerce(){
    global $woocommerce;
    if( is_cart() && WC()->cart->cart_contents_count == 0){
        wp_safe_redirect( site_url( 'shop' ) );
    }
}

The code above will redirect the visitors from an empty checkout or cart page to the archive Shop page.

However, if you prefer to land them on a different page, such as a specific product or the pricing page, change the URL address from 'shop' to 'product/product-name/'.

Redirect an Empty Checkout Page in Easy Digital Downloads

If you’re using the EDD plugin to sell your goods, use the code below

add_action( 'template_redirect', 'redirect_empty_checkout_edd', 11 );
function redirect_empty_checkout_edd(){
	if ( is_page( edd_get_option( 'purchase_page' ) ) && edd_get_cart_quantity() == 0 ) {
        wp_safe_redirect( site_url( 'downloads' ) );
		exit;
	}
}

Like the WooCommerce redirection function, the code above will redirect the users to the archive Downloads page, where they can view all your available products.

If you want to set a different URL, change 'downloads' to your desired address, such as 'downloads/product-name/'.

Related Articles

Conclusion

This article teaches you how to redirect empty checkout pages in WooCommerce and Easy Digital Downloads to another page.

Let us know which code snippet you used to achieve that.

Also, make sure to subscribe to our YouTube channel and like our page on Facebook.

PluginsForWP

PluginsForWP is a website specializing in redistributing WordPress plugins and themes with a variety of knowledge about WordPress, internet marketing, and blogging.

Leave a Reply