Redirect an Empty EDD Checkout to Your Products
Sends visitors who land on the Easy Digital Downloads checkout with an empty cart to your products page instead of showing "Your cart is empty".
Opens WPIDE on
Code
$wpide_edd_shop_url = ''; // Empty uses the downloads archive, or the home page if there is none.
add_action( 'template_redirect', function () use ( $wpide_edd_shop_url ) {
if ( ! function_exists( 'edd_is_checkout' ) || ! edd_is_checkout() || edd_get_cart_contents() || isset( $_GET['payment-confirmation'] ) || isset( $_GET['edd-listener'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
$url = $wpide_edd_shop_url ? $wpide_edd_shop_url : get_post_type_archive_link( 'download' );
wp_safe_redirect( $url ? $url : home_url( '/' ) );
exit;
} );
Notes
Set $wpide_edd_shop_url to your products page; receipts and payment confirmation pages are not affected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.