Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active July 11, 2021 13:31
Show Gist options
  • Save djrmom/7e9233b2b67393cf90bde4ca470e2961 to your computer and use it in GitHub Desktop.
Save djrmom/7e9233b2b67393cf90bde4ca470e2961 to your computer and use it in GitHub Desktop.
facetwp add tooltips to slider
<?php
/** adds tooltips to slider handles
** https://refreshless.com/nouislider/slider-options/#section-tooltips
** note that you need an array even if you want true for both handles
**/
add_action( 'wp_footer', function() { ?>
<script>
(function($) {
if ('object' != typeof FWP) {
return;
}
FWP.hooks.addFilter('facetwp/set_options/slider', function(opts, facet) {
if (facet.facet_name == 'price') {
opts.tooltips = [true,true];
return opts;
}
});
})(jQuery);
</script>
<?php }, 100 );
@rjcdr
Copy link

rjcdr commented Jan 22, 2019

Had this break on me due to a plugin update. Replacing "wp" with the "FWP" object got things working again. To be clear:

wp.hooks.addFilter('facetwp/set_options/slider', function(opts, facet)

becomes

FWP.hooks.addFilter('facetwp/set_options/slider', function(opts, facet)

@bboerendans
Copy link

Thanks! Anybody an idea how to hide the decimals? Since it does not "respect" the decimal settings of the facet itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment