Home › Forums › WoodMart support forum › Theme Presets Not Working For Terms Attributes eg: Brand
Theme Presets Not Working For Terms Attributes eg: Brand
- This topic has 8 replies, 2 voices, and was last updated 7 months, 3 weeks ago by
Luke Nielsen.
-
AuthorPosts
-
July 10, 2024 at 1:30 pm #582385
MikeParticipantHi im trying to set catalog mode with theme presets for specific brand (Product Attribute) but its not working.
I created a video showcase so you will understood better the problem that i haveJuly 11, 2024 at 9:13 am #582561
Luke NielsenKeymasterHello,
I would like to request temporary admin access to the website to take a better look at the issue there.
Looking forward to collaborating with you!
Kind Regards
July 11, 2024 at 9:33 am #582569
MikeParticipantHi Luke,
Sure, please check privateJuly 12, 2024 at 9:25 am #582812
Luke NielsenKeymasterHello,
May I enable the parent theme and disable 3rd party plugins for testing?
Thank you in advance.
Kind Regards
July 12, 2024 at 9:38 am #582819
MikeParticipantHi Luke, please don’t enable or disable anything its a live eshop.
Instead of that i have setup a staging site to another domain so you can do whatever you need. Please check private content.July 13, 2024 at 9:50 am #583071
MikeParticipanthey Luke, you forgot me?
July 15, 2024 at 3:05 pm #583414
Luke NielsenKeymasterHello,
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
July 15, 2024 at 3:37 pm #583431
MikeParticipantHi Luke,
please check if your answer is related to another thread or something… because you talk about css, and the code you post its a php function related to my problem but unfortunately its not working, i added the code i create a preset based on brand term but the products belong to that brand still display the price and add to cart button. You can double check it on the function.php with the ftp credentials i have send to you
July 15, 2024 at 5:39 pm #583483
Luke NielsenKeymasterHello,
Here is the updated code, and it works well – https://prnt.sc/1lIN2edF6xZK
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( 'slug', $_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 );
Kind Regards
-
This reply was modified 7 months, 3 weeks ago by
Luke Nielsen.
-
This reply was modified 7 months, 3 weeks ago by
-
AuthorPosts
- You must be logged in to create new topics. Login / Register