2017-01-17 5 views
-1

WooCommerceの属性で検索しましたが、すべてが正常であるようです。しかし、1つの属性が検索で機能していません。唯一の違いはアルファベット順の属性であり、他は数字であることです。属性別のWoocommerce検索がうまくいきません

たとえば、this URLは結果を正しく返しますが、vehiculo(pa_vehiculo)で検索するとすべての商品が返されます。

どうしてですか?

// The filter for some categories 

function pf_get_filter_options($title, $taxonomy) { 

    global $wp_query; 

    $options = '' . $title . ''; 

    $data = get_terms($taxonomy); 

    foreach ($data as $term) { 

     // Skip some weird terms 
     switch ($taxonomy) { 
      case 'product_cat': 
       if(in_array($term->slug, array('promociones'))) 
        continue(2); 
       break; 

     } 

     $selected = isset($wp_query->query_vars[$taxonomy]) && $wp_query->query_vars[$taxonomy] == $term->slug; 
     $options .= '<option value="' . $term->slug . '"' . $selected . '>' . $term->slug . '</option>'; 

    } 

    return $options; 

} 


// the front-end display and the script for change search by categories because have different attributes 

/** 
    * Front-end display of widget. 
    * 
    * @see WP_Widget::widget() 
    * 
    * @param array $args  Widget arguments. 
    * @param array $instance Saved values from database. 
    */ 
    public function widget($args, $instance) { 

     echo $args['before_widget']; 
     if (! empty($instance['title'])) { 
      echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; 
     } 
     ?> 

     <form id="form-neumaticos" action="<?php echo site_url('/'); ?>" class="search2" style="display:block"> 
      <input type="hidden" name="s" value=""/> 
      <input type="hidden" name="post_type" value="product"/> 
      <input type="hidden" name="product_cat" value="neumaticos"/> 

      <div class="search_box"> 

       <div class="select-categories-content-neumatic"> 
       <label>TIPO</label> 
       <select id="select-categories-neumaticos" class="selectBox" name="categories" placeholder="Seleccione"> 
       <option selected>neumaticos</option> 
       <option>llantas</option> 
       <option>accesorios</option> 

       <!-- <?php echo pf_get_filter_options('category-name', 'product_cat'); ?> --> 
       </select> 
       </div> 

      <div id="select-neumaticos"> 

       <div class="select-categories-content">   
       <label>VEHICULO</label> 
       <select class="selectBox selectneumaticos" name="pa_vehiculo"> 
        <option value="">Seleccione</option> 
       <?php echo pf_get_filter_options('vehiculo', 'pa_vehiculo'); ?> 
       </select> 
       </div> 

       <div class="select-categories-content">  
       <label>ANCHO</label> 
       <select class="selectBox selectneumaticos" name="pa_ancho"> 
       <option value="">Seleccione</option> 
       <?php echo pf_get_filter_options('ancho', 'pa_ancho'); ?> 
       </select> 
       </div> 

       <div class="select-categories-content">  
       <label>TALON</label> 
       <select class="selectBox selectneumaticos" name="pa_talon"> 
       <option value="">Seleccione</option>  
       <?php echo pf_get_filter_options('talón', 'pa_talon'); ?> 
       </select> 
       </div> 

       <div class="select-categories-content">  
       <label>RODADO</label> 
       <select class="selectBox selectneumaticos" name="pa_rodado"> 
       <option value="">Seleccione</option>  
       <?php echo pf_get_filter_options('rodado', 'pa_rodado'); ?> 
       </select> 
       </div> 

      </div> 
       <button class="search-button" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button> 
      </div> 
     </form> 

     <form id="form-llantas" action="<?php echo site_url('/'); ?>" class="search2" style="display:none;"> 
      <input type="hidden" name="s" value=""/> 
      <input type="hidden" name="post_type" value="product"/> 
      <input type="hidden" name="product_cat" value="llantas"/> 


      <div class="search_box"> 

       <div class="select-categories-content">  
       <label>TIPO</label> 
       <select id="select-categories-llantas" class="selectBox" name="categories"> 
       <option >neumaticos</option> 
       <option selected>llantas</option> 
       <option>accesorios</option> 
       <!-- <?php echo pf_get_filter_options('category-name', 'product_cat'); ?> --> 
       </select> 
       </div> 

      <div id="select-llantas"> 

       <div class="select-categories-content">  
       <label>VEHICULO</label> 
       <select class="selectBox selectllantas" name="pa_vehiculo"> 
       <option value="">Seleccione</option> 
       <?php echo pf_get_filter_options('vehiculo', 'pa_vehiculo'); ?> 
       </select> 
       </div> 

       <div class="select-categories-content"> 
       <label>RODADO</label> 
       <select class="selectBox selectllantas" name="pa_rodado"> 
       <option value="">Seleccione</option>  
       <?php echo pf_get_filter_options('rodado', 'pa_rodado'); ?> 
       </select> 
       </div> 

       <div class="select-categories-content"> 
       <label>AGUJEROS</label>   
       <select class="selectBox selectllantas" name="pa_agujeros"> 
       <option value="">Seleccione</option> 
       <?php echo pf_get_filter_options('agujeros', 'pa_agujeros'); ?> 
       </select> 
       </div> 

       <div class="select-categories-content"> 
       <label>PCD</label>  
       <select class="selectBox selectllantas" name="pa_pcd"> 
       <option value="">Seleccione</option>  
       <?php echo pf_get_filter_options('pcd', 'pa_pcd'); ?> 
       </select> 
       </div> 

      </div> 

       <button class="search-button" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button> 

      </div> 
     </form> 

     <?php 
     echo $args['after_widget']; 
     ?> 

    <script> 

jQuery.noConflict()(function ($){ 
    $(document).ready(function(){ 

     $('#select-categories-neumaticos').on('change', function() { 

     if (this.value == 'neumaticos') 

     { 

     $("#form-llantas").hide(); 


     $("#form-neumaticos").show(); 


    } 

     if (this.value == 'llantas') 

     { 


     $("#form-llantas").show(); 


     $("#form-neumaticos").hide(); 

    } 

}) 

     $('#select-categories-llantas').on('change', function(){ 


     if (this.value == 'llantas'); 

     { 

     $("#form-neumaticos").hide(); 


     $("#form-llantas").show(); 


     } 
     if (this.value == 'neumaticos') 

     { 

     $("#form-neumaticos").show(); 


     $("#form-llantas").hide(); 


     } 
    }) 

    $('#select-categories-neumaticos').on('change', function(){ 


     if (this.value == 'accesorios') 

     { 

      window.location = 'http://neumaticos.7vidas.com.ar/index.php/categoria-producto/accesorios/'; 
     } 
    }); 
    $('#select-categories-llantas').on('change', function(){ 


     if (this.value == 'accesorios') 

     { 

      window.location = 'http://localhost/neumaticos/index.php/categoria-producto/accesorios/'; 
     } 
    }); 

    }); 
}); 
    </script> 

<?php  
    } 

すべてがすべての結果を返す属性vehiculo、除いて動作します:ここで

コード、ウィジェットのプラグインです。

+1

あなたのコード/スニペットで質問を更新してください。 –

+0

こんにちは!ここで私はコードを更新します。何か見つかったら私に教えてください! – Peregrina

+0

これは私の専門知識から外れていますが、いくつかはあなたを助けます。私は 'if(this.value == 'llantas')'の近くにjsエラーがあると思います。余分な ';'があります。 –

答えて

0

私は解決策を見つける!属性による検索の場合は、チェックする必要があります。「この属性でストア内の製品アーカイブを使用する場合は、これを有効にしてください。属性で。 私はそれをチェックし、検索は正常に動作します。

Raunakさん、ありがとうございます!h

関連する問題