简体   繁体   中英

How to replace Wordpress default search with Woocommerce search

I need help replacing the default Wordpress search with Woocommerce search.

Tried this in functions.php

add_filter( 'pre_get_posts', 'custom_pre_get_posts' );
function custom_pre_get_posts( $query ) {
    if ( is_search() ) {
        $query->set('post_type', 'product');
    }

    return $query;
}

but the output of the search is still just a list of post-like search results. I would like the same output (product archive'ish) as the Woocommerce search outputs.

Is that possible?

Found a plugin. If anyone else wants a solutions without coding: https://wordpress.org/plugins/woocommerce-menu-extension/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM