5 days ago
<?php
// Changes 'mi' to 'miles' in a Proximity facet's radius dropdown
add_action('facetwp_scripts', function () {
?>
<script>
(function($) {
document.addEventListener('facetwp-loaded', function() {
let radiusdropdown = document.querySelector('.facetwp-radius-dropdown');
radiusdropdown.querySelectorAll('option').forEach(option => {
if (option.textContent.trim().endsWith('mi')) {
const newOptionText = option.textContent.replace(/mi\b/g, 'miles'); // Replace 'mi' with 'miles' if it is at the end of the option string
option.textContent = newOptionText;
}
});
});
})(fUtil);
</script>
<?php
}, 100);
6 days ago
<?php
add_action('facetwp_scripts', function () {
?>
<script>
(function($) {
document.addEventListener('facetwp-refresh', function() {
if ( 'undefined' != typeof FWP_MAP && true === FWP_MAP.is_filtering) {
$('.facetwp-location').val(''); // reset the value of the input field
$('.facetwp-lat').val(''); // reset hidden field
$('.facetwp-lng').val(''); // reset hidden field
$('.facetwp-radius option').each(function () {
if (this.defaultSelected) {
this.selected = true;
return false;
} // reset default radius if it is a dropdown
});
FWP.facets['my_proximity_facet'] = []; // change 'my_proximity_facet' to name of your Proximity facet
}
});
})(fUtil);
</script>
<?php
}, 100);
7 days ago
<?php
// Adds FacetWP compatibility to the Avada theme's Post Cards element.
// For this to work, the Post Cards listing also needs a 'facetwp-template' class.
add_filter( 'fusion_post_cards_shortcode_query_args', function( $query_args ) {
$query_args['facetwp'] = true;
return $query_args;
}, 10 );
1 week ago
<?php
/** filter upt post type registration prevent
** frontend viewing of single posts
**/
add_filter( 'upt_post_type_args', function( $args ) {
$args['publicly_queryable'] = false;
return $args;
});
1 week ago
<div class="woocommerce">
<?php
if ( have_posts() ) {
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
while ( have_posts() ) {
the_post();
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
} else {
do_action( 'woocommerce_no_products_found' );
}
?>
</div>
1 week ago
<?php
/** changes depth and parent_ids
** to allow a hierarchy to start with
** first level children instead of top level parents
**/
add_filter( 'facetwp_index_row', function( $params ) {
if ( 'my_facet' == $params['facet_name'] ) { // 'my_facet' should be replaced with your facet name
if ( 1 > $params[ 'parent_id' ] ) { // this will be top level parents
$params[ 'facet_value' ] = ''; // don't index
} elseif ( 2 > $params[ 'depth' ] ) { // first level children need depth and parent id changed
$params[ 'parent_id' ] = 0;
$params[ 'depth' ] = 0;
} else { // other children just need depth adusted
$params[ 'depth' ] = $params[ 'depth' ] - 1;
}
}
return $params;
});
1 week ago
<?php
/** change names formatted "John Smith"
** to display as "Smith, John"
** in facet's index
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'personfacet' == $params['facet_name'] ) { // change 'personfacet' to name of your facet
$name = $params['facet_display_value'];
$name = explode( ' ', $name );
$display_name = array_pop( $name ) . ', ' . implode( ' ', $name );
$params['facet_display_value'] = $display_name;
}
return $params;
}, 10, 2 );
1 week ago
<?php
add_action( 'facetwp_scripts', function() { ?>
<script>
(function($) {
FWP.hooks.addAction('facetwp/loaded', function() {
$( '.facetwp-facet-my_categories .fs-option.d1').each(function() {
var el = $(this);
var parent = el.prev('.fs-option.d0');
parent.addClass( 'disabled' );
});
}, 100 );
})(jQuery);
</script>
<?php }, 100 );
2 weeks ago
<?php
add_action('facetwp_scripts', function () {
?>
<script>
FWP.hooks.addAction('facetwp/loaded', function() {
/** adds aria-label to input */
fUtil('.facetwp-type-fselect .fs-search input').each(function() {
fUtil(this).attr('aria-label', 'this is the label');
});
/** prepends <label> and text to input */
// element that will be wrapped
var el = document.querySelector('.facetwp-type-fselect .fs-search input');
// create wrapper container
var wrapper = document.createElement('label');
// insert wrapper before el in the DOM tree
el.parentNode.insertBefore(wrapper, el);
// add label text
wrapper.textContent = "This is the label";
}, 1000);
</script>
<?php
}, 100);
3 weeks ago
<?php
/** change 'Default sort' to the text of your Default label setting of your search facet, be sure to match exactly including case
** https://facetwp.com/help-center/facets/facet-types/sort/#available-options
** change 'my_search_facet' to the name of your search facet (2 places)
** change 'Relevance' to whatever you want the default label to be when using a search facet
**/
add_filter( 'facetwp_i18n', function( $text ) {
if ( 'Default sort' == $text && isset( FWP()->facet->facets['my_search_facet']['selected_values'] ) && !empty( FWP()->facet->facets['search']['selected_values'] ) ) {
return 'Relevance';
}
return $text;
});