13 hours ago
<?php
// Temporary fix to remove accessibility attributes from the Pager facets "dots" element.
add_action( 'facetwp_scripts', function() {
?>
<script>
(function($) {
if ('undefined' !== typeof FWP.hooks) {
FWP.hooks.addAction('facetwp/loaded', function() {
$('.facetwp-page').each(function() {
let el = $(this);
if (el.hasClass('dots')) {
el.nodes[0].removeAttribute('role');
el.nodes[0].removeAttribute('aria-label');
el.nodes[0].removeAttribute('tabindex');
}
});
}, 1000);
}
})(fUtil);
</script>
<?php
}, 100 );
2 days ago
<?php
add_action('facetwp_scripts', function () {
?>
<script>
FWP.hooks.addAction('facetwp/loaded', function() {
/** 1. add an aria-label attribute to input */
fUtil('.facetwp-per-page-select').each(function() {
fUtil(this).attr('aria-label', 'Set the number of results per page');
});
/** 2. prepend a <label for="id"> element to the <select> element and add an 'id' to the <select> */
let select = document.querySelector('.facetwp-per-page-select');
// set 'id' attribute for select
select.setAttribute('id', 'set-results-per-page');
// create label element
let label = document.createElement('label');
// set 'for' attribute for label: must me same as 'id' of the select element.
label.setAttribute('for', 'set-results-per-page');
// insert label before select in the DOM tree
select.parentNode.insertBefore(label, select);
// add label text
label.textContent = "Set the number of results per page";
}, 1000);
</script>
<?php
}, 100);
2 days ago
<?php
// Creates a custom dynamic tag {{ my-color-swatches }} to use in the Listing Builder, that displays color swatches for each product.
// This snippet works with swatches from Iconic's WooCommerce Attribute Swatches plugin and colors set as product attribute.
// See: https://facetwp.com/help-center/using-facetwp-with/woocommerce-attribute-swatches/#create-a-custom-dynamic-tag-to-output-color-swatches-for-each-product
add_filter( 'facetwp_builder_dynamic_tag_value', function( $tag_value, $tag_name, $params ) {
// Replace 'my-color-swatches' with the name of your custom dynamic tag name .
if ( 'my-color-swatches' == $tag_name ) {
// Replace 'pa_color' with the name of the WooCommerce attribute used for the product color.
// Note that 'pa_' is automatically added by WooCommerce before the attribute's slug.
$terms = wp_get_post_terms( $params['post']->ID, 'pa_color', array( 'fields' => 'ids' ) );
$tag_value = '';
foreach($terms as $term_id) {
$color_code = get_term_meta($term_id, 'iconic_was_term_meta', true);
$color_code = maybe_unserialize($color_code);
$color_code = $color_code['colour-swatch'];
if ($color_code) {
$tag_value .= '<div class="color-swatch" style="background-color: ' . $color_code . '; width: 24px; height:24px; display: inline-block; margin: 0 12px 0 0;"></div>'; // Adapt the CSS as needed.
}
}
}
return $tag_value;
}, 10, 3 );
3 days ago
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
if ( 'my_color_facet_name' == $facet['name'] ) { // Change 'my_color_facet_name' to the name of your facet.
$term_ids = get_terms( [
'taxonomy' => 'pa_color', // Change 'pa_color' to the name of the attribute used in the Color facet's data source setting..
'term_order' => true,
'fields' => 'ids',
] );
if ( ! empty( $term_ids ) && ! is_wp_error( $term_ids ) ) {
$term_ids = implode( ',', $term_ids );
$orderby = "FIELD(f.term_id, $term_ids)";
}
}
return $orderby;
}, 10, 2 );
2 weeks 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);
2 weeks 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);
2 weeks 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 );
3 weeks 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;
});
3 weeks 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>
3 weeks 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;
});