Gists

by mgibbs189 - 2 hours ago

(function($) {
  FWP.hooks.addAction('facetwp/loaded', function() {
    var facet_name = 'search';                                          // EDIT ME
    var allowed_elements = '.cat-item__title a, .cat-item__descr p';    // EDIT ME

    var keywords = FWP.facets[facet_name].toString();

    if ('' !== keywords) {
      $(allowed_elements).each(function() {
        var results = $(this).html();
        results = results.replace(new RegExp(keywords, "gi"), (match) => `<mark>${match}</mark>`);
        $(this).html(results);
      });
    }
  });
})(jQuery);

by mgibbs189 - 1 day ago

jQuery(document).ready(function($) {
  //* FacetWP Isotope
  var fwpScrollToBtn = false;
  var $grid = $('.fwpl-layout');
  $grid.imagesLoaded(function() {
    //* Wrapped in a short timeout function because $grid.imagesLoaded doesn't reliably lay out correctly
    setTimeout(function(){
      $grid.isotope({
        itemSelector: '.fwpl-result',
      });
    }, 250);
  });

  $(document).on('facetwp-loaded', function() {
    if (FWP.loaded) {
      $grid = $('.fwpl-layout');
      $grid.isotope('destroy');
      $grid.isotope({
        itemSelector: '.fwpl-result',
      });

      //* Scroll to the button of the results on click of load more since we're destroying the listing
      if(fwpScrollToBtn === true){
        var $loadMoreBtn = $('.facetwp-load-more');
        if($loadMoreBtn.length){
          $([document.documentElement, document.body]).animate({
            scrollTop:
              $loadMoreBtn.offset().top // button scrolled distance from the top of the screen
              - window.innerHeight // window height (to get it scrolled where the button is at the bottom of the screen vs top)
              + $loadMoreBtn.outerHeight() // height of the btn
              + 20 // padding from the bottom of the screen
          }, 250);
        }
      }
    }
  });
  
  $(document).on('click', '.facetwp-load-more', function () {
    fwpScrollToBtn = true;
  });
});
by mgibbs189 - 2 days ago

<?php

// Add the following to your (child) theme's functions.php file

add_action( 'wp_head', function() {
?>
<script>
(function($) {
    $(function() {
        if ('undefined' !== typeof FWP) {
            FWP.loading_handler = function(params) {}
        }
    });
})(jQuery);
</script>
<?php
}, 100 );

by mgibbs189 - 1 week ago

<?php

// Add to your (child) theme's functions.php

add_action( 'wp_head', function() {
?>
<script>
(function($) {
  $(document).on('facetwp-loaded', function() {
    $(document).trigger('updated_cart_totals'); // fix the "+/-" quantity buttons
  });
})(jQuery);
</script>
<?php
}, 100 );

by djrmom - 2 weeks ago

<?php
/** if facet is identifying the wrong query in elementor
 ** add a custom query id to your query settings in the element and
 ** use that name in the filter below in place of my_custom_filter
 ** https://developers.elementor.com/custom-query-filter/
 **/
add_action( 'elementor/query/my_custom_filter', function( $query ) {
	$query->set( 'facetwp', false );
} );
by mgibbs189 - 3 weeks ago

<?php

// Add to your (child) theme's functions.php file

add_action( 'wp_head', function() {
?>
<script>
(function($) {
  $(document).on('facetwp-loaded', function() {
    $('.facetwp-facet-product_categories > .facetwp-checkbox .facetwp-expand').each(function() {
      if ('[+]' == $(this).text()) {
        $(this).click();
      }
    });
  });
})(jQuery);
</script>
<?php
}, 100 );

by mgibbs189 - 4 weeks ago

(function($) {
    $(document).on('facetwp-loaded', function() {
        $('.fwpl-item.titleemail a').each(function() {
            var href = $(this).attr('href');
            $(this).closest('.fwpl-result').wrap('<a href="' + href + '"></a>');
        });
    });
})(jQuery);
by djrmom - 1 month ago

<?php
/** close flyout on facetwp-loaded so that the user doesn't need to close after facet refreshes **/
add_action( 'wp_head', function() { ?>
    <script>
        (function($) {
            $(document).on('facetwp-loaded', function() {
              if (FWP.loaded && $('.facetwp-flyout').hasClass('active') ) {
                  FWP.flyout.close();
              }
          });
        })(jQuery);
    </script>
<?php } );
by djrmom - 1 month ago

add_action( 'wp_head', function() {
    ?>
    <script>
    (function($) {
        $(function() {
            if ( 'undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
                FWP.hooks.addFilter('facetwp_map/fit_bounds', function( fit_bounds ) {
                    if ( FWP.loaded ) {
                        return fit_bounds;
                    } else {
                        return false;
                    }
                });
            }
        });
    })(jQuery);
    </script>
    <?php
}, 100);
by mgibbs189 - 1 month ago

<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'has_image' == $params['facet_name'] ) {
        $post_id = (int) $params['post_id'];

        if ( has_post_thumbnail( $post_id ) ) {
            $params['facet_value'] = 1;
            $params['facet_display_value'] = 'Has photos';
        }
        else {
            $params['facet_value'] = ''; // skip indexing this row
        }
    }
    return $params;
}, 10, 2 );