Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created November 16, 2017 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/22524bd45731c1d9fe186ff22fae7339 to your computer and use it in GitHub Desktop.
Save djrmom/22524bd45731c1d9fe186ff22fae7339 to your computer and use it in GitHub Desktop.
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 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment