Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

search-results template display placeholder image for Woo products

  • Is there a way to show the placeholder image for Woo products on the search-results template? I don’t see it in settings anywhere.

  • Hi there,

    I’m not sure what you mean by placeholder image, do you mean the primary image of the product?

    Let me know 🙂

  • Hi Ying,
    No. I mean the placeholder image. It’s the image that every product has until you add a primary image. On wooCommerce/Settings/Product, there is a field for the ID# of a placeholder image. I would like the search results to show that image if a primary image has not been added.
    This is the goal https://yourmediaexchange.com/?s=who&post_type=product to have the search results look the same as when the post type is on the query. Or how can I add the post type to the query?

    I think someone asked a similar question here: https://generatepress.com/forums/topic/change-search-parameters-in-navigation-menu/ (at least, I think that is what they are asking). The code, as far as I can tell, no longer works.

  • I see, but I don’t think there’s such an option. Woocommerce does not show the placeholder image on search result page by default.

    You will need to write custom functions for this, unfortunately.

  • Correct. Similar to what Tom wrote for the person who asked this question previously.

    add_filter( ‘generate_navigation_search_output’, ‘tu_wc_navigation_search’ );
    function tu_wc_navigation_search() {
    printf(
    ‘<form method=”get” class=”search-form navigation-search” action=”%1$s”>
    <input type=”search” class=”search-field” value=”%2$s” name=”s” title=”%2$s”>
    <input type=”hidden” name=”post_type” value=”product”>
    </form>’,
    esc_url( home_url( ‘/’ ) ),
    esc_attr( get_search_query() ),
    esc_attr_x( ‘Search’, ‘label’, ‘generatepress’ )
    );
    }

    Is this something you can’t do?

  • The code returns only products in the search result, but it can not alter the HTML of the woocommerce products. So no, it does not work for your needs.

  • Hi Ying,
    Let me ask the question differently.

    How do I add a post_type parameter in the search form located in the inc/structure/navigation.php line 449 properly to a child theme?

    Similar to what Tom provided in the topic I referenced earlier?

  • Hi there,

    can i see your website ? I need to see what Search you’re using on the site.
    For example the code you have in Toms reply is related to the old Navigation Search, and it won’t work with the newer modal search or a search widget.

  • Try this PHP snippet:

    
    add_action('wp',function(){
    	remove_action( 'generate_inside_search_modal', 'generate_do_search_fields');
    	add_action( 'generate_inside_search_modal', 'custom_do_search_fields' );	
    });
    
    function custom_do_search_fields() {
    	?>
    	<form role="search" method="get" class="search-modal-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    		<label for="search-modal-input" class="screen-reader-text"><?php echo apply_filters( 'generate_search_label', _x( 'Search for:', 'label', 'generatepress' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label>
    		<div class="search-modal-fields">
    			<input id="search-modal-input" type="search" class="search-field" placeholder="<?php echo esc_attr( apply_filters( 'generate_search_placeholder', _x( 'Search &hellip;', 'placeholder', 'generatepress' ) ) ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
                            <input type="hidden" name="post_type" value="product">
    			<button aria-label="<?php echo esc_attr( apply_filters( 'generate_search_button', _x( 'Search', 'submit button', 'generatepress' ) ) ); ?>"><?php echo generate_get_svg_icon( 'search' ); // phpcs:ignore -- Escaped in function. ?></button>
    		</div>
    		<?php do_action( 'generate_inside_search_modal_form' ); ?>
    	</form>
    	<?php
    }
    
  • THANK YOU SOOOOOOOOO MUCH, DAVID!!!!! IT WORKS!!!! I have been trying so many plugins to do this and they all conflicted with Relevanssi. I’ve been trying to figure this out for almost two years, lol. I knew there had to be a simple solution.

    Thank you again!!! I really appreciate your help! You have made my week!

  • Glad we could be of help!

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.