facetwp select all
<?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 });