Hello, I hope you are well
I want to add a feature
When the color or size is not available, it should not be displayed in the filter search
for example :
The customer enters the shoes category and filters size 40
And I want the shoes whose size 40 is finished not to be displayed in the filter
I also used the code below, but it didn’t work
Thank you for your guidance
add_filter( 'woocommerce_product_variation_get_available', 'hide_unavailable_variations', 10, 3 );
function hide_unavailable_variations( $available_variations, $product, $variation ) {
// Check if the variation is available
if ( ! $variation->is_in_stock() ) {
// If not available, remove it from the list of available variations
foreach ( $available_variations as $key => $value ) {
if ( $value['variation_id'] == $variation->get_id() ) {
unset( $available_variations[$key] );
}
}
}
return $available_variations;
}