Viewing 1 replies (of 1 total)
  • Hi @alekseykurylev!

    You can do it this way:
    1. Create a new page in Admin Dashboard with no results message and publish it.
    2. Get this page ID – you can find it in the URL (see screenshot: https://prnt.sc/258jcr0).
    3. Use this code snippet (it will redirect user to no results page if there is no products to show):

    add_action( 'template_redirect', function () {
      global $wp_query; 
    
      $no_results_page = 'ID'; // replace with your no results page ID
    
      if ( ! empty ( $no_results_page ) && isset( $_GET['s'] ) && isset( $_GET['post_type'] ) && 'product' === $_GET['post_type'] && isset( $_GET['dgwt_wcas'] )
        && ! empty ( $wp_query ) && 0 == $wp_query->post_count  ) {
        wp_redirect( get_permalink( $no_results_page ) ); 
        exit();
      }
    
    } );

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

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

Viewing 1 replies (of 1 total)
  • The topic ‘Page without result’ is closed to new replies.