• Resolved pedrorito

    (@pedrorito)


    Hi,
    after I updated the Product tab description of all items of a specific attribute, the tab of that attribute now appears in the product page. However, the same attribute continues to appear in the Additional information tab. Is there a way to set the attribute to only appear in the new tab and disappear from the Additional information tab?
    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter pedrorito

    (@pedrorito)

    If I disable “Visible on the product page”, the attribute disappears from the Additional information tab, and the new attributed tab from your plugin is still kept. So, it solves. However, it would be nice to have an option of doing this automatically, without going to every product to disable “Visible on the product page” in that attribute. Any suggestion? Thanks

    Plugin Author mjke87

    (@mjke87)

    Hi @pedrorito,

    What you are looking for seems to be a new functionality that removes product attribute terms from the “Additional information tab” implicitly, if they have a product tab description set. Is that correct?

    This behavior should be be achievable using the appropriate WooCommerce filter hook which checks for the “Visible on the product page” flag.

    One easy idea would be to disable a specific attribute globally using something like the following code:

    // Globally disable attribute visibility for MY TAXONOMY
    add_filter('woocommerce_get_product_attributes', function($attributes) {
        foreach ($attributes as $key => $attribute) {
            if ($attribute['is_taxonomy'] && $attribute['name'] == 'MY_TAXONOMY') {
                $attributes[$key]['is_visible'] = false;
            }
        }
        return $attributes;
    }, 10, 1);

    Note that the above code is untested.

    Otherwise the following filter should get you on track if you are looking for a term specific behavior: woocommerce_get_product_terms.

    However, I do not see this as adequate plugin extension, since displaying term titles in the “Additional information” tab and displaying new tabs with extension information about that term are two separate things, than can co-exist without causing any redundant information. Furthermore, it is possible to control this behavior by setting the “Visible on the product page” option on the product level (which is of course cumbersome if you have a lot of products).

    Kind regards,
    Mike

    Thread Starter pedrorito

    (@pedrorito)

    Hi Mike,
    Thank you for your detailed answer. I found a way to do it. I’m using Woo Default Attributes plugin as well, and this plugin automatically populates the attributes I want to use in every product, in the admin panel add product. When they appear automatically, they are marked visible. So, I modified that plugin to mark all visible but the one that I use in the separated tab.
    I have one last question though. How could I modify the appearance of the separated tab created by your plugin? I’m interested in having more than one column (for non-mobile), and also reduce the space between lines. You can have a look on my example of a product https://new.garagemrito.pt/?product=audi-a4-2-0-tdi-advance-140cv-m6-nav and the separated tab is “Extras”.
    Best regards,
    Pedro

    Plugin Author mjke87

    (@mjke87)

    Hi Pedro,

    I cannot access your example product page, but I think I understand what you mean.

    The default behavior of the plugin is to simply wrap attribute descriptions in paragraph tags. There is a filter that allows you to modify this behavior, however:

    /**
     * Filter for the tab content format template.
     * The format is a wrapper around the content which has to contain a placeholder for the content.
     * The content is injected via PHP string formatting. Make sure you have a <code>%s</code> placeholder in your format.
     * Return an empty value to skip the formatting.
     * 
     * @param string $format The format template. Default is <code><p>%s</p></code>.
     * @param stdClass $term The current attribute term object.
     * @param stdClass $attribute The current attribute object.
     * @param string $display_type The current attribute display type.
     * 
     */
    $format = apply_filters('woocommerce_product_attribute_tab_content_format', $format, $term, $attribute, $display_type);

    If you simply wish to reduce the space between lines, then you can achieve this with pure CSS. Simply reduce the line-height of the p-tags within the tab.

    Also a two-column layout can be achieved with only CSS. You might want to switch to a div-wrapper instead of paragraphs using the filter above. Then you can make use of the :even and :odd CSS pseudo selectors. See here for some inspiration: https://stackoverflow.com/questions/5645986/two-column-div-layout-with-fluid-left-and-fixed-right-column

    Best wishes,
    Mike

    Thread Starter pedrorito

    (@pedrorito)

    Solved. You were very helpful.
    Thank you!
    Pedro

    Thanks Mike,

    I’ve used the function you have indicated to remove a taxonomy term from the Additional Information tab if it has a product tab description.

    How can I change this code to include two taxonomy terms? I can’t figure out the syntax required.

    Thanks!
    Louise

    Don’t worry – figured it out – just copied the statement and replaced the attribute name. ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Attribute appears simultaneously in additional information and new attribute tab’ is closed to new replies.