Support » Plugin: WooCommerce » Display Multiple Attributes in Variation Names

  • Resolved Lisa Clarke

    (@polkadotcreations)


    Most products in my store have two or more attributes associated with the variations. When I display them, I see that the variations with only one attribute have names like Product - Attribute. This is great.

    However, if a product has more than one attribute, none of them are displayed. The variation name becomes simply Product. This is not great.

    For example, one of my products is Crochet Hooks. They have attributes for hook size, brand name, and handle design, but when they are displayed in a search like this, they all just say Crochet Hooks.

    Ideally they would say something like Crochet Hooks - H/8, Susan Bates, Blue Tortoise , which would be much more helpful to someone shopping for a hook.

    At the very least, I’d like to see the first attribute displayed (as in Crochet Hooks - H/8) .

    I have tried exporting all of my items and re-importing them with customized names, but that has no effect at all, as if that field is ignored.

    Is there some way to change the variation display name so that it always tacks on at least one attribute? Some function I can stick in functions.php maybe?

    Thanks for the help!

    The page I need help with: [log in to see the link]

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

    (@polkadotcreations)

    I’ve looked in the database and I can see that the post_title for variations is set exactly how it’s displayed: Product - Attribute for variations with one attribute, and Product for variations with multiple attributes.

    So, this issue is definitely not with the display of the title, but with the setting of the title.

    Even though I would prefer to have WooCommerce set the post_title to something more useful by default, I could deal with the issue by updating the post_title directly in the database. The problem with that, is I’d have to do it every time I create new variations.

    I would really appreciate it if someone had some ideas for me that didn’t involve running frequent MySQL queries.

    Plugin Support Pepe (woo-hc)

    (@anastas10s)

    Howdy @polkadotcreations

    From what I gather, when two or more attributes are set for a product, it displays as Product, instead of Product - Attribute.

    Just to clarify, are the attributes added using the default product attributes tab (as showcased in the screenshot linked here), or otherwise?

    To help you further, I’d like to understand more about your setup.

    Could you please send me a copy of your site’s System Status? You can find it via WooCommerce > Status. Select Get system report and then Copy for support.

    Once you’ve done that, you can paste the text in https://gist.github.com/ and feel free to change/remove your site URL in the report for privacy reasons.

    You can paste the Gist link here in your reply, once you have that.

    Thread Starter Lisa Clarke

    (@polkadotcreations)

    I’ve actually gotten pretty far to make the catalog pages behave the way I want them to. I’ve cobbled together this code:

    add_filter( 'woocommerce_product_variation_title', 'lrc_variation_with_attribute', 10, 4 );
    function lrc_variation_with_attribute( $variation_title, $product, $title_base, $title_suffix ) {
        add_filter( 'woocommerce_cart_item_name', function($variation_title) { return $variation_title; } , 20, 3);
        $attribute = wc_get_formatted_variation( $product->get_variation_attributes(), true );
        $product_parent = wc_get_product( $product->get_parent_id() );
        $product_title = $product_parent->get_name();
        return $product_title . "<br><small>" . $attribute . "</small>";
    }
    

    It does exactly what I want, except it also changes the product name in the cart, which I don’t want. I’ve tried using if ( !is_cart() ) but that doesn’t do anything. I’ve used various functions like that to determine what page I’m on but none of them work in this function.

    What I really need now is a way to say “only return this new product name if I’m on a catalog page” or “return the original variation title if I’m in the cart”

    To answer your questions, I define my attributes outside of the product, from the Products > Attributes menu. Within the product, I choose an attribute from the screen in your screenshot, and select use for variations. Then I add my variations.

    Here’s my system report: https://gist.github.com/lclarke522/a35a88ee6389a6144f8a888aaf80d527

    Thank you for your help!

    Hi @polkadotcreations

    Thanks for your confirmation that you are using a custom code to achieved your requirement here.

    This is a fairly complex development topic. These forums are meant for general support with the core functionality of WooCommerce itself. Since custom coding is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    Hope this helps!

    Thread Starter Lisa Clarke

    (@polkadotcreations)

    Thank you. I appreciate the links.

    I solved this issue changing directly in the function of woocommerce .

    Navigate to: wp-content > plugins > woocommerce > includes > data-stores > class-wc-product-variation-data-store-cpt.php

    At line 291 you can see the function “generate_product_title”.

    We need to set $should_include_attributes always “true” and change the number “1” to bigger then your attributes count.

    Bye.

    Hi @marcozz

    We appreciate your proactive approach in addressing the problem.

    Modifying the function directly in the WooCommerce plugin files can be a solution in some cases, but it’s important to note that directly modifying core plugin files is generally not recommended. It can lead to compatibility issues and may be overwritten when the plugin is updated.

    However, if the changes you made have resolved the specific issue you were facing and you are satisfied with the outcome, that’s great to hear. Just be aware that when you update the WooCommerce plugin in the future, your modifications may be overwritten, and you’ll need to reapply them.

    If you encounter any further issues or require assistance with any other aspect of WooCommerce, please don’t hesitate to create a new ticket.

    Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display Multiple Attributes in Variation Names’ is closed to new replies.