I am using Easy Digital Downloads to sell some digital products, I want if the checkout page is empty, when they try to visit the empty checkout page they will be redirected to a specific page. is it possible? if possible how can I do this?
Asked
Active
Viewed 407 times
2 Answers
0
I know that this post is old but I found a snippet that actually works, maybe someone can be useful.
function edd_empty_cart_redirect() {
$cart = function_exists( 'edd_get_cart_contents' ) ? edd_get_cart_contents() : false;
$redirect = site_url( 'shop' ); // could be the URL to your shop
if ( function_exists( 'edd_is_checkout' ) && edd_is_checkout() && ! $cart ) {
wp_redirect( $redirect, 301 );
exit;
}
}
add_action( 'template_redirect', 'edd_empty_cart_redirect' );
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 21 '22 at 12:35
-1
WooCommerce already redirect checkout to cart page if there are not products in cart, but you can change that and redirect to your custom page:
function wc_custom_template_redirect(){
global $wp_query, $wp;
// When on the checkout with an empty cart, redirect to cart page.
if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
$page_id = 62;
wp_redirect( get_the_permalink( $page_id ) );
exit;
}
}
add_action( 'template_redirect', 'wc_custom_template_redirect', 0 );
Make sure the $page_id
reflects ID of the page you want to redirect to.

Ali_k
- 1,642
- 1
- 11
- 20
-
-
can you please customise the code which will work with the easy digital download? – Iftikhar Alam Jun 10 '19 at 19:17