<?php
add_action( 'wp_footer', function() {
?>
<script>
(function($) {
if ('object' !== typeof FWP) {
return;
}
$(function() {
FWP.hooks.addAction('facetwp/loaded', function() {
/* run code here after facetwp loaded, 100 below can be modified to set priority order */
$('.facetwp-facet').each(function() {
var facet_name = $(this).attr('data-name');
var facet_label = FWP.settings.labels[facet_name];
if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && FWP.settings.num_choices[facet_name] > 0 && $('.facet-label[data-for="' + facet_name + '"]').length < 1 ) {
$(this).before('<h3 class="facet-label" data-for="' + facet_name + '">' + facet_label + '</h3>');
} else if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && !FWP.settings.num_choices[facet_name] > 0 ) {
$('.facet-label[data-for="' + facet_name + '"]').remove();
}
});
}, 100 );
});
})(jQuery);
</script>
<?php
}, 100 );