• Resolved sean815

    (@sean815)


    Need help please. I setup this plugin a couple of ways. First using append to normal description and second to its own tab. Both ways will display all my variation descriptions together, 1 on each line. How can I only display 1 description at a time for the selected attribute?

Viewing 1 replies (of 1 total)
  • Plugin Author mjke87

    (@mjke87)

    Hi Sean,

    I’m sorry but this is currently not conveniently possible.
    The plugin will always display all attribute descriptions of the current product.

    The only solution I can think of is the following hacky code, which adds a filter that returns an empty content of an attribute, if a content of the same attribute has already been filtered previously. I did not the test the code and you’d have to adjust it to your needs.

    
    <?php
    
    class MyFilterClass {
    
        private $attribute_contents = array();
        private $num_contents = 1;
        private $attributes_filter = array('myterm1', 'myterm2');
    
        public function __construct() {
            add_filter('woocommerce_product_attribute_tab_content_term', array($this, 'display_only_first_content', 10, 3);
        }
    
        public function display_only_first_content($content, $term, $attribute) {
            if (in_array($attribute['name'], $this->attributes_filter)) {
                if (isset($this->$attribute_contents[$attribute['name']]) {
                    if ($this->$attribute_contents[$attribute['name']] >= $this->num_contents) {
                        return '';
                    }
                    $this->$attribute_contents[$attribute['name']] += 1;
                }
                $this->$attribute_contents[$attribute['name']] = 1;
            }
            return $conent;
        }
    }
    
    new MyFilterClass();
    

    Kind regards,
    Mike

    • This reply was modified 6 years, 2 months ago by mjke87.
Viewing 1 replies (of 1 total)
  • The topic ‘Duplicate descriptions’ is closed to new replies.