如何更改默认的WordPress搜索以搜索woocommerce产品?

时间:2017-12-24 11:01:07

标签: php wordpress search woocommerce

我想更改这些代码以显示woocommerce的产品。

public function wpr_search_form() {
    $search_placeholder = $this->option('search_box_text');
    $unique_id = esc_attr( uniqid( 'search-form-' ) );
    return '<form role="search" method="get" class="wpr-search-form" action="' action="<?php echo esc_url(home_url('/') . '"><label for="'.$unique_id.'"></label><input type="search" class="wpr-search-field" placeholder="' . $search_placeholder . '" value="" name="s" title="Search for:"><button type="submit" class="wpr_submit"><i class="wpr-icon-search"></i></button></form>';

1 个答案:

答案 0 :(得分:0)

请使用以下内容:

 <form role="search" method="get" class="search-form" action="<?php echo 
 home_url( '/' ); ?>">
<label>
    <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) 
 ?></span>
    <input type="search" class="search-field" placeholder="<?php echo 
  esc_attr_x( 'Search …', 'placeholder' ) ?>" value="<?php echo 
get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 
 'label' ) ?>" />
 </label>
  <input type="submit" class="search-submit" value="<?php echo esc_attr_x( 
 'Search', 'submit button' ) ?>" />
<input type="hidden" value="product" name="post_type" id="post_type" />
   </form>