Ich habe eine Suche nach Attributen in WooCommerce entwickelt und alles scheint in Ordnung zu sein. Aber ein Attribut funktioniert nicht in der Suche. Der einzige Unterschied, den ich finde, ist ein alphabetisches Attribut und die anderen sind numerisch.Woocommerce Suche nach Attributen funktioniert nicht gut
Zum Beispiel gibt this URL die Ergebnisse korrekt zurück, aber wenn ich suche nach Vehiculo (pa_vehiculo) gibt alle Produkte zurück.
Warum passiert das? Hier
ist der Code, ein Plugin für ein Widget:
// 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
}
Alles funktioniert, außer dem Attribut vehiculo, die alle Ergebnisse.
Bitte aktualisieren Sie Ihre Frage mit Ihrem Code/Snippets? –
Hallo! hier update ich de code, wenn du etwas findest, sag es mir bitte! – Peregrina
Dies ist nicht mein Fachwissen, aber einige werden Ihnen helfen. und ich denke es gibt einen js Fehler in der Nähe von 'if (this.value ==' llantas ') 'gibt es ein extra'; '. –