Home › Forums › WoodMart support forum › Theme Presets Not Working For Terms Attributes eg: Brand › Reply To: Theme Presets Not Working For Terms Attributes eg: Brand
July 15, 2024 at 3:05 pm
#583414

Luke Nielsen
Keymaster
Hello,
The problem is that the condition you used (https://monosnap.com/file/1ALtunRr0C3MLtnar63alySn0in05P) only works for this term’s page (/brand/hay/
) but doesn’t work with our search because it uses our custom get parameters for filtering of goods (shop/?filter_brand=hay
). It was always there.
add_filter(
'xts_active_options_presets',
function ( $active_presets, $all ) {
foreach ( $all as $preset ) {
if ( empty( $preset['condition'] ) || empty( $preset['condition']['rules'] ) ) {
continue;
}
$rules = $preset['condition']['rules'];
foreach ( $rules as $rule ) {
$is_active = false;
switch ( $rule['type'] ) {
case 'term_id':
$object = get_queried_object();
$term_id = false;
if ( is_object( $object ) && property_exists( $object, 'term_id' ) ) {
$term_id = get_queried_object()->term_id;
$type = get_queried_object()->taxonomy;
$ancestors = get_ancestors( $term_id, $type );
if ( in_array( $rule['value_id'], $ancestors, false ) ) { // phpcs:ignore
$term_id = $rule['value_id'];
}
} else if ( isset( $_GET['filter_brand'] ) ) {
$taxonomy = 'pa_brand';
$term = get_term_by( 'name', $_GET['filter_brand'], $taxonomy );
$term_id = $term->term_id;
$ancestors = get_ancestors( $term_id, $taxonomy );
if ( in_array( $rule['value_id'], $ancestors, false ) ) { // phpcs:ignore
$term_id = $rule['value_id'];
}
}
if ( $term_id ) {
$condition = (int) $term_id === (int) $rule['value_id'];
$is_active = 'equals' === $rule['comparison'] ? $condition : ! $condition;
}
break;
}
if ( isset( $_GET['page'] ) && isset( $_GET['preset'] ) && 'xts_theme_settings' === $_GET['page'] ) { // phpcs:ignore
$is_active = true;
$preset['id'] = $_GET['preset']; // phpcs:ignore
}
if ( $is_active ) {
$priority = isset( $preset['priority'] ) ? $preset['priority'] : '';
$active_presets[ $priority ] = $preset['id'];
}
}
}
foreach ( $all as $preset ) {
if ( isset( $_GET['opts'] ) && $preset['name'] === $_GET['opts'] ) { // phpcs:ignore
$active_presets[] = $preset['id'];
}
}
ksort( $active_presets );
return array_unique( $active_presets );
},
10,
2
);
For now, you can use the above custom CSS to make it work. Define it in the functions.php file in your child theme.
Kind Regards