• Resolved mcuypers

    (@mcuypers)


    Hi,

    I’m having one issue which I am unable to resolve myself. I can’t seem to find the appropriate answer online.

    For example: I have an attribute named “Spiced”, with attribute values 0, 1, 2 and 3. The attribute indicates how spiced a product is on a scale from 0 to 3. My customers can filter on this attribute, for instance if they only want to see the products with a Spiced value of 2 . This all works really well.

    The problem I have is that, when such a filter is activated, it shows up in the Active Filters block as “2”, but it doesn’t show the attribute name “Spiced” . So you don’t really see or know what the “2” means. That becomes a problem once the customer has more and more filters active to make his search more specific.

    Is there a way to have the attribute name show up in the active filters block, so that it shows “Spiced: 2” ? I’d prefer to code it via functions.php and not resort to a plugin for this.

    I’m running the latest Woocommerce/Wordpress, in combination with the shoppingcart theme. But in Storefront, I don’t see the attribute name showing up either. It’s just showing the selected value.

    What am I missing?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Is it possible to share your store URL? If it’s not a live site, you can share a screenshot of the page where you want to show your attribute name – I recommend?https://snipboard.io?for easily sharing screenshots – please follow the instructions on the page, then paste the URL in this chat. It works with Chrome, Firefox, Safari, and Edge.

    Thread Starter mcuypers

    (@mcuypers)

    Hi

    Thanks for your reply. I managed to solve my issue over the weekend via jQuery, but I still find it strange that this doesn’t work out of the box.

    This was what I was trying to accomplish (the underlined texts in the “active filters on products “FILTERS” widget):

    https://snipboard.io/JfkQE8.jpg

    This is how I solved it:

    
    jq( document ).ready(function() {	    
        var label = [];
    	    
        <?php
               // QUERY ALL TAXONOMIES
               $args = array(
                          'public'   => true,
                          '_builtin' => false
       
                ); 
    
                $output = 'objects'; // or objects
                $operator = 'and'; // 'and' or 'or'
                $taxonomies = get_taxonomies( $args, $output, $operator ); 
                if ( $taxonomies ) {
                    foreach ( $taxonomies  as $taxonomy ) {
                        $attr_sing_name = $taxonomy->labels->singular_name;
                        
                        // GETTING THE TRANSLATED LABEL NAME (WPML)
                        $attr_label = apply_filters('wpml_translate_single_string', $attr_sing_name, "WordPress", "taxonomy singular name: " . $attr_sing_name);
    
                        ?>
                        /* ADDING TO A JS NAMED ARRAY FOR LATER */
                        label["<?php echo strtolower($attr_sing_name); ?>"] = "<?php echo $attr_label; ?>";
                        <?php
                    }
                }
    	    ?>
    
                /* GETTING ALL li OBJECTS WITH A CLASS THAT CONTAINS "chosen-" */
    	    
    	    $('li[class*="chosen-"]').each(function (index) {
    	       var obj = $(this);
    	       
    	       var classes = obj.attr('class');
    	       var classList = classes.split(" ");
    	       var attName = "";
    
                   /* GETTING THE ATTRIBUTE SINGULAR NAME FROM THE CLASS LIST */	       
    	       for (var iloop = 0; iloop<classList.length; iloop++) {
    	           var cname = classList[iloop].split("-");
    	           if (cname.length == 2) {
    	               attName = cname[1];
    	           }
    	       }
    	       
    	       attName = attName.toLowerCase();
    	       attNamePrint = label[attName] + ": ";
    	       
               /* NOW GETTING ALL THE anchors INSIDE THE CURRENT li OBJECT */
        	   obj.find('a').each(function (i) {
        	        var writehtml = "";
        	        var val = $( this ).text();
    
                    /* ADDING THE attribute name IN FRONT OF THE EXISTING VALUE */
      	        writehtml = attNamePrint + val;
            
        	        $(this).html(writehtml);
        	   });    	   
        });
        // ********
    
    });
    
    
    • This reply was modified 3 years, 11 months ago by mcuypers.
    • This reply was modified 3 years, 11 months ago by mcuypers.
    • This reply was modified 3 years, 11 months ago by mcuypers.

    Hello,

    Thank you for the update and sharing your solution! At this moment, core WooCommerce doesn’t show attribute names out of the box. It would be great to have you add your ideas to the Ideas Board, which is where developers go to look for future plugin features and improvements.

    I’m marking this thread as closed. If you have any other questions, please feel free to open a new topic.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show attribute name in active filters’ is closed to new replies.