Home Forums WoodMart support forum Theme Presets Not Working For Terms Attributes eg: Brand

Theme Presets Not Working For Terms Attributes eg: Brand

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #582385

    Mike
    Participant

    Hi 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 have

    #582561

    Luke Nielsen
    Keymaster

    Hello,

    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

    #582569

    Mike
    Participant

    Hi Luke,
    Sure, please check private

    #582812

    Luke Nielsen
    Keymaster

    Hello,

    May I enable the parent theme and disable 3rd party plugins for testing?

    Thank you in advance.

    Kind Regards

    #582819

    Mike
    Participant

    Hi 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.

    #583071

    Mike
    Participant

    hey Luke, you forgot me?

    #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

    #583431

    Mike
    Participant

    Hi 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

    #583483

    Luke Nielsen
    Keymaster

    Hello,

    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.
Viewing 9 posts - 1 through 9 (of 9 total)