Overview

This JS event gets triggered before FacetWP begins the refresh process. It happens before any AJAX is requested, and before the URL hash gets updated. This event is useful for modifying any FWP variables before getting sent to the server.

Usage

Override facet value:

<?php
add_action( 'wp_footer', function() {
  ?>
    <script>
      document.addEventListener('facetwp-refresh', function() {
        FWP.facets['vehicle_type'] = ['car']; // force a specific value
      });
    </script>
  <?php
}, 100 );

Clear facet A’s value if a value for facet B is selected:

<?php
add_action( 'wp_footer', function() {
  ?>
    <script>
      document.addEventListener('facetwp-refresh', function() {
        if (FWP.facets['facet_b'].length > 0) {
          FWP.facets['facet_a'] = [];
        }
      });
    </script>
  <?php
}, 100 );

More examples

See also