• Resolved claumigue

    (@claumigue)


    When the search result is null, pressing Enter or clicking the magnifying glass icon leaves the page blank and the search form disappears. Is there a way to prevent that behavior? For example, when the search returns no results, pressing Enter or clicking does not trigger any action. Or any suggestions on how to prevent WooCommerce search results page from going blank

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Kris

    (@c0nst)

    Hi @claumigue!

    You can use this code snippet to redirect from search results page to a custom page when there aren’t search results:

    add_action( 'template_redirect', function () {
    	if ( ! empty( $_GET['dgwt_wcas'] ) ) {
        
    		global $wp_query;
    
    		if ( empty( $wp_query->found_posts ) ) {
    			wp_redirect(home_url('custom-page')); // Redirect URL
    			exit();
    		}
    
    	}
    } );
    

    You have two ways to add this code to your theme:

    1. Open the functions.php in your child theme and add the code at the end.
    2. or install the Code Snippets plugin and apply this code as a snippet.

    Regards,
    Kris

    Thread Starter claumigue

    (@claumigue)

    Thanks Kris. That helped me.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Blank page when no results’ is closed to new replies.