PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Limit Slider values based on current Category

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

In some situation could be great if also Slider view can limit values only to possible values based on products in current Category.

Other fields types already do it, but actually Sliders show ALL terms of the selected taxonomy...

here my solution to limit values and automatically hide the filter if products of this category are not related to these terms.

if (!is_admin()) {

add_filter('woof_sort_terms_before_out', function($terms, $type) {

 

if($type == 'slider') {

 

// get current term ID

$term_id = 0;

$term = get_queried_object();

if ($term && get_class($term) == 'WP_Term') {

$term_id = get_queried_object_id();

$term_slug = $term->slug;

$taxonomy = $term->taxonomy;

} else {

if (!empty($_GET['really_curr_tax'])) {

$tmp = explode('-', $_GET['really_curr_tax']);

$term_id = intval(reset($tmp));

$taxonomy = end($tmp);

$term = get_term_by('id', $term_id, $taxonomy);

$term_slug = $term->slug;

}

}

if ($term_id) {

$value = reset($terms);

$field = $value['taxonomy'];

 

$args = array(

'category' => array( $term_slug ),

'limit' => -1,

'type' => ['simple','variable','variation']

);

$products = wc_get_products( $args );

$values = [];

foreach ($products as $product) {

$tmp = get_the_terms($product->get_id(), $field);

if ($tmp) {

foreach ($tmp as $vtmp) {

$values[$vtmp->term_id] = $vtmp;

}

}

}

if (empty($values)) {

// remove filter

return $values;

} else {

// limit filter values for this category

foreach ($terms as $key => $term) {

if (empty($values[$term['term_id']])) {

unset($terms[$key]);

}

}

}

}

}

 

return $terms;

 

}, 11, 2);

}

Could be great if you integrate this code and add an extra option for each filter to limit values.

 

Thanks

Hello

PleaseĀ  try to check this option - https://share.pluginus.net/image/i20250402113148.png