In a recent version of WooCommerce the developers made a tweak to how variable products are show when they only have one attribute. The chose attribute value is shown directly in the product title when, in example, the product is added to the cart.

I’ve noticed that not everyone likes this new feature and some asked to revert it back to how it was before.

Can we accommodate everyone? Yes, here is how.

Let’s Write Some Code!

I created a Pull Request not too long ago to add the filter woocommerce_is_attribute_in_product_name to the core of WooCommerce.

This filter can be used to show the attributes below the product title, like it was before the most recent version of WooCommerce.

You can add this code to the functions.php file in wp-content/themes/your-child-theme-name/ to do that:

This code alone though is not enough. You will now see the attributes table below the product title, but also you will see the attribute in the product title.

To remove it from there, you need some more code:

Using both these snippets together will make sure that you only show the attributes table like it was before, and the title of the product will be the one that you set in the Dashboard, with nothing added to it.

10 replies
  1. Lina
    Lina says:

    This is great, thank you so much!
    I used only the part to add the attribute below the title and changed the rest manually by changing get_name to get_title within the templates (had them anyway in my childtheme because I already changed some code). I had some reasons to do it like this instead of using your function, too complicated to explain why. Anyway, if I change get_name to get_title in order/oder-details-item, it doesnt work. It says:
    “Fatal error: Uncaught Error: Call to undefined method WC_Order_Item_Product::get_title() in …/woocommerce/order/order-details-item.php:41 Stack trace: #0 /wp-content/plugins/woocommerce/includes/wc-core-functions.php(204)…..”
    Also with your function, it doesnt work in the order details (it shows no error but its simply not applied ). Sorry for my english, I hope you understand what I mean 🙂
    Any idea how to get rid of this error would be really appreciated!

    Reply
  2. Kasia
    Kasia says:

    Hi again Nicola, I was wondering if it might be possible for you to help me modify your code to remove the product attributes from the titles on the Thank You page and the My Account > Orders page in the Order Details section. These use the woocommerce_order_item_name rather than woocommerce_cart_item_name. I have been trying to play around with what you’ve done and apply it here, but I’m not having any success making it work. Many thanks in advance!

    Reply
  3. Zygimantas
    Zygimantas says:

    this code below works fine for me except it does not remove the original a tag but just creates a new one, any suggestion on why is that?

    Reply
  4. Ewout
    Ewout says:

    for a version that is a bit simpler than the above, you can also use a combination of these two oneliners:

    add_filter( ‘woocommerce_product_variation_title_include_attributes’, ‘__return_false’ );
    add_filter( ‘woocommerce_is_attribute_in_product_name’, ‘__return_false’ );

    Reply
  5. Patrick
    Patrick says:

    This code works great during add to cart and during checkout. However, this attribute is re-added to the title on the successful order page and in the successful order e-mail. Does’t seem to stay away. Is it possible to keep the coding removed after the order is fulfilled and in order e-mails?

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.