I’m working on an e-commerce site based on WooCommerce and the Divi theme. Specifically, when the cart is empty, I get a blank page (though the header and footer are present). I’d like to know if there is a way to use a custom page for the empty cart.
I’ve already tried adding this code to functions.php
:
function custom_redirect_empty_cart() {
// Replace 123 with the ID of your custom page
$empty_cart_page_id = 123; // Change this to your page ID
if ( WC()->cart->is_empty() && !is_cart() && !is_checkout() ) {
wp_redirect( get_permalink( $empty_cart_page_id ) );
exit;
}
}
add_action( 'template_redirect', 'custom_redirect_empty_cart' );
But it didn’t work.
Can you help me? Thank you very much!