Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从我的搜索中阻止某些词直接进入产品-商业_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 如何从我的搜索中阻止某些词直接进入产品-商业

Php 如何从我的搜索中阻止某些词直接进入产品-商业,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我已经为我的woocommerce产品页面添加了一个搜索栏。有些搜索转到archive-product.php,有些搜索转到single-product.php。我想禁用单一产品快捷方式。我曾尝试在stackoverflow和google上搜索我的问题,但我得到的只是搜索过滤器插件 如何停止搜索单个产品,并在我的库存列表页面上自动搜索 要简化我的问题,这里是它的外观: 未搜索任何内容时: 当我搜索“轮子”时: 当我搜索“空气过滤器”时: 这是我的搜索条形码: <div class=&

我已经为我的woocommerce产品页面添加了一个搜索栏。有些搜索转到archive-product.php,有些搜索转到single-product.php。我想禁用单一产品快捷方式。我曾尝试在stackoverflow和google上搜索我的问题,但我得到的只是搜索过滤器插件

如何停止搜索单个产品,并在我的库存列表页面上自动搜索

要简化我的问题,这里是它的外观:

未搜索任何内容时:

当我搜索“轮子”时:

当我搜索“空气过滤器”时:

这是我的搜索条形码:

<div class="search-wrap">
            <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                <div class="search">
                    <label class="screen-reader-text " for="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>"><?php esc_html_e( 'Search for:', 'woocommerce' ); ?></label>
                    <input type="search" id="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>" class="search-field searchTerm" placeholder="<?php echo esc_attr__( 'Search products&hellip;', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
                    <button type="submit" class="searchButton" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>"><i class="fa fa-search"></i>
                    </button>
                    <input type="hidden" name="post_type" value="product" />
                </div>
            </form>
        </div>


通过将其添加到my functions.php中进行修复

add_filter( 'woocommerce_redirect_single_search_result', 'my_remove_search_redirect', 10 );
function my_remove_search_redirect() {
    return false;        
}
add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );
答案如下:
将以下内容添加到functions.php

add_filter( 'woocommerce_redirect_single_search_result', 'my_remove_search_redirect', 10 );
function my_remove_search_redirect() {
    return false;        
}
add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );

在全新安装上进行测试并正常工作。

这是产品搜索字段还是特定插件@wp78de这是通过PHP完成的产品搜索字段,没有任何插件。我使用了woocommerce自己插件中的搜索示例。(但在我的主题中重新设计了样式)酷,这与我找到的答案相似,但我没有意识到“return”和“false”是一个可用的过滤器。太棒了!谢谢