Created
November 16, 2017 16:01
-
-
Save djrmom/22524bd45731c1d9fe186ff22fae7339 to your computer and use it in GitHub Desktop.
facetwp select all
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
<?php | |
/** | |
* attaches a click even to a div that selects all of a checkbox facets available options and triggers a refresh | |
* change "product_categories" to the name of your facet | |
* <div class="facetwp-checkbox select-all">Select all</div> creates a div that looks like facet checkboxes | |
* | |
*/ | |
add_action( 'wp_head', function() { ?> | |
<script> | |
(function($) { | |
$(document).ready(function() { | |
$(".select-all").click(function () { | |
var available = []; | |
$( '.facetwp-facet-product_categories .facetwp-checkbox' ).each( function (index, item) { | |
available.push( $(item).attr( 'data-value' ) ); | |
}); | |
FWP.facets['product_categories'] = available; | |
FWP.is_reset = true; // don't parse facets | |
FWP.refresh(); | |
}); | |
}); | |
})(jQuery); | |
</script> | |
<?php }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment