Skip to content

Instantly share code, notes, and snippets.

@rayrutjes
Last active February 14, 2018 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayrutjes/82c392fa206a6f9f3f47aa2fd424fea1 to your computer and use it in GitHub Desktop.
Save rayrutjes/82c392fa206a6f9f3f47aa2fd424fea1 to your computer and use it in GitHub Desktop.
Filter displayed facets in Algolia plugin for WooCommerce
<?php
add_filter( 'algolia_wc_attributes_for_faceting', function( $attributes ) {
$only_ids = array(
15, // Main Style
13, // Main Color
49, // Sizes
23, // Brand
4, // Collection
22, // Material
17, // Construction
);
foreach ( $attributes as &$attribute ) {
if ( ! in_array( $attribute['attribute_id'], $only_ids, true ) ) {
$attribute['is_enabled'] = false;
} else {
$attribute['is_enabled'] = true;
$attribute['weight'] = array_search( $attribute['attribute_id'], $only_ids, true );
$attribute['sort_by'] = array( 'isRefined:desc', 'name:asc' );
}
}
return $attributes;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment