Halloween Sale 15% off Ends in See the plans
PHP

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".

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.