<?php
add_action( 'facetwp_scripts', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
FWP.hooks.addFilter('facetwp/selections/hierarchy_select', function(output, params) {
var selected_values = [];
params.el.find('.facetwp-hierarchy_select option:checked').each(function() {
var value = $(this).attr('value');
if (value.length) {
selected_values.push({value: value, label: $(this).text()});
}
});
if (selected_values.length === 3) {
console.log(selected_values[2]['label']); // get the label of the 3rd level choice and do something with it
}
return output;
});
});
})(fUtil);
</script>
<?php
}, 100 );