Как изменить результаты поиска WooCommerce? - PullRequest
0 голосов
/ 07 июля 2019

Я считаю, что поиск WooCommerce использует URL-адрес типа http://localhost/myshoesssite/?s=noheelshoes&post_type=product

Таким образом, мне нужно отредактировать результат поиска, чтобы я мог добавить параметр URL в конце каждого URL продукта, например http://localhost/myshoesssite/product/no-heel-shoes?get=specs, где get = specs - это параметр. Я только хочу добавить этот параметр в мои результаты поиска, а НЕ в типичный URL моего продукта.

Я пытался использовать search.php в своей теме, но, похоже, при редактировании файла результаты поиска не меняются. Ниже мой search.php

<?php
/**
 * The template for displaying search results pages.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
 *
 * 
 */

get_header(); ?>

<div id="primary" class="site-content content-wrapper topofset">
    <div id="main" class="container" >
        <div class="content content_search" >
            <?php
            if ( have_posts() ) : ?>

                <header class="page-header">
                    <h1 class="page-title text-light"><?php printf( esc_html__( 'Search Results for: %s', 'myticket' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                </header><!-- .page-header -->

                <?php
                /* Start the Loop */
                while ( have_posts() ) : the_post(); ?>

                     <span class="search-post-title">Testing<?php the_title(); ?></span>
            <span class="search-post-excerpt"><?php the_excerpt(); ?></span>
            <span class="search-post-link"><a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a></span>


                    <?php
                    /**
                     * Run the loop for the search to output the results.
                     * If you want to overload this in a child theme then include a file
                     * called content-search.php and that will be used instead.
                     */
                    //get_template_part( 'template-parts/content', 'search' );

                endwhile;

            else :

                get_template_part( 'template-parts/content', 'none' );

            endif; ?>
        </div>
    </div><!-- #main -->
</div><!-- #primary -->

<?php
get_footer();

Как мне этого добиться?

1 Ответ

0 голосов
/ 07 июля 2019

Во-первых, убедитесь, что у вас есть копия archive-product.php в папке wp-content / themes / yourtheme / woocommerce.Вы можете скопировать этот файл из wp-content / plugins / woocommerce / templates

Внутри archive-product.php, вам нужно различать результаты поиска между результатами поиска и результатами поиска на странице магазина, потому чтоделятся тем же шаблоном.Используйте что-то вроде ниже ... взято из шаблона результатов поиска WooCommerce

if ( is_search() ) {
    //put your search results markup here (you can copy some code from archive-product.php file and also from content-product.php to create a standard markup
} else {
    // here goes the content that is already in that file (archive-product.php) 
}

В заявлении is_search () if вы редактируете результаты поиска по своему усмотрению.Вы можете создать еще одну копию файла content-product.php (опять же, копирование из шаблона woocommerce в папку вашей темы), и там вы сможете настроить свои результаты поиска.Вы можете переопределить ловушки, такие как "woocommerce_before_shop_loop_item", поместив свои новые функции в functions.php в папке вашей темы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...