Last active
August 31, 2017 23:05
-
-
Save djrmom/80eea2dff3b4bd7430c712e7283bea33 to your computer and use it in GitHub Desktop.
facetwp disable dropdown conditionally
This file contains hidden or 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
<script> | |
(function($) { | |
/** | |
* creates a parent -> child -> grandchild dependency to disable facets | |
*/ | |
$(document).on('facetwp-loaded', function() { | |
if ('undefined' !== typeof FWP.facets['product_categories'] && FWP.facets['product_categories'].length < 1 ) { | |
$( '.facetwp-facet-product_tags select, .facetwp-facet-rating select').prop('disabled', 'disabled'); | |
} else if ('undefined' !== typeof FWP.facets['product_tags'] && FWP.facets['product_tags'].length < 1 ) { | |
$( '.facetwp-facet-rating select').prop('disabled', 'disabled'); | |
} | |
}); | |
/** | |
* resets the facets when the "parent" is deselected | |
*/ | |
$(document).on('facetwp-refresh', function() { | |
if ( 'undefined' !== typeof FWP.facets['product_categories'] && FWP.facets['product_categories'].length < 1 ) { | |
FWP.facets['product_tags'] = []; | |
FWP.facets['rating'] = []; | |
} else if ( 'undefined' !== typeof FWP.facets['product_tags'] && FWP.facets['product_tags'].length < 1 ) { | |
FWP.facets['rating'] = []; | |
} | |
}); | |
})(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment