How to display filter "sale products" at woo commerce

Hi we wonder how to display sale products filter at our categories. its was basic filter on difficult woo commerce.
Thanks !

Hi there,

This is currently not do-able by default and would require some custom development and overwriting files of the plugin.

I think the notion of “on_sale” should be in the index already.

You could add a toggle component to the instantsearch.js experience in the file templates/woocommerce-instantsearch.php.

I hope that helps,

hi,

I added to file woocommerce-instantsearch.php next code, like before.

search.addWidget(
instantsearch.widgets.refinementList({
container: ‘#facet-is-on-sale’,
attributeName: ‘is_on_sale’,
templates: {
header: ‘Sale’
}
})
);

But it not helped.
Also I added “section” with id “facet-is-on-sale” before

To get the on sale filter working you need to add the attribute to the facet attributes for example through child themes functions.php. Do this by adding the code

function customize_facets( array $settings ) {
$settings[‘attributesForFaceting’] = ‘is_on_sale’;
return $settings;
}
add_filter( ‘algolia_posts_product_index_settings’, ‘customize_facets’ );

Then woocommerce-instantsearch.php needs the the widget added:

search.addWidget(
instantsearch.widgets.toggle({
container: ‘#facet-saleproducts’,
attributeName: ‘is_on_sale’,
label: ‘Only on sale’,
values: {
on: true,
}
})
);

And also the section with id facet-saleproducts. This way I got it working. However there is still one issue to solve. When the toggle is active the current refined values show ‘true’ as a name for the facet clear button instead of the label set in the widget settings. I’m trying to find a solution to be able to customize this button naming.