Last active
October 4, 2016 16:04
-
-
Save quimo/7b7f5bcba2221bea91bcd9a3d89c3961 to your computer and use it in GitHub Desktop.
WP | Aggiunta di una select per una tassonomia gerarchica gestita dal plugin Search and Filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function(){ | |
if (jQuery('body.home').length) { | |
var taxonomy = jQuery('li.sf-field-taxonomy-product_cat'); | |
taxonomy.addClass('product_first_cat'); | |
//clono la select della tassonomia e gli aggiungo una classe specifica | |
var taxonomy_clone = taxonomy.clone(); | |
taxonomy_clone.removeClass('product_first_cat').addClass('product_second_cat'); | |
taxonomy_clone.insertAfter(taxonomy); | |
//rimuovo le voci di secondo livello dalla prima select | |
taxonomy.find('option.sf-level-1').hide(); | |
taxonomy_clone.find('option').hide(); | |
jQuery('.product_first_cat select').on('change',function(){ | |
var selected = jQuery(this).find('option:selected').attr('class'); | |
jQuery('.product_second_cat option').hide(); | |
jQuery('.product_second_cat option').each(function(){ | |
if (jQuery(this).attr('class') == selected) jQuery(this).nextUntil('.sf-level-0').show(); | |
}); | |
}); | |
jQuery('.product_second_cat select').on('change',function(){ | |
jQuery('.product_first_cat select').val(jQuery(this).val()); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sul singolo form di ricerca in Search and Filters > General bisogna disabilitare le opzioni Enable auto count e Update the Search Form on user interaction altrimenti ad ogni interazione il form viene ricaricato via Ajax e l'aggiunta della select con jQuery è vanificata.